4220niller
XHTML / CSS Coder
hey guys, i once saw someone who requested a onAdvance function, so i decided to make one for TFS.
data/creaturescripts/scripts/onAdvance.lua
Then you need to make a new directory in data/creaturescritps/scripts/ and name it advances.
then in data/creaturescripts/scripts/advances/ add the following files: axe.lua, club.lua, distance.lua, fishing.lua, fist.lua, level.lua, maglevel.lua, shield.lua, sword.lua.
Then add this in all of the files:
Now add this in data/global.lua:
And add this in data/creaturescripts/scripts/login.lua:
And add this in data/creaturescripts/scripts/think.lua (in the onLogin function:
then your creaturescripts.xml should look a little like this:
If you have another PlayerLogin/PlayerThink event then add the above things in that/those file(s)
data/creaturescripts/scripts/onAdvance.lua
Code:
--onAdvance system by 4220niller
--xmlReader might be implemented later so that you can have multiple scripts
--there is no onDeAdvance() since it equals to onDeath()
function onAdvanceController(cid)
local skillLevel = OLD_LEVELS[cid]
local level = getPlayerLevel(cid)
local skillMagLevel = OLD_MAGLEVELS[cid]
local maglevel = getPlayerMagLevel(cid)
local skillFist = OLD_FIST[cid]
local fist = getPlayerSkill(cid,SKILL_FIST)
local skillClub = OLD_CLUB[cid]
local club = getPlayerSkill(cid,SKILL_CLUB)
local skillSword = OLD_SWORD[cid]
local sword = getPlayerSkill(cid,SKILL_SWORD)
local skillAxe = OLD_AXE[cid]
local axe = getPlayerSkill(cid,SKILL_AXE)
local skillDistance = OLD_DISTANCE[cid]
local distance = getPlayerSkill(cid,SKILL_DISTANCE)
local skillShield = OLD_SHIELD[cid]
local shield = getPlayerSkill(cid,SKILL_SHIELD)
local skillFishing = OLD_FISHING[cid]
local fishing = getPlayerSkill(cid,SKILL_FISHING)
--Levels
if skillLevel < level then
dofile("./data/creaturescripts/scripts/advances/level.lua")
onAdvance(cid, skillLevel, level)
OLD_LEVELS[cid] = level
end
--Magic Levels
if skillMagLevel < maglevel then
dofile("./data/creaturescripts/scripts/advances/maglevel.lua")
onAdvance(cid, skillMagLevel, maglevel)
OLD_MAGLEVELS[cid] = maglevel
end
--Fist
if skillFist < fist then
dofile("./data/creaturescripts/scripts/advances/fist.lua")
onAdvance(cid, skillFist, fist)
OLD_FIST[cid] = fist
end
--Club
if skillClub < club then
dofile("./data/creaturescripts/scripts/advances/club.lua")
onAdvance(cid, skillClub, club)
OLD_CLUB[cid] = club
end
--Sword
if skillSword < sword then
dofile("./data/creaturescripts/scripts/advances/sword.lua")
onAdvance(cid, skillSword, sword)
OLD_SWORD[cid] = sword
end
--Axe
if skillAxe < axe then
dofile("./data/creaturescripts/scripts/advances/axe.lua")
onAdvance(cid, skillAxe, axe)
OLD_AXE[cid] = axe
end
--Distance
if skillDistance < distance then
dofile("./data/creaturescripts/scripts/advances/distance.lua")
onAdvance(cid, skillDistance, distance)
OLD_DISTANCE[cid] = distance
end
--Shield
if skillShield < shield then
dofile("./data/creaturescripts/scripts/advances/shield.lua")
onAdvance(cid, skillShield, shield)
OLD_SHIELD[cid] = shield
end
--Fishing
if skillFishing < fishing then
dofile("./data/creaturescripts/scripts/advances/fishing.lua")
onAdvance(cid, skillFishing, fishing)
OLD_FISHING[cid] = fishing
end
return TRUE
end
Then you need to make a new directory in data/creaturescritps/scripts/ and name it advances.
then in data/creaturescripts/scripts/advances/ add the following files: axe.lua, club.lua, distance.lua, fishing.lua, fist.lua, level.lua, maglevel.lua, shield.lua, sword.lua.
Then add this in all of the files:
Code:
--onAdvance system by 4220niller
--xmlReader might be implemented later so that you can have multiple scripts
function onAdvance(cid, oldlevel, newlevel)
end
Now add this in data/global.lua:
Code:
--onAdvance system by 4220niller
OLD_LEVELS = {}
OLD_MAGLEVELS = {}
OLD_FIST = {}
OLD_CLUB = {}
OLD_SWORD = {}
OLD_AXE = {}
OLD_DISTANCE = {}
OLD_SHIELD = {}
OLD_FISHING = {}
And add this in data/creaturescripts/scripts/login.lua:
Code:
OLD_LEVELS[cid] = getPlayerLevel(cid)
OLD_MAGLEVELS[cid] = getPlayerMagLevel(cid)
OLD_FIST[cid] = getPlayerSkill(cid,SKILL_FIST)
OLD_CLUB[cid] = getPlayerSkill(cid,SKILL_CLUB)
OLD_AXE[cid] = getPlayerSkill(cid,SKILL_AXE)
OLD_SWORD[cid] = getPlayerSkill(cid,SKILL_SWORD)
OLD_DISTANCE[cid] = getPlayerSkill(cid,SKILL_DISTANCE)
OLD_SHIELD[cid] = getPlayerSkill(cid,SKILL_SHIELD)
OLD_FISHING[cid] = getPlayerSkill(cid,SKILL_FISHING)
And add this in data/creaturescripts/scripts/think.lua (in the onLogin function:
Code:
dofile("./data/creaturescripts/scripts/onAdvance.lua")
onAdvanceController(cid)
then your creaturescripts.xml should look a little like this:
Code:
<event type="login" name="PlayerLogin" script="login.lua"/>
<event type="logout" name="PlayerLogout" script="logout.lua"/>
<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
<event type="think" name="PlayerThink" script="think.lua"/>
If you have another PlayerLogin/PlayerThink event then add the above things in that/those file(s)
Last edited: