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

[release] onAdvance

4220niller

XHTML / CSS Coder
Joined
Jul 4, 2007
Messages
127
Reaction score
1
Location
Denmark, Korsør
hey guys, i once saw someone who requested a onAdvance function, so i decided to make one for TFS.

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:
I'v never seen this before could u explain abit more what it does?
 
I'v never seen this before could u explain abit more what it does?

well this fires a script when you advance in level, magic level or a skill


HOW TO USE IT:
Open the file you need: axe, fist, club, level, maglevel or whatever you need to set a script on, and then inside the function onAdvance you add your script
 
well this fires a script when you advance in level, magic level or a skill


HOW TO USE IT:

Example if i get an skill in axe fighting the script will start working right? what will happen then
 
then it will fire the script that you have inside the advances/axe.lua inside the onAdvance(cid, oldlevel, newlevel) function. That means
function(cid, oldlevel, newlevel)
PUT YOUR SCRIPT IN HERE
end

ill post some examples:
creaturescripts/scripts/advances/axe.lua
Code:
function onAdvance(cid, oldlevel, newlevel)
	if newlevel == 11 then
		doPlayerSendTextMessage(cid, 22, "You just got your first Axe Fighting skill!")
	end
end
If he/she advanced to axe fighting level 11 then it will send the message: "You just got your first Axe Fighting skill!"

creaturescripts/scripts/advances/maglevel.lua
Code:
function onAdvance(cid, oldlevel, newlevel)
	doSendMagicEffect(getPlayerPosition(cid),12)
	doCreatureSay(cid,"ME GOT MAGIC LEVEL!!",TALKTYPE_SAY)
end
If he/she advanced in magic level then he/she will get a healing effect on him/her, and say: "ME GOT MAGIC LEVEL!!"
 
Last edited:
Hmm, some ideia to use it?
I was think to use a magic effect when you get skills & itens when you get hi-levels...
 
it is pretty easy to do such things with it, but i would like to see if someone else would try to do something with it, since it's boring beeing the only one making such scripts.
 
I dont have the think.lua file :S what do I have to put in it exactly in order to create one :)
 
if you dont have it, make one with this contents:
Code:
function onThink(cid, interval)
	dofile("./data/creaturescripts/scripts/onAdvance.lua")
	onAdvanceController(cid)
	return TRUE
end
 
Hmm, some ideia to use it?
I was think to use a magic effect when you get skills & itens when you get hi-levels...
I use it to teleport player to main city when he get 8 lvl. Players on my server choose vocation in acc maker (page), but i need rook (1 lvl chars trap higher levels).
THANK YOU VERY MUCH for this script and samples!
 
i use the last version of TFS and don't work this function, have a onThink error, why?
 
Just see 2 posts before :)

men i put these script and the error continue!!

this is the error:

Code:
Lua Script Error: [CreatureScript Interface] 
data/creaturescripts/scripts/think.lua:onThink

./data/creaturescripts/scripts/onAdvance.lua:34: attempt to compare nil with number
 
i want to some like this (that send a magic effect when you reach xlvl, or like each level):

Code:
--onAdvance system by 4220niller

function onAdvance(cid, oldlevel, newlevel)
	if newlevel == 20 then
		local ppos = getPlayerPosition(cid)
		local positions = {
			{x=ppos.x-3, y=ppos.y-1, z=ppos.z},
			{x=ppos.x-1, y=ppos.y-1, z=ppos.z},
			{x=ppos.x, y=ppos.y-1, z=ppos.z},
			{x=ppos.x+1, y=ppos.y-1, z=ppos.z},
			{x=ppos.x+3, y=ppos.y-1, z=ppos.z},
			{x=ppos.x+4, y=ppos.y-1, z=ppos.z},
			{x=ppos.x+5, y=ppos.y-1, z=ppos.z},
			
			{x=ppos.x-3, y=ppos.y, z=ppos.z},
			{x=ppos.x-1, y=ppos.y, z=ppos.z},
			{x=ppos.x+1, y=ppos.y, z=ppos.z},
			{x=ppos.x+3, y=ppos.y, z=ppos.z},
			{x=ppos.x+5, y=ppos.y, z=ppos.z},
			
			{x=ppos.x-3, y=ppos.y+1, z=ppos.z},
			{x=ppos.x-1, y=ppos.y+1, z=ppos.z},
			{x=ppos.x, y=ppos.y+1, z=ppos.z},
			{x=ppos.x+1, y=ppos.y+1, z=ppos.z},
			{x=ppos.x+3, y=ppos.y+1, z=ppos.z},
			{x=ppos.x+4, y=ppos.y+1, z=ppos.z},
			{x=ppos.x+5, y=ppos.y+1, z=ppos.z},
		}
		local effect = math.random(CONST_ME_FIREWORK_YELLOW,CONST_ME_FIREWORK_BLUE)
		for i = 1, table.getn(positions) do
			doSendMagicEffect(positions[i],effect)
		end
	end
end

but when i put on my server it give me this error:
Code:
Warning: [Event::loadScript] Event level not found. data/creaturescripts/scripts/level.lua
 
Back
Top