Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,336
- Solutions
- 68
- Reaction score
- 1,018
I am not sure if this is better than the lua random but I used the c++ random for this.
Maybe someone can tell me a better way to do this.
luascript.h
find
add
luascript.cpp
find
add
find
Under all that code add
Then you can use
Game.randNumbers(num1, num2)
Game.randNumbers(num) -> Will rand 1-num
Maybe someone can tell me a better way to do this.
luascript.h
find
Lua:
static int luaGameLoadMap(lua_State* L);
add
Lua:
static int luaGameRandNumbers(lua_State* L);
luascript.cpp
find
Lua:
registerMethod("Game", "loadMap", LuaScriptInterface::luaGameLoadMap);
add
Lua:
registerMethod("Game", "randNumbers", LuaScriptInterface::luaGameRandNumbers);
find
Lua:
int LuaScriptInterface::luaGameLoadMap(lua_State* L)
Under all that code add
Lua:
int LuaScriptInterface::luaGameRandNumbers(lua_State* L)
{
uint64_t num1 = getNumber<uint64_t>(L, 1);
uint64_t num2 = getNumber<uint64_t>(L, 2);
uint64_t rand;
if (!num2) {
rand = uniform_random(
static_cast<int64_t>(1),
static_cast<int64_t>(num1)
);
} else {
rand = uniform_random(
static_cast<int64_t>(num1),
static_cast<int64_t>(num2)
);
}
if (!rand) {
lua_pushnil(L);
}
lua_pushnumber(L, rand);
return 1;
}
Then you can use
Game.randNumbers(num1, num2)
Game.randNumbers(num) -> Will rand 1-num
Last edited: