• 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!

TFS 0.X C++ to Lua Code

Guizek69

New Member
Joined
Jul 14, 2020
Messages
10
Reaction score
3
Hello Otlanders!

I would like to use this TFS 1.2 function in my TFS 0.4 for fun.

Could anyone help me convert this code?

int LuaScriptInterface::luaPlayerGetContainerById(lua_State* L)
{
// player:getContainerById(id)
Player* player = getUserdata<Player>(L, 1);
if (!player) {
lua_pushnil(L);
return 1;
}

Container* container = player->getContainerByID(getNumber<uint8_t>(L, 2));
if (container) {
pushUserdata<Container>(L, container);
setMetatable(L, -1, "Container");
} else {
lua_pushnil(L);
}
return 1;
}

Container* Player::getContainerByID(uint8_t cid)
{
auto it = openContainers.find(cid);
if (it == openContainers.end()) {
return nullptr;
}
return it->second.container;
}
 
Back
Top