88#include " stdafx.hpp"
99#include " globals.hpp"
1010
11- #include " sdk.hpp"
12- #include " p2sm.hpp"
13- #include " utils/loggingsystem.hpp"
14-
1511// ---------------------------------------------------------------------------------
1612// Interfaces from the engine.
1713// ---------------------------------------------------------------------------------
@@ -24,182 +20,3 @@ IPlayerInfoManager* g_pPlayerInfoManager = nullptr;
2420// IGameEventManager2* g_pGameEventManager_;
2521// IServerPluginHelpers* g_pPluginHelpers = nullptr;
2622// IFileSystem* g_pFileSystem;
27-
28- // ---------------------------------------------------------------------------------
29- // Purpose: Get the player's entity index by their userid.
30- // ---------------------------------------------------------------------------------
31- int UserIDToPlayerIndex (const int userid)
32- {
33- for (int i = 1 ; i <= MAX_PLAYERS; i++)
34- {
35- const edict_t * pEdict = nullptr ;
36- if (i >= 0 && i < g_pGlobals->maxEntities )
37- pEdict = (g_pGlobals->pEdicts + i);
38-
39- if (engineServer->GetPlayerUserId (pEdict) == userid)
40- return i;
41- }
42- return 0 ; // Return 0 if the index can't be found
43- }
44-
45- // ---------------------------------------------------------------------------------
46- // Purpose: Get player username by their entity index.
47- // ---------------------------------------------------------------------------------
48- const char * GetPlayerName (const int playerIndex)
49- {
50- if (playerIndex <= 0 || playerIndex > MAX_PLAYERS)
51- {
52- Log (WARNING, true , " Invalid index passed to GetPlayerName: %i! Returning " " !" , playerIndex);
53- return " " ;
54- }
55-
56- player_info_t playerInfo;
57- if (!engineServer->GetPlayerInfo (playerIndex, &playerInfo))
58- {
59- Log (WARNING, true , R"( Couldn't retrieve playerInfo of player index in GetPlayerName: %i! Returning ""!)" , playerIndex);
60- return " " ;
61- }
62-
63- return playerInfo.name ;
64- }
65-
66- // ---------------------------------------------------------------------------------
67- // Purpose: Get the account ID component of player SteamID by the player's entity index.
68- // ---------------------------------------------------------------------------------
69- int GetSteamID (const int playerIndex)
70- {
71- edict_t * pEdict = nullptr ;
72- if (playerIndex >= 0 && playerIndex < MAX_PLAYERS)
73- pEdict = (g_pGlobals->pEdicts + playerIndex);
74-
75- if (!pEdict)
76- return -1 ;
77-
78- player_info_t playerInfo;
79- if (!engineServer->GetPlayerInfo (playerIndex, &playerInfo))
80- return -1 ;
81-
82- const CSteamID* pSteamID = engineServer->GetClientSteamID (pEdict);
83- if (!pSteamID || pSteamID->GetAccountID () == 0 )
84- return -1 ;
85-
86- return pSteamID->GetAccountID ();
87- }
88-
89- // ---------------------------------------------------------------------------------
90- // Purpose: Self-explanatory.
91- // ---------------------------------------------------------------------------------
92- int GetConVarInt (const char * cvName)
93- {
94- const ConVar* pVar = g_pCVar->FindVar (cvName);
95- if (!pVar)
96- {
97- Log (WARNING, false , R"( Could not find ConVar: "%s"! Returning ""!)" , cvName);
98- return -1 ;
99- }
100-
101- return pVar->GetInt ();
102- }
103-
104- // ---------------------------------------------------------------------------------
105- // Purpose: Self-explanatory.
106- // ---------------------------------------------------------------------------------
107- const char * GetConVarString (const char * cvName)
108- {
109- const ConVar* pVar = g_pCVar->FindVar (cvName);
110- if (!pVar)
111- {
112- Log (WARNING, false , R"( Could not find ConVar: "%s"! Returning ""!)" , cvName);
113- return " " ;
114- }
115-
116- return pVar->GetString ();
117- }
118-
119- // ---------------------------------------------------------------------------------
120- // Purpose: Self-explanatory.
121- // ---------------------------------------------------------------------------------
122- void SetConVarInt (const char * cvName, const int newValue)
123- {
124- ConVar* pVar = g_pCVar->FindVar (cvName);
125- if (!pVar)
126- {
127- Log (WARNING, false , " Could not set ConVar: \" %s\" !" , cvName);
128- return ;
129- }
130- pVar->SetValue (newValue);
131- }
132-
133- // ---------------------------------------------------------------------------------
134- // Purpose: Self-explanatory.
135- // ---------------------------------------------------------------------------------
136- void SetConVarString (const char * cvName, const char * newValue)
137- {
138- ConVar* pVar = g_pCVar->FindVar (cvName);
139- if (!pVar)
140- {
141- Log (WARNING, false , R"( Could not set ConVar: "%s"!)" , cvName);
142- return ;
143- }
144- pVar->SetValue (newValue);
145- return ;
146- }
147-
148- // ---------------------------------------------------------------------------------
149- // Purpose: Returns true if player is a bot.
150- // ---------------------------------------------------------------------------------
151- bool IsBot (const int playerIndex)
152- {
153- player_info_t playerInfo;
154- if (!engineServer->GetPlayerInfo (playerIndex, &playerInfo))
155- {
156- Log (WARNING, true , R"( Couldn't retrieve player info of player index "%i" in IsBot!)" , playerIndex);
157- return false ;
158- }
159-
160- return playerInfo.fakeplayer ;
161- }
162-
163- // ---------------------------------------------------------------------------------
164- // Purpose: Get the number of bots in the server.
165- // ---------------------------------------------------------------------------------
166- int GetBotCount ()
167- {
168- int b = 0 ;
169- FOR_ALL_PLAYERS (i)
170- {
171- if (IsBot (i))
172- b++;
173- }
174- return b;
175- }
176-
177- // ---------------------------------------------------------------------------------
178- // Purpose: Get the current player count on the server.
179- // ---------------------------------------------------------------------------------
180- int CURPLAYERCOUNT ()
181- {
182- int playerCount = 0 ;
183- for (int i = 1 ; i <= MAX_PLAYERS; i++)
184- {
185- if (UTIL_PlayerByIndex (i))
186- playerCount++;
187- }
188- return playerCount;
189- }
190-
191- // ---------------------------------------------------------------------------------
192- // Purpose: Entity index to script handle.
193- // ---------------------------------------------------------------------------------
194- HSCRIPT INDEXHANDLE (const int iEdictNum)
195- {
196- edict_t * pEdict = INDEXENT (iEdictNum);
197- if (!pEdict->GetUnknown ())
198- return nullptr ;
199-
200- CBaseEntity* pBaseEntity = pEdict->GetUnknown ()->GetBaseEntity ();
201- if (!pBaseEntity)
202- return nullptr ;
203-
204- return CBaseEntity__GetScriptInstance (pBaseEntity);
205- }
0 commit comments