Skip to content

Commit c4ea64c

Browse files
committed
fix: Simplified Script_EyeAngles, updated comments, and added new VScript functions to README
1 parent 09f6527 commit c4ea64c

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

README.md

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,36 @@ The purpose of this plugin is to patch Portal 2 to make the mod work as well as
1515
Note: While represented in C++, below functions are for Squirrel. `const char*` type is translated to `string` type. `byte`, `short`, and `long` types are translated to `integer` type. `void` types are simply the `function` type in Squirrel. `HSCRIPT` is a VScript script handle which is an entity instance.
1616

1717
```c++
18-
void printlP2MM(int level, bool dev, const char* pMsgFormat); | "Logging for the P2MM VScript. The log message must be passed as a string or it will error."
19-
const char* GetPlayerName(int playerIndex); | "Gets player username by their entity index."
20-
int GetSteamID(int playerIndex); | "Gets the account ID component of player SteamID by the player's entity index."
21-
int UserIDToPlayerIndex(int userid); | "Get the player's entity index by their userid."
22-
bool IsMapValid(const char* map); | "Returns true is the supplied string is a available map to load and run."
23-
int GetDeveloperLevelP2MM(); | "Returns the value of ConVar p2mm_developer."
24-
bool IsDedicatedServer(); | "Returns true if this is a dedicated server."
25-
void InitializeEntity(HSCRIPT ent); | "Initializes, spawns, then activates an entity in the map. Create a entity using CreateByClassname, then use this function on its handle. Note: Not all entities will work even after being initialized with this function."
26-
void SendToChat(const char* msg, int playerIndex); | "Sends a raw message to the chat HUD. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
27-
const char* GetGameMainDir(); | "Returns the current game directory. Ex. portal2"
28-
const char* GetGameRootDir(); | "Returns the current root game directory. Ex. Portal 2"
29-
void CallFirstRunPrompt(); | "Shows the first run prompt if enabled in config.nut."
30-
int GetConVarInt(const char* cvName); | "Get the integer value of a ConVar."
31-
const char* GetConVarString(const char* cvName); | "Get the string value of a ConVar."
32-
void SetConVarInt(const char* cvName, int newValue); | "Set the integer value of a ConVar."
33-
void SetConVarString(const char* cvName, const char* newValue); | "Set the string value of a ConVar."
34-
HSCRIPT PlayerByIndex(int playerIndex); | "Takes the player's entity index and returns the player's script handle."
35-
void RespawnPlayer(int playerIndex); | "Respawn the a player by their entity index."
36-
void SetFlashlightState(int playerIndex, bool enable); | "Set the flashlight for a player on or off."
37-
void ConsolePrint(int playerIndex, const char* msg); | "Print a message to a player's console, unlike printl() which is just the host. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
38-
void ClientPrint(int playerIndex, const char* msg); | "Print a message to the top center position of a player's screen. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
39-
void HudPrint(int playerIndex, const char* msg, Vector(float x, float y, int channel), int effect, float fxTime, Vector RGB1, float alpha1, Vector RGB2, float alpha2, Vector(float fadeinTime, float fadeoutTime, float holdTime));
40-
| "Print a message to the screen based on what the game_text entity does, with many values to set. See Valve Developer Commentary for the game_text entity to see what each field does. Vectors are in place for sets of RGB values. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
41-
int GetMaxPlayers(); | "Self-explanatory."
42-
void ShowScoreboard(int playerIndex, bool bEnable); | "Enable or disable displaying the score board a player."
18+
void printlP2MM(int level, bool dev, const char* pMsgFormat); | "Logging for the P2MM VScript. The log message must be passed as a string or it will error."
19+
const char* GetPlayerName(int playerIndex); | "Gets player username by their entity index."
20+
int GetSteamID(int playerIndex); | "Gets the account ID component of player SteamID by the player's entity index."
21+
int UserIDToPlayerIndex(int userid); | "Get the player's entity index by their userid."
22+
bool IsMapValid(const char* map); | "Returns true is the supplied string is a available map to load and run."
23+
int GetDeveloperLevelP2MM(); | "Returns the value of ConVar p2mm_developer."
24+
bool IsDedicatedServer(); | "Returns true if this is a dedicated server."
25+
void InitializeEntity(HSCRIPT ent); | "Initializes, spawns, then activates an entity in the map. Create a entity using CreateByClassname, then use this function on its handle. Note: Not all entities will work even after being initialized with this function."
26+
void SendToChat(const char* msg, int playerIndex); | "Sends a raw message to the chat HUD. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
27+
const char* GetGameMainDir(); | "Returns the current game directory. Ex. portal2"
28+
const char* GetGameRootDir(); | "Returns the current root game directory. Ex. Portal 2"
29+
void CallFirstRunPrompt(); | "Shows the first run prompt if enabled in config.nut."
30+
int GetConVarInt(const char* cvName); | "Get the integer value of a ConVar."
31+
const char* GetConVarString(const char* cvName); | "Get the string value of a ConVar."
32+
void SetConVarInt(const char* cvName, int newValue); | "Set the integer value of a ConVar."
33+
void SetConVarString(const char* cvName, const char* newValue); | "Set the string value of a ConVar."
34+
HSCRIPT PlayerByIndex(int playerIndex); | "Takes the player's entity index and returns the player's script handle."
35+
void RespawnPlayer(int playerIndex); | "Respawn the a player by their entity index."
36+
void SetFlashlightState(int playerIndex, bool enable); | "Set the flashlight for a player on or off."
37+
void ConsolePrint(int playerIndex, const char* msg); | "Print a message to a player's console, unlike printl() which is just the host. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
38+
void ClientPrint(int playerIndex, const char* msg); | "Print a message to the top center position of a player's screen. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
39+
void HudPrint(int playerIndex, const char* msg, Vector(float x, float y, int channel), int effect, float fxTime, Vector RGB1, float alpha1, Vector RGB2, float alpha2, Vector(float fadeinTime, float fadeoutTime, float holdTime));
40+
| "Print a message to the screen based on what the game_text entity does, with many values to set. See Valve Developer Commentary for the game_text entity to see what each field does. Vectors are in place for sets of RGB values. Specifying no playerIndex or 0 sends to all players. Supports printing localization strings but those that require formatting can't be formatted."
41+
int GetMaxPlayers(); | "Return max amount of players that can be in the server."
42+
void ShowScoreboard(int playerIndex, bool bEnable); | "Enable or disable displaying the score board a player."
43+
void RemovePlayerUI(const int playerIndex, const bool bBanning) | "Display UI for either banning or kicking so host can ban or kick a player. WIP, need to manually open pause menu to see VGUI"
44+
float TraceLineEx(const Vector& vecAbsStart, const Vector& vecAbsEnd, const int mask, const HSCRIPT ignore, const int collisionGroup)
45+
| "Improved version of TraceLine that allows for checking with bit masks and collision groups. Returns a fraction of line where a collision occured, or if in a solid, the amount spent outside the solid."
46+
const Vector& Script_EyeAngles(const int playerIndex) | "Get the eye angles of a player. WIP seems to crash."
47+
4348
```
4449
4550
## Game Events Interfaced To Squirrel VScript Functions:

vscript.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static void ShowScoreboard(const int playerIndex, const bool enable)
303303
* @param mask Bit mask used for determining what objects should be hit.
304304
* @param ignore A entity for the trace line to ignore, typically this is for a trace line originating from a entity.
305305
* @param collisionGroup Collision group that the trace line can hit.
306-
* @return
306+
* @return Returns a fraction of line where a collision occured, or if in a solid, the amount spent outside the solid.
307307
*/
308308
static float Script_UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, const int mask, const HSCRIPT ignore, const int collisionGroup)
309309
{
@@ -323,12 +323,8 @@ static float Script_UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecA
323323
*/
324324
static const Vector& Script_EyeAngles(const int playerIndex)
325325
{
326-
Vector eyeVector;
327326
const QAngle eyeAngles = CBasePlayer__EyeAngles(playerIndex);
328-
eyeVector.x = eyeAngles.x;
329-
eyeVector.y = eyeAngles.y;
330-
eyeVector.z = eyeAngles.z;
331-
return eyeVector;
327+
return Vector(eyeAngles.x, eyeAngles.y, eyeAngles.z);
332328
}
333329

334330
void RegisterFuncsAndRun()
@@ -374,7 +370,7 @@ void RegisterFuncsAndRun()
374370
"Supports printing localization strings but those that require formatting can't be formatted."
375371
"Vectors are used to consolidate some parameters so function isn't monstrously big."
376372
);
377-
ScriptRegisterFunction (g_pScriptVM, GetMaxPlayers, "Returns the current max players in the server.");
373+
ScriptRegisterFunction (g_pScriptVM, GetMaxPlayers, "Return max amount of players that can be in the server.");
378374
ScriptRegisterFunction (g_pScriptVM, ShowScoreboard, "Enable or disable displaying the score board for players.");
379375
ScriptRegisterFunction (g_pScriptVM, RemovePlayerUI, "Display UI for either banning or kicking so host can ban or kick a player.");
380376
ScriptRegisterFunctionNamed(g_pScriptVM, Script_UTIL_TraceLine, "TraceLineEx", "Improved version of TraceLine that allows for checking with bit masks and collision groups.");

0 commit comments

Comments
 (0)