• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua 'setWorldType' equivalent in TFS 1.0

dominique120

Science & Reason
Senator
Premium User
Joined
Jun 16, 2013
Messages
3,881
Solutions
3
Reaction score
1,046
Location
Númenor
What is the name of the function to change world type in TFS 1.0?

Mainly I use it in this script:
Code:
local t = {
    ["Monday"] = {WORLDTYPE_OPEN, "Its Monday, that means its time to get out there and KILL!"},
    ["Tuesday"] = {WORLDTYPE_OPTIONAL, "Hope you enjoyed PVP Mondays!"},
    ["Friday"] = {WORLDTYPE_OPTIONAL, "Time for PVP-E!!!"},
    ["Saturday"] = {WORLDTYPE_OPTIONAL, "Hope you enjoyed PVPE Fridays!"}
}

function onTime()
local v = t[os.date("%A")]
    if v then
        setWorldType(v[1])
        doBroadcastMessage(v[2], MESSAGE_EVENT_ADVANCE)
    end
    return true
end
 
You could add the function by your own...

go to luascript.h and add:
Code:
static int32_t luaSetWorldType(lua_State* L);

now on luascript.cpp search:
Code:
lua_register(m_luaState, "getWorldType", LuaScriptInterface::luaGetWorldType);

add after:
Code:
//setWorldType(type)
lua_register(m_luaState, "setWorldType", LuaScriptInterface::luaSetType);

search:
Code:
int32_t LuaScriptInterface::luaGetWorldTime(lua_State* L)

and before it, add:
Code:
int32_t LuaScriptInterface::luaSetWorldType(lua_State* L)
{
    //setWorldType(type)
    WorldType_t type = static_cast<WorldType_t>(getNumber<int64_t>(L, 1));
    g_game.setWorldType(type);
    pushBoolean(L, true);
    return 1;
}

done.
 
You could add the function by your own...

go to luascript.h and add:
Code:
static int32_t luaSetWorldType(lua_State* L);

now on luascript.cpp search:
Code:
lua_register(m_luaState, "getWorldType", LuaScriptInterface::luaGetWorldType);

add after:
Code:
//setWorldType(type)
lua_register(m_luaState, "setWorldType", LuaScriptInterface::luaSetType);

search:
Code:
int32_t LuaScriptInterface::luaGetWorldTime(lua_State* L)

and before it, add:
Code:
int32_t LuaScriptInterface::luaSetWorldType(lua_State* L)
{
    //setWorldType(type)
    WorldType_t type = static_cast<WorldType_t>(getNumber<int64_t>(L, 1));
    g_game.setWorldType(type);
    pushBoolean(L, true);
    return 1;
}

done.

Little error here:
Code:
1>..\src\luascript.cpp(1271): error C2039: 'luaSetType' : is not a member of 'LuaScriptInterface'
1>          c:\users\dominique\documents\github\forgottenserver - copy\src\luascript.h(208) : see declaration of 'LuaScriptInterface'
1>..\src\luascript.cpp(1271): error C2065: 'luaSetType' : undeclared identifier
1>  map.cpp
 
...

change:
Code:
lua_register(m_luaState, "setWorldType", LuaScriptInterface::luaSetType);

to:
Code:
lua_register(m_luaState, "setWorldType", LuaScriptInterface::luaSetWorldType);

you were supposed to try to fix it by yourself :/
 
Back
Top