English Tibia save error

4 replies
Goto Page
To the start Previous 1 Next To the start
21.04.17 02:26:37 pm
Up
Goo
User
Offline Off
Please help me with this error I will try to explain the problem:
First the error:
Code:
1
2
3
4
5
LUA ERROR: sys/lua/cs2dtibia/saves/players.lua:3: '}' expected near '#'
 -> [C]: in function 'dofile'
 -> sys/lua/cs2dtibia/server.lua:138: in main chunk
 -> [C]: in function 'dofile'
 -> sys/lua/server.lua:1: in main chunk


And now the problem.
When you die from a monster and disconnect without respawning you will have your save as:
Code:
1
PLAYERCACHE[99153] = {Inventory={326}, Tutorial={inventory=true, hitm=true, safe=true, die=true}, MP=0, Money=4970, name="Player", Equipment={}, Experience=0, tmp={usgn=99153, atk=0, def=0, equip={{}, {}, {}, {}, {}, {}, {}, {}, {}}, exhaust={talk=false, use=false}, hp=100, spd=0}, Info={}, Level=1, HP=-1.#INF, Spawn={160, 176}}


Now if we look careful we see this:
Code:
1
hp=100, spd=0}, Info={}, Level=1, HP=-1.#INF

1. Why is there hp and HP?
2. The error comes when you do what I said above and leave then your HP is -1.#INF and the # breaks the saves!!!
Please help!!!
21.04.17 02:42:43 pm
Up
Yates
Reviewer
Offline Off
PLAYERCACHE[99153].hp
and
PLAYERCACHE[99153].HP
are two different things.

The funny thing is Tibia doesn't really use either of them for what they are actually meant for; having items increase/decrease your health. It doesn't work properly or at all if I remember correctly.

You shall have to remove them or rebuild the way health and mana stats on items work. Or to quick fix this error you find the save function and set the player's
hp
and
HP
manually to 0 or something, even better would be to find the tbl_to_txt (pretty sure it was called that) function and check every entry for these kinds of things so you won't have to deal with it again.
21.04.17 02:51:22 pm
Up
Goo
User
Offline Off
I do want to be able to save health from items like having helmet increase your health by 5 and then it will save I just don't want to to it now
And I found that function and everything is in one big string!
And I think you meant table.val_to_str
21.04.17 02:53:31 pm
Up
Yates
Reviewer
Offline Off
user Goo has written:
And I think you meant table.val_to_str

Yeah that's it, all the frustrating Tibia code memories come rushing back.

As for fixing it, it took me quite some time to get it fully working and you have to change a shitload of functions. Good luck with that.
21.04.17 04:13:56 pm
Up
Goo
User
Offline Off
OK so I fixed it like that it was pretty easy once I understood how those things work:
Created this function in functions.lua:
Code:
1
2
3
4
5
6
7
8
function getHealth(id)
     local health=player(id,"health")
     if not tonumber(health) or health<0 or health=="-1.#INF" then
          return 0
     else
          return health
     end
end


And then I replaced everything that used the CS2D default get health
More >

with getHealth(parameter)
And that wasn't enough I actually had to add this in the leave hook:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
if not tonumber(PLAYERS[id].tmp.hp) or PLAYERS[id].tmp.hp<0 then
          PLAYERS[id].tmp.hp=0
     end
     if not tonumber(PLAYERS[id].tmp.HP) or PLAYERS[id].tmp.HP<0 then
          PLAYERS[id].tmp.HP=0
     end
     if not tonumber(PLAYERS[id].hp) or PLAYERS[id].hp<0 then
          PLAYERS[id].hp=0
     end
     if not tonumber(PLAYERS[id].HP) or PLAYERS[id].HP<0 then
          PLAYERS[id].HP=0
     end

IT HAS TO BE BEFORE EVERY SINGLE LINE IT JUST HAS TO BE ON THE TOP!

Thanks for hints @user Yates:
To the start Previous 1 Next To the start