added random number natives
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40536
This commit is contained in:
parent
0b8874e5ec
commit
bb69a9f0d2
core
plugins/include
@ -665,6 +665,10 @@
|
||||
RelativePath="..\smn_float.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\smn_halflife.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\smn_handles.cpp"
|
||||
>
|
||||
|
45
core/smn_halflife.cpp
Normal file
45
core/smn_halflife.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* ===============================================================
|
||||
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
||||
* ===============================================================
|
||||
*
|
||||
* This file is not open source and may not be copied without explicit
|
||||
* written permission of AlliedModders LLC. This file may not be redistributed
|
||||
* in whole or significant part.
|
||||
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemm_api.h"
|
||||
|
||||
static cell_t SetRandomSeed(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
engrandom->SetSeed(params[1]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t GetRandomFloat(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
float fMin = sp_ctof(params[1]);
|
||||
float fMax = sp_ctof(params[2]);
|
||||
|
||||
float fRandom = engrandom->RandomFloat(fMin, fMax);
|
||||
|
||||
return sp_ftoc(fRandom);
|
||||
}
|
||||
|
||||
static cell_t GetRandomInt(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return engrandom->RandomInt(params[1], params[2]);
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(halflifeNatives)
|
||||
{
|
||||
{"SetRandomSeed", SetRandomSeed},
|
||||
{"GetRandomFloat", GetRandomFloat},
|
||||
{"GetRandomInt", GetRandomInt},
|
||||
{NULL, NULL},
|
||||
};
|
@ -24,6 +24,7 @@ ISmmPluginManager *g_pMMPlugins = NULL;
|
||||
CGlobalVars *gpGlobals = NULL;
|
||||
ICvar *icvar = NULL;
|
||||
IGameEventManager2 *gameevents = NULL;
|
||||
IUniformRandomStream *engrandom = NULL;
|
||||
CallClass<IVEngineServer> *enginePatch = NULL;
|
||||
|
||||
PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
|
||||
@ -37,6 +38,7 @@ bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen
|
||||
GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
|
||||
GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
|
||||
GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
|
||||
GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
|
||||
|
||||
if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <eiface.h>
|
||||
#include <icvar.h>
|
||||
#include <igameevents.h>
|
||||
#include <random.h>
|
||||
|
||||
/**
|
||||
* @file Contains wrappers around required Metamod:Source API exports
|
||||
@ -52,6 +53,7 @@ extern ISmmPluginManager *g_pMMPlugins;
|
||||
extern CGlobalVars *gpGlobals;
|
||||
extern IGameEventManager2 *gameevents;
|
||||
extern SourceHook::CallClass<IVEngineServer> *enginePatch;
|
||||
extern IUniformRandomStream *engrandom;
|
||||
|
||||
#define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func)
|
||||
|
||||
|
@ -340,5 +340,32 @@ native LogMessage(const String:format[], {Handle,Float,String,_}:...);
|
||||
*/
|
||||
native LogError(const String:format[], {Handle,Float,String,_}:...);
|
||||
|
||||
/**
|
||||
* Sets the seed value for the global Half-Life 2 Random Stream
|
||||
*
|
||||
* @param seed Seed value.
|
||||
* @noreturn
|
||||
*/
|
||||
native SetRandomSeed(seed);
|
||||
|
||||
/**
|
||||
* Returns a random floating point number from the Half-Life 2 Random Stream
|
||||
*
|
||||
* @param fMin Minimum random bound.
|
||||
* @param fMax Maximum random bound.
|
||||
* @return A random number between (inclusive) fMin and fMax.
|
||||
*/
|
||||
native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
|
||||
|
||||
/**
|
||||
* Returns a random number from the Half-Life 2 Random Stream
|
||||
*
|
||||
* @param nmin Minimum random bound.
|
||||
* @param nmax Maximum random bound.
|
||||
* @return A random number between (inclusive) nmin and nmax.
|
||||
*/
|
||||
native GetRandomInt(nmin, nmax);
|
||||
|
||||
|
||||
#include <usermessages>
|
||||
#include <helpers>
|
||||
|
Loading…
Reference in New Issue
Block a user