Forum

> > CS2D > Scripts > Tibia save error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Tibia save error

4 replies
To the start Previous 1 Next To the start

old Tibia save error

Mami Tomoe
User Off Offline

Quote
Please help me with this error I will try to explain the problem:
First the error:
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:
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:
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!!!

old Re: Tibia save error

Yates
Reviewer Off Offline

Quote
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.

old Re: Tibia save error

Mami Tomoe
User Off Offline

Quote
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

old Re: Tibia save error

Yates
Reviewer Off Offline

Quote
user Mami Tomoe 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.

old Re: Tibia save error

Mami Tomoe
User Off Offline

Quote
OK so I fixed it like that it was pretty easy once I understood how those things work:
Created this function in functions.lua:
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:
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
Log in to reply Scripts overviewCS2D overviewForums overview