LUA GetRand

EQ2Emulator Development forum.

Moderator: Team Members

Post Reply
bolly
Retired
Posts: 389
Joined: Mon Sep 21, 2009 3:03 pm
Location: Leeds, UK

LUA GetRand

Post by bolly » Fri Nov 13, 2009 3:35 am

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

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Re: LUA GetRand

Post by LethalEncounter » Fri Nov 13, 2009 4:28 am

Isn't there already a function built into LUA for random numbers? I thought there was, but if not I can add it.

User avatar
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

Post by Scatman » Fri Nov 13, 2009 6:11 am

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

Post by bolly » Fri Nov 13, 2009 8:29 am

thanks i have been without internet and had no lua documentation - yay for libraries and minilogin

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest