2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
14 #include "sm_globals.h"
15 #include "sourcemod.h"
16 #include "sourcemm_api.h"
17 #include "PlayerManager.h"
19 static cell_t SetRandomSeed(IPluginContext *pContext, const cell_t *params)
21 engrandom->SetSeed(params[1]);
26 static cell_t GetRandomFloat(IPluginContext *pContext, const cell_t *params)
28 float fMin = sp_ctof(params[1]);
29 float fMax = sp_ctof(params[2]);
31 float fRandom = engrandom->RandomFloat(fMin, fMax);
33 return sp_ftoc(fRandom);
36 static cell_t GetRandomInt(IPluginContext *pContext, const cell_t *params)
38 return engrandom->RandomInt(params[1], params[2]);
41 static cell_t IsMapValid(IPluginContext *pContext, const cell_t *params)
44 pContext->LocalToString(params[1], &map);
46 return engine->IsMapValid(map);
49 static cell_t IsDedicatedServer(IPluginContext *pContext, const cell_t *params)
51 return engine->IsDedicatedServer();
54 static cell_t GetEngineTime(IPluginContext *pContext, const cell_t *params)
56 float fTime = engine->Time();
57 return sp_ftoc(fTime);
60 static cell_t GetGameTime(IPluginContext *pContext, const cell_t *params)
62 return sp_ftoc(gpGlobals->curtime);
65 static cell_t CreateFakeClient(IPluginContext *pContext, const cell_t *params)
69 pContext->LocalToString(params[1], &netname);
71 edict_t *pEdict = engine->CreateFakeClient(netname);
73 /* :TODO: does the engine fire forwards for us and whatnot? no idea... */
80 return engine->IndexOfEdict(pEdict);
83 static cell_t SetFakeClientConVar(IPluginContext *pContext, const cell_t *params)
85 CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
89 return pContext->ThrowNativeError("Player %d is not a valid player", params[1]);
92 if (!pPlayer->IsConnected())
94 return pContext->ThrowNativeError("Player %d is not connected", params[1]);
97 if (!pPlayer->IsFakeClient())
99 return pContext->ThrowNativeError("Player %d is not a fake client", params[1]);
104 pContext->LocalToString(params[2], &cvar);
105 pContext->LocalToString(params[3], &value);
107 engine->SetFakeClientConVarValue(pPlayer->GetEdict(), cvar, value);
112 static cell_t GetGameDescription(IPluginContext *pContext, const cell_t *params)
114 const char *description;
118 description = gamedll->GetGameDescription();
120 description = SERVER_CALL(GetGameDescription)();
125 pContext->StringToLocalUTF8(params[1], params[2], description, &numBytes);
130 static cell_t GetCurrentMap(IPluginContext *pContext, const cell_t *params)
133 pContext->StringToLocalUTF8(params[1], params[2], STRING(gpGlobals->mapname), &bytes);
137 REGISTER_NATIVES(halflifeNatives)
139 {"CreateFakeClient", CreateFakeClient},
140 {"GetCurrentMap", GetCurrentMap},
141 {"GetEngineTime", GetEngineTime},
142 {"GetGameDescription", GetGameDescription},
143 {"GetGameTime", GetGameTime},
144 {"GetRandomFloat", GetRandomFloat},
145 {"GetRandomInt", GetRandomInt},
146 {"IsDedicatedServer", IsDedicatedServer},
147 {"IsMapValid", IsMapValid},
148 {"SetFakeClientConVar", SetFakeClientConVar},
149 {"SetRandomSeed", SetRandomSeed},