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
LUA GetRand
Moderator: Team Members
-
LethalEncounter
- Team: Zombie
- Posts: 2717
- Joined: Wed Jul 25, 2007 10:10 pm
Re: LUA GetRand
Isn't there already a function built into LUA for random numbers? I thought there was, but if not I can add it.
- Scatman
- Retired
- Posts: 1688
- Joined: Wed Apr 16, 2008 5:44 am
- EQ2Emu Server: Scatman's Word
- Characters: Scatman
- Location: New Jersey
Re: LUA GetRand
math.random(low, high) both are inclusive.
-
bolly
- Retired
- Posts: 389
- Joined: Mon Sep 21, 2009 3:03 pm
- Location: Leeds, UK
Re: LUA GetRand
thanks i have been without internet and had no lua documentation - yay for libraries and minilogin
Who is online
Users browsing this forum: No registered users and 1 guest