More consistency of some sort...
Oh god, what has possessed me to do this?
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "sm_globals.h"
16 #include "sourcemod.h"
17 #include "sourcemm_api.h"
18 #include "PlayerManager.h"
20 static cell_t SetRandomSeed(IPluginContext *pContext, const cell_t *params)
22 engrandom->SetSeed(params[1]);
27 static cell_t GetRandomFloat(IPluginContext *pContext, const cell_t *params)
29 float fMin = sp_ctof(params[1]);
30 float fMax = sp_ctof(params[2]);
32 float fRandom = engrandom->RandomFloat(fMin, fMax);
34 return sp_ftoc(fRandom);
37 static cell_t GetRandomInt(IPluginContext *pContext, const cell_t *params)
39 return engrandom->RandomInt(params[1], params[2]);
42 static cell_t IsMapValid(IPluginContext *pContext, const cell_t *params)
45 pContext->LocalToString(params[1], &map);
47 return engine->IsMapValid(map);
50 static cell_t IsDedicatedServer(IPluginContext *pContext, const cell_t *params)
52 return engine->IsDedicatedServer();
55 static cell_t GetEngineTime(IPluginContext *pContext, const cell_t *params)
57 float fTime = engine->Time();
58 return sp_ftoc(fTime);
61 static cell_t GetGameTime(IPluginContext *pContext, const cell_t *params)
63 return sp_ftoc(gpGlobals->curtime);
66 static cell_t CreateFakeClient(IPluginContext *pContext, const cell_t *params)
70 pContext->LocalToString(params[1], &netname);
72 edict_t *pEdict = engine->CreateFakeClient(netname);
74 /* :TODO: does the engine fire forwards for us and whatnot? no idea... */
81 return engine->IndexOfEdict(pEdict);
84 static cell_t SetFakeClientConVar(IPluginContext *pContext, const cell_t *params)
86 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
90 return pContext->ThrowNativeError("Player %d is not a valid player", params[1]);
93 if (!pPlayer->IsConnected())
95 return pContext->ThrowNativeError("Player %d is not connected", params[1]);
98 if (!pPlayer->IsFakeClient())
100 return pContext->ThrowNativeError("Player %d is not a fake client", params[1]);
105 pContext->LocalToString(params[2], &cvar);
106 pContext->LocalToString(params[3], &value);
108 engine->SetFakeClientConVarValue(pPlayer->GetEdict(), cvar, value);
113 static cell_t GetGameDescription(IPluginContext *pContext, const cell_t *params)
115 const char *description;
119 description = gamedll->GetGameDescription();
121 description = SERVER_CALL(GetGameDescription)();
126 pContext->StringToLocalUTF8(params[1], params[2], description, &numBytes);
131 static cell_t GetCurrentMap(IPluginContext *pContext, const cell_t *params)
134 pContext->StringToLocalUTF8(params[1], params[2], STRING(gpGlobals->mapname), &bytes);
138 REGISTER_NATIVES(halflifeNatives)
140 {"CreateFakeClient", CreateFakeClient},
141 {"GetCurrentMap", GetCurrentMap},
142 {"GetEngineTime", GetEngineTime},
143 {"GetGameDescription", GetGameDescription},
144 {"GetGameTime", GetGameTime},
145 {"GetRandomFloat", GetRandomFloat},
146 {"GetRandomInt", GetRandomInt},
147 {"IsDedicatedServer", IsDedicatedServer},
148 {"IsMapValid", IsMapValid},
149 {"SetFakeClientConVar", SetFakeClientConVar},
150 {"SetRandomSeed", SetRandomSeed},