• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Need Radom player chose!

johny5608

johny
Joined
Oct 5, 2008
Messages
120
Reaction score
0
Location
Wien
Hello,
I need c++ script: Radom player chose!
That the serwer (computer) radom chose a player.
 
I guess it would be something like this. I havent tried the code or debugged it. You can try compile but I dont think it will work. But you get the idea how you can add LUA functions.

luascript.h

below:
Code:
//lua functions

add this:
Code:
static int32_t luaSelectRandomPlayer(lua_State* L);

luascript.cpp

below:
Code:
void LuaScriptInterface::registerFunctions()
{

add this:
Code:
//selectRandomPlayer(uid[, count])
lua_register(m_luaState, "selectRandomPlayer", LuaScriptInterface::luaSelectRandomPlayer);

below:
Code:
int32_t LuaScriptInterface::luaGetPlayerAccountManager(lua_State* L)
{
	return internalGetPlayerInfo(L, PlayerInfoAccountManager);
}

add this:
Code:
int32_t LuaScriptInterface::luaSelectRandomPlayer(lua_State* L)
{
	//selectRandomPlayer()
	lua_pushinteger(L, autoList.begin() + rand() % (autoList.end()+1 - autoList.begin()) );
	return 1;
}
 
@up
Thanks for the script!

But have you a C++ Script with configuration in config.lua
I mean that this line in the config.lua is:
choseRadomPlayer = true
choseRadomPlayerEverySecond = true
HowManySecondToChoseAOtherPlayer = second
ChoseRadomPlayerinTheEndofTheRound = true
 
Ej i got an Error:
In static member function `static int32_t LuaScriptInterface::luaSelectRandomPlayer(lua_State*)':
2788 .:\M...\forgottenserver-0.3.6pl1\0.3.6pl1\luascript.cpp `autoList' was not declared in this scope
.:\...\forgottenserver-0.3.6pl1\0.3.6pl1\dev-cpp\Makefile.win [Build Error] [obj//luascript.o] Error 1
 
Yeah, I see now that autoList is a static varibale in the Player class. Or many of the classes use it so I guess its like a generic vector.

I reply if I find solution.
 
Back
Top