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

Solved Trying to add "getPlayerRebirths"

Cornwallis

Member
Joined
Jan 3, 2010
Messages
480
Reaction score
16
I'm using 0.2.14, and I'm trying to add a LUA function, getPlayerRebirths(cid). I have rebirths as a field in my SQL database, and I'm trying to make this return how many rebirths the player has. I tried to do it like the getPlayerLevel, but there was an error on compiling. Then I tried doing it like the getPlayerSex, basically because the tibia client doesn't have the players sex anywhere on it. I figured maybe the getPlayerLevel gets the level from the tibia client because that would be quicker than checking the database, but I could, and probably are, wrong. But I'm not sure where everything's located because for the getPlayerSex, it returns getSex, then getSex returns Sex, and i just don't know where it actually finds if your sex is = 1 or 2 is lol, so if someone could give me some help with this that would be great.
 
First of all, formatting the text.

CBF reading it but i'm guessing you want something like this
LUA:
Information is money
 
Last edited by a moderator:
One of the features I would always recommend doing in C++ is reborn system.

In player.h below "Skulls_t getSkull() const;" add:
[cpp] uint32_t getRebornCount() const {return rebornCount;}
void setRebornCount(uint32_t newValue) {rebornCount = newValue;} [/cpp]

After "protected:" add:
[cpp] uint32_t rebornCount;[/cpp]

In iologindata.cpp:
In loadPlayer() add:
[cpp]`reborns`,[/cpp]
after:
[cpp]query << "SELECT `id`, `account_id`,[/cpp]

After:
[cpp] player->blessings = result->getDataInt("blessings");[/cpp]
add:
[cpp] player->rebornCount = result->getDataInt("reborns");[/cpp]

In savePlayer() add:
[cpp] query << "`reborns` = " << player->rebornCount << ", ";[/cpp]
After:
[cpp] query << "`town_id` = " << player->town << ", ";[/cpp]


Luascript.cpp:

Set reborns:
[cpp]int32_t LuaScriptInterface::luaSetRebornCount(lua_State* L)
{
//setRebornCount(cid, newValue)
uint32_t newValue = popNumber(L);
uint32_t cid = popNumber(L);

ScriptEnvironment* env = getScriptEnv();
Player* player = env->getPlayerByUID(cid);
if(player)
{
player->setRebornCount(newValue);
lua_pushboolean(L, true);
}
else
{
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}[/cpp]

Get reborns:
[cpp]int32_t LuaScriptInterface::luaGetRebornCount(lua_State* L)
{
return internalGetPlayerInfo(L, PlayerInfoRebornCount);
}[/cpp]

After:
[cpp] case PlayerInfoAccess:
value = player->accessLevel;
break;[/cpp]
Add:
[cpp] case PlayerInfoRebornCount:
value = player->getRebornCount();
break;[/cpp]

In luascript.h add:
[cpp] PlayerInfoRebornCount,[/cpp]
After:
[cpp] PlayerInfoBankBalance, [/cpp]
 
Thanks a lot, and yeah I figured it'd be better to do it in C++, might aswell do it the right way while I can. Now I'm gonna see if I can figure out how to make spells depend on rebirth, I'll try it myself :P thanks again
 
You also have to register the functions in luascript.cpp and add the declaration of the method in luascript.h
 
Back
Top