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

LUA/SQL Level Reset

hodleo

Formerly cbrm -Crypto enthusiast, Retired scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,598
Solutions
3
Reaction score
955
Location
Caribbean Sea
TFS 0.2.5

This script isn't working :(
Lua:
function onLogin(cid)

if getPlayerLevel(cid) < 10 then 

	dofile("./config.lua")
	env = assert(luasql.mysql()) 
	con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))                
	id = getPlayerGUID(cid)           
	assert(con:execute("UPDATE `players` (`player_id` ,`level` ,`experience`) VALUES ('" .. id .. "', '10', '9300');"))
	con:close()
	env:close()
	
end
	return TRUE
end

Debug print:
PHP:
[21/09/2009 12:15:21] Lua Script Error: [CreatureScript Interface] 
[21/09/2009 12:15:21] data/creaturescripts/scripts/level10.lua:onLogin

[21/09/2009 12:15:21] data/creaturescripts/scripts/level10.lua:9: LuaSQL: Error executing query. MySQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`player_id` ,`level` ,`experience`) VALUES ('695', '10', '9300')' at line 1
[21/09/2009 12:15:21] stack traceback:
[21/09/2009 12:15:21] 	[C]: in function 'assert'
[21/09/2009 12:15:21] 	data/creaturescripts/scripts/level10.lua:9: in function <data/creaturescripts/scripts/level10.lua:1>

what is wrong in it?
 
Last edited:
Your query is is in wrong format, look:

Lua:
assert(con:execute("UPDATE `players` SET `level` = 10, `experience` = 9300 WHERE `id` = " .. id))
 
yeah he is right, it won't work because player is in game when executing this script. So if he'll logout out then all values will be overridden.
 
@yes since 10 is minimun level
so what can I do? onDie, onLogOut?

on a tfs 0.2.5
 
Maybe?
Lua:
function onLogout(cid)
    if getPlayerLevel(cid) < 10 then
	db.executeQuery("UPDATE `players` SET `level` = 10, `experience` = 9300 WHERE `player_id` = " .. getPlayerGUID(cid) .. "")
    end
    return TRUE
end
 
Last edited:
Use:
Code:
doPlayerAddExp
Code:
setCreatureMaxHealth
Code:
setCreatureMaxMana
Code:
doPlayerSetMaxCapacity


Maybe?
Lua:
function onLogout(cid)
    if getPlayerLevel(cid) < 10 then
	db.executeQuery("UPDATE `players` SET `level` = 10, `experience` = 9300 WHERE `id` = " .. id)
    return TRUE
    end
end

It'll not work! You can't change player' values while he's online!
 
Use:
Code:
doPlayerAddExp
Code:
setCreatureMaxHealth
Code:
setCreatureMaxMana
Code:
doPlayerSetMaxCapacity




It'll not work! You can't change player' values while he's online!

I had it with doPlayerAddExp but that'sbuggy since player sometimes gets to lvl 8,below or he gets more experience than lvl10(9300)

I need it when player dies so he comes back with lvl 10
 
-.- just set exp to 9300 points that is lvl 10 that value is on tibia exp table
 
If you add exp = add level it should auto add hp and mana. If you add it to database 'level = 10' it will not change hp/mp and player after few deaths can have 0 hp (die every login, sux).
Maybe?
Lua:
function onLogout(cid)
    if getPlayerLevel(cid) < 10 then
	db.executeQuery("UPDATE `players` SET `level` = 10, `experience` = 9300 WHERE `player_id` = " .. getPlayerGUID(cid) .. "")
    return TRUE
    end
end
I'm not sure, but if Elf didnt change it players cant login if function 'onlogin' doesnt return true. It wont work, because player is online and when logout server will save his level again.
Script:
Lua:
function onLogout(cid)
    if getPlayerLevel(cid) < 10 then
        doPlayerAddExp(cid, 9300 - getPlayerExperience(cid))
    end
    return TRUE
end
It should add hp/mp/cap and set level 10 (9300 exp for lvl 10).
EDIT:
@down
player_exp + needed_exp = 9300
9300 - player_exp = needed_exp

hardcore math :D
 
Last edited:
@chojrak
=.= 9300 are the experience points when you are lvl 10 on tibia
but doPlayerExp adds more or less exp so I need it clean
 
hm ok gesior then I need to set it : (my sorc sample)
lvl 10
exp 9300
all skills 10
hp 180
mp 35
cap 250
 
Edit characters in the database manually. :thumbup:
(Sucks if you have over 50 players).
 
@JDB
wtf? every time a char levels down to 9!!? no way codes make our life easier

@Gesior
that's what I'm talking about xD pure math
 
Back
Top