Page 1 of 1

LUA GetRand

Posted: Fri Nov 13, 2009 3:35 am
by bolly
Hi,

I wanted to have a chance that a monster would jump out and needed random

Can i get this added?

int EQ2Emu_lua_GetRand(lua_State* state) {
if(!lua_interface)
return 0;

srand(time(0));
int max = lua_interface->GetInt32Value(state, 1);
int randomNumber = rand();
int value = (randomNumber % max) + 1;
//LogFile->write(EQEMuLog::Debug, "Random Value was: %i", value);
lua_interface->SetInt32Value(state, value);
return 1;
}

Cheers

Re: LUA GetRand

Posted: Fri Nov 13, 2009 4:28 am
by LethalEncounter
Isn't there already a function built into LUA for random numbers? I thought there was, but if not I can add it.

Re: LUA GetRand

Posted: Fri Nov 13, 2009 6:11 am
by Scatman
math.random(low, high) both are inclusive.

Re: LUA GetRand

Posted: Fri Nov 13, 2009 8:29 am
by bolly
thanks i have been without internet and had no lua documentation - yay for libraries and minilogin