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

Solved Change Vocation Script Not Working Fully

Works tyvm!

Also if you don't mind could you also help me with another script?
The script is a change vocation script which works perfect except that it doesn't take away skills & magic lvl.

Code:
--SCRIPT BY AlcikOTS----tibiaserver.pl--BEST SERVER ONLINE--
-----------------------CONFIG---START-----------------------------------------
local config = {
	removelevel = 35, -- Amount of level taken away.
	itemid = 8982, -- Item ID.
	efekt = 2, -- Effect shown.
	skilafter = 10, -- What skill will the player have after change.
	minimumlevel = 100, -- What will be min level required? 
	magafter = 2, -- What magic level will he recive after change? 
	--Change only if you have edited your vocations.xml so players get more mana/health/cap each level.
	sorcincrease = {5, 30, 10}, --The amount of health/mana/cap that increases when Sorcerer levels up.
	druidincrease = {5, 30, 10}, --The amount of health/mana/cap that increases when Druid levels up.
	paladinincrease = {10, 10, 20}, --The amount of health/mana/cap that increases when Paladin levels up.
	knightincrease = {15, 5, 25} --The amount of health/mana/cap that increases when Knight levels up.
}
-----------------------CONFIG---END-------------------------------------------
 
function onSay(cid, words, param)
 
if(param == "") then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must say what vocation you want change to.")
		return TRUE
    end
 if(param == "sorcerer") or (param == "druid") or (param == "knight") or (param == "paladin") or (param == "Paladin") or (param == "Druid") or (param == "Sorcerer") or (param == "Knight") or (param == "sorc") or (param == "Sorc") then
		if getPlayerLevel(cid) >= config.minimumlevel then
			if getPlayerItemCount(cid, config.itemid) >= 1 then
				if(param == "sorcerer") or (param == "Sorcerer") or (param == "sorc") or (param == "Sorc") then	
					if getPlayerVocation(cid) > 1 then
					doPlayerAddLevel(cid, -(config.removelevel))
						doPlayerSetVocation(cid, 1) -- Sorc
						setCreatureMaxHealth(cid, (185+(config.sorcincrease[1]*((getPlayerLevel(cid)-8)))))
						setCreatureMaxMana(cid, (35+(config.sorcincrease[2]*((getPlayerLevel(cid)-8)))))
						doPlayerSetMaxCapacity(cid, (470+(config.sorcincrease[3]*((getPlayerLevel(cid)-8)))))
						doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to sorcerer.")
					else doPlayerSendCancel(cid, "You are already a sorcerer.")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					return TRUE
					end		
				end
 
				if(param == "druid") or (param == "Druid") then
					if getPlayerVocation(cid) == 1 or getPlayerVocation(cid) > 2 then
					doPlayerAddLevel(cid, -(config.removelevel))
						doPlayerSetVocation(cid, 2) -- Druid
						setCreatureMaxHealth(cid, (185+(config.druidincrease[1]*((getPlayerLevel(cid)-8)))))
						setCreatureMaxMana(cid, (35+(config.druidincrease[2]*((getPlayerLevel(cid)-8)))))
						doPlayerSetMaxCapacity(cid, (470+(config.druidincrease[3]*((getPlayerLevel(cid)-8)))))				
						doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to druid.")	
					else doPlayerSendCancel(cid, "You are already a druid.")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					return TRUE
					end	
				end
 
				if(param == "paladin") or (param == "Paladin") then
					if getPlayerVocation(cid) < 3 or getPlayerVocation(cid) > 3 then
					doPlayerAddLevel(cid, -(config.removelevel))
					doPlayerSetVocation(cid, 3) -- Sorc
						setCreatureMaxHealth(cid, (185+(config.paladinincrease[1]*((getPlayerLevel(cid)-8)))))
						setCreatureMaxMana(cid, (35+(config.paladinincrease[2]*((getPlayerLevel(cid)-8)))))
						doPlayerSetMaxCapacity(cid, (470+(config.paladinincrease[3]*((getPlayerLevel(cid)-8)))))
						doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to paladin.")
					else doPlayerSendCancel(cid, "You are already a paladin.")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					return TRUE
					end
				end	
 
				if(param == "knight") or (param == "Knight") then
					if getPlayerVocation(cid) < 4 then
					doPlayerAddLevel(cid, -(config.removelevel))
					doPlayerSetVocation(cid, 4) -- Sorc
						setCreatureMaxHealth(cid, (185+(config.knightincrease[1]*((getPlayerLevel(cid)-8)))))
						setCreatureMaxMana(cid, (35+(config.knightincrease[2]*((getPlayerLevel(cid)-8)))))	
						doPlayerSetMaxCapacity(cid, (470+(config.knightincrease[3]*((getPlayerLevel(cid)-8)))))
						doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to knight.")		
					else doPlayerSendCancel(cid, "You are already a knight.")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					return TRUE
					end
				end
 
				doPlayerRemoveItem(cid, config.itemid, 1)
				doPlayerAddMagLevel(cid, -((getPlayerMagLevel(cid))-config.magafter))
				doSendMagicEffect(getCreaturePosition(cid), config.efekt)
				doCreatureAddMana(cid, -((getCreatureMana(cid))-(getCreatureMaxMana(cid))))
				doCreatureAddHealth(cid, -((getCreatureHealth(cid))-(getCreatureMaxHealth(cid))))
							for a = 0,6 do
								doPlayerAddSkill(cid, a, -(getPlayerSkillLevel(cid, a)-config.skilafter))
							end	
 
			else doPlayerSendCancel(cid, "You need "..getItemNameById(config.itemid).." to change your vocation.")
			doSendMagicEffect(getCreaturePosition(cid), 2)
			end
		else doPlayerSendCancel(cid, "You don't have enough level. Your level must be "..(config.minimumlevel).." or higher.")
		doSendMagicEffect(getCreaturePosition(cid), 2)
		end
else doPlayerSendCancel(cid, "You must say what vocation you want change to.")
doSendMagicEffect(getCreaturePosition(cid), 2)
end
end
 
Replace
Code:
doPlayerAddSkill(cid, a, -(getPlayerSkillLevel(cid, a)-config.skilafter))
with
Code:
doPlayerAddSkillTry(cid, a, getPlayerSkillTries(cid, a)*-1)
doPlayerAddSkill(cid, a, config.skilafter)

Your intial script should work tho, but try the above if there aren't errors..
 
Replace
Code:
doPlayerAddSkill(cid, a, -(getPlayerSkillLevel(cid, a)-config.skilafter))
with
Code:
doPlayerAddSkillTry(cid, a, getPlayerSkillTries(cid, a)*-1)
doPlayerAddSkill(cid, a, config.skilafter)

Your intial script should work tho, but try the above if there aren't errors..
It adds 10 skills to fist,club,sword etc instead of removing them.
 
Oh yea, skill tries are just for a single level.
You can try this:
Code:
doPlayerAddSkill(cid, a, (getPlayerSkillLevel(cid, a)-config.skilafter)*-1)
If that fails, we can conclude doPlayerAddSkill doesn't support negative values, and so we must edit the crap via a sql query.
 
Oh yea, skill tries are just for a single level.
You can try this:
Code:
doPlayerAddSkill(cid, a, (getPlayerSkillLevel(cid, a)-config.skilafter)*-1)
If that fails, we can conclude doPlayerAddSkill doesn't support negative values, and so we must edit the crap via a sql query.

Same :S
 
Try this then - replace the whole for... loop with this:
Code:
local id = getPlayerGUIDByName(getCreatureName(cid))
doRemoveCreature(cid, true)
addEvent(function(x)
 db.query("UPDATE player_skills SET `value`= 10 WHERE `player_id` = "..x..";")
end, 10, id)
 
Try this then - replace the whole for... loop with this:
Code:
local id = getPlayerGUIDByName(getCreatureName(cid))
doRemoveCreature(cid, true)
addEvent(function(x)
 db.query("UPDATE player_skills SET `value`= 10 WHERE `player_id` = "..x..";")
end, 10, id)
Now it resets everything it is supposed to except sword & magic lvl.
 
You're awfully sure you don't want to reset the magic level? A knight with magic level 50 or so crashes the server once he casts a spell, afaik.
 
You said:
Now it resets everything it is supposed to except sword & magic lvl.
I think you mean:
Now it resets everything, like it is supposed to, but I want to reset everything except sword & magic levels.

I'm not sure what you want.
 
You said:
Now it resets everything it is supposed to except sword & magic lvl.
I think you mean:
Now it resets everything, like it is supposed to, but I want to reset everything except sword & magic levels.

I'm not sure what you want.

I meant that it resets everything the script is supposed to reset but it doesnt reset sword and magic.
-Resets fist,club,axe,distance,shielding,fishing,
-Doesnt reset sword,magic
 
Code:
local id = getPlayerGUIDByName(getCreatureName(cid))
doRemoveCreature(cid, true)
addEvent(function(x)
 db.query("UPDATE player_skills SET `value`= 10 WHERE `player_id` = "..x..";")
 db.query("UPDATE players SET `maglevel`= 10 WHERE `id` = "..x..";")
end, 10, id)
Sword level should already work..
 
Code:
local id = getPlayerGUIDByName(getCreatureName(cid))
doRemoveCreature(cid, true)
addEvent(function(x)
 db.query("UPDATE player_skills SET `value`= 10 WHERE `player_id` = "..x..";")
 db.query("UPDATE players SET `maglevel`= 10 WHERE `id` = "..x..";")
end, 10, id)
Sword level should already work..
Sword doesnt work :s & magic lvl goes to 10.
 
You wear some item that gives sword level or something?
Replace
db.query("UPDATE players SET `maglevel`= 10 WHERE `id` = "..x..";")
with
db.query("UPDATE players SET `maglevel`= 2 WHERE `id` = "..x..";")
 
You wear some item that gives sword level or something?
Replace
db.query("UPDATE players SET `maglevel`= 10 WHERE `id` = "..x..";")
with
db.query("UPDATE players SET `maglevel`= 2 WHERE `id` = "..x..";")

Works perfect now! Thanks very much!

And yeh I was waring fireborn giant armor which gave +2 sword xD.
 
Back
Top