• 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 Change Vocation Script - ALMOST working

Galaxy

New Member
Joined
Feb 24, 2011
Messages
108
Reaction score
1
Location
Ireland/Carlow
Hello,
I have a script that changes your vocation. Almost everything works perfectly but when I change from which ever vocation to which ever vocation, I get an error in my console that says:

vocationscript.jpg

Here is my script for vocation change:
Code:
-----------------------CONFIG---START-----------------------------------------
local config = {
	removelevel = 1, -- Amount of level taken away.
	itemid = 11207, -- Item ID.
	efekt = 2, -- Effect shown.
	skilafter = 10, -- What skill will the player have after change.
	minlevel = 90, -- What will be min level required? 
	magafter = 5, -- What magic level will he recive after change? 
}
-----------------------CONFIG---END-------------------------------------------
 
function onSay(cid, words, param)
	local param, oldVoc = param:lower(), 0
	local voc = {
	['sorcerer'] = {hp = 5, mana = 30, cap = 10, voc = 1},
	['druid'] = {hp = 5, mana = 30, cap = 10, voc = 2},
	['paladin'] = {hp = 10, mana = 15, cap = 20, voc = 3},
	['knight'] = {hp = 15, mana = 5, cap = 25, voc = 4},
	}
 
	if(getPlayerVocation(cid) > 4)then
		oldVoc = getPlayerVocation(cid)-4
	else
		oldVoc = getPlayerVocation(cid)
	end		
 
	if(voc[param])then
		if getPlayerLevel(cid) >= config.minlevel then
			if(getPlayerItemCount(cid, config.itemid) > 0)then
				if(oldVoc ~= voc[param].voc)then
					doPlayerAddLevel(cid, -(config.removelevel)) --Set new level
					doPlayerSetVocation(cid, voc[param].voc) --Change vocation
					setCreatureMaxHealth(cid, (185+((getPlayerLevel(cid)-8)*voc[param].hp))) --Set new hp
					setCreatureMaxMana(cid, (35+((getPlayerLevel(cid)-8)*voc[param].mana))) --Set new mana
					doPlayerSetMaxCapacity(cid, (470+((getPlayerLevel(cid)-8)*voc[param].cap))) --Set new cap
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to ".. param ..".")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					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, -(getPlayerSkillLevel(cid, a)-config.skilafter))
					end	
				else
					 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You already are a ".. param ..".")
				end
			else
				 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have a ".. getItemNameById(config.itemid) ..".")
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be at least level ".. config.minlevel .." to use this command.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must say what vocation you want to change into, ie !changevoc sorcerer.")
	end
	return true
end

And here is my part in 050-function that has something to do with the error. Line 378.

Code:
function doPlayerAddMagLevel(cid, amount)
	for i = 1, amount do
		doPlayerAddSpentMana(cid, (getPlayerRequiredMana(cid, getPlayerMagLevel(cid, true) + 1) - getPlayerSpentMana(cid)) / getConfigInfo('rateMagic'))
	end
	return true
end

function doPlayerAddSkill(cid, skill, amount, round)
	if(skill == SKILL__LEVEL) then
		return doPlayerAddLevel(cid, amount, round)
	elseif(skill == SKILL__MAGLEVEL) then
		return doPlayerAddMagLevel(cid, amount)
	end

	return doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)) / getConfigInfo('rateSkill'))
end

Problem is: it doesn't set my magic level to 5 as it should and also doesn't reset my skills to 10 as it should ;(


I need to solve this problem very fast. I already fixed one problem with this script because it didn't work properly. But I just can't fix this problem ;/ Im not that good at lua as I thought. :(

Thanks :)

HUGE EDIT OMG!!! I am so proud of myself... I solved 1 problem...

I changed this line in 050-functions
Code:
function doPlayerAddSkill(cid, [COLOR="#0000CD"]a,[/COLOR] skill, amount, round)
The blue part is what I added ;D

so I got rid of the error in console...

BUT, the magic level and skills still dont reset as they should. So when changing vocation i do not get 5 maglevel and 10 skills
 

Attachments

  • vocationscript.jpg
    vocationscript.jpg
    65.1 KB · Views: 17 · VirusTotal
Last edited:
Lua:
doPlayerAddSkill(cid, -(getPlayerSkillLevel(cid, a)-config.skilafter))
-- U gotta put skill..
doPlayerAddSkill(cid, SKILL__LEVEL, -(getPlayerSkillLevel(cid, a)-config.skilafter))

Also idk if it will work with minus levels ^.-..
 
Try adding more parenthesis to this:
doPlayerAddSkill(cid, -(getPlayerSkillLevel(cid, a)-config.skilafter))

Like this:

doPlayerAddSkill(cid, -(getPlayerSkillLevel(cid, a)-(config.skilafter)))

And try what Milice said, but like this:

doPlayerAddSkill(cid, a, -(getPlayerSkillLevel(cid, a)-(config.skilafter)))
 
nah, it still doesnt reset my skills :S ;( (magic level and sword,axe etc skills...) it takes away 1 level tho... xD

EDIT EDIT!!

I just saw something... When I have this:

doPlayerAddSkill(cid, a, -(getPlayerSkillLevel(cid, a)-(config.skilafter)))

and this in function:

function doPlayerAddSkill(cid, skill, amount, round)
if(skill == SKILL__LEVEL) then
return doPlayerAddLevel(cid, amount, round)
elseif(skill == SKILL__MAGLEVEL) then
return doPlayerAddMagLevel(cid, amount)
end

return doPlayerAddSkillTry(cid, skill, (getPlayerRequiredSkillTries(cid, skill, getPlayerSkillLevel(cid, skill) + 1) - getPlayerSkillTries(cid, skill)) / getConfigInfo('rateSkill'))
end

it adds me skills LOOOL... and it should reset it to 5... I mean, every time i use command to change voc and it changes my voc, it gives me 1 skills lool xD interesting thing is that it only gives me shielding skills and sword skills... ;O
 
Try with this:
Lua:
-----------------------CONFIG---START-----------------------------------------
local config = {
	removelevel = 1, -- Amount of level taken away.
	itemid = 11207, -- Item ID.
	efekt = 2, -- Effect shown.
	skilafter = 10, -- What skill will the player have after change.
	minlevel = 90, -- What will be min level required? 
	magafter = 5, -- What magic level will he recive after change? 
}
-----------------------CONFIG---END-------------------------------------------
 
function onSay(cid, words, param)
	local param, oldVoc = param:lower(), 0
	local voc = {
	['sorcerer'] = {hp = 5, mana = 30, cap = 10, voc = 1},
	['druid'] = {hp = 5, mana = 30, cap = 10, voc = 2},
	['paladin'] = {hp = 10, mana = 15, cap = 20, voc = 3},
	['knight'] = {hp = 15, mana = 5, cap = 25, voc = 4},
	}
 
	if(getPlayerVocation(cid) > 4)then
		oldVoc = getPlayerVocation(cid)-4
	else
		oldVoc = getPlayerVocation(cid)
	end		
 
	if(voc[param])then
		if getPlayerLevel(cid) >= config.minlevel then
			if(getPlayerItemCount(cid, config.itemid) > 0)then
				if(oldVoc ~= voc[param].voc)then
					doPlayerAddLevel(cid, -(config.removelevel)) --Set new level
					doPlayerSetVocation(cid, voc[param].voc) --Change vocation
					setCreatureMaxHealth(cid, (185+((getPlayerLevel(cid)-8)*voc[param].hp))) --Set new hp
					setCreatureMaxMana(cid, (35+((getPlayerLevel(cid)-8)*voc[param].mana))) --Set new mana
					doPlayerSetMaxCapacity(cid, (470+((getPlayerLevel(cid)-8)*voc[param].cap))) --Set new cap
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to ".. param ..".")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					doPlayerRemoveItem(cid, config.itemid, 1)
					doSendMagicEffect(getCreaturePosition(cid), config.efekt)
					doCreatureAddMana(cid, -((getCreatureMana(cid))-(getCreatureMaxMana(cid))))
					doCreatureAddHealth(cid, -((getCreatureHealth(cid))-(getCreatureMaxHealth(cid))))
					doRemoveCreature(cid)
					db.executeQuery('UPDATE `player_skills` SET `value` = "..config.skilafter.." WHERE `player_id` = "..getPlayerGUID(cid)..";')
                                        db.executeQuery('UPDATE `player_skills`SET `value`= "..config.magafter.." WHERE `player_id`= "..getPlayerGUID(cid).." AND `skillid`= 7;')
						doPlayerSave(cid)
					end	
				else
					 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You already are a ".. param ..".")
				end
			else
				 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have a ".. getItemNameById(config.itemid) ..".")
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be at least level ".. config.minlevel .." to use this command.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must say what vocation you want to change into, ie !changevoc sorcerer.")
	end
	return true
end

It will kick player, then, change database values for skills, and then, save player... xD
 
Last edited:
lots of errors show about database... like, i dont have some SQL table or whatever like ;D

what should i add to my database? xD

AND BTW EDIT 2 ;d

It kicks player but still doesnt change his skills (magic level and skills)... maybe it would if those errors about database in my console wouldnt show up
 
Maybe that should work...

(i changed on last post... xD)

Will not work, another error...

Maybe this:
Lua:
-----------------------CONFIG---START-----------------------------------------
local config = {
	removelevel = 1, -- Amount of level taken away.
	itemid = 11207, -- Item ID.
	efekt = 2, -- Effect shown.
	skilafter = 10, -- What skill will the player have after change.
	minlevel = 90, -- What will be min level required? 
	magafter = 5, -- What magic level will he recive after change? 
}
-----------------------CONFIG---END-------------------------------------------
 
function onSay(cid, words, param)
	local param, oldVoc = param:lower(), 0
	local voc = {
	['sorcerer'] = {hp = 5, mana = 30, cap = 10, voc = 1},
	['druid'] = {hp = 5, mana = 30, cap = 10, voc = 2},
	['paladin'] = {hp = 10, mana = 15, cap = 20, voc = 3},
	['knight'] = {hp = 15, mana = 5, cap = 25, voc = 4},
	}
 
	if(getPlayerVocation(cid) > 4)then
		oldVoc = getPlayerVocation(cid)-4
	else
		oldVoc = getPlayerVocation(cid)
	end		
 
	if(voc[param])then
		if getPlayerLevel(cid) >= config.minlevel then
			if(getPlayerItemCount(cid, config.itemid) > 0)then
				if(oldVoc ~= voc[param].voc)then
					doPlayerAddLevel(cid, -(config.removelevel)) --Set new level
					doPlayerSetVocation(cid, voc[param].voc) --Change vocation
					setCreatureMaxHealth(cid, (185+((getPlayerLevel(cid)-8)*voc[param].hp))) --Set new hp
					setCreatureMaxMana(cid, (35+((getPlayerLevel(cid)-8)*voc[param].mana))) --Set new mana
					doPlayerSetMaxCapacity(cid, (470+((getPlayerLevel(cid)-8)*voc[param].cap))) --Set new cap
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to ".. param ..".")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					doPlayerRemoveItem(cid, config.itemid, 1)
					doSendMagicEffect(getCreaturePosition(cid), config.efekt)
					doCreatureAddMana(cid, -((getCreatureMana(cid))-(getCreatureMaxMana(cid))))
					doCreatureAddHealth(cid, -((getCreatureHealth(cid))-(getCreatureMaxHealth(cid))))
					doRemoveCreature(cid)
					db.executeQuery('UPDATE `player_skills` SET `value` = "..config.skilafter.." WHERE `player_id` = "..getPlayerGUID(cid)..";')
                    db.executeQuery('UPDATE `players` SET `maglevel`= "..config.magafter.." WHERE `id`= "..getPlayerGUID(cid)..";')
						doPlayerSave(cid)
					end	
				else
					 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You already are a ".. param ..".")
				end
			else
				 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have a ".. getItemNameById(config.itemid) ..".")
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be at least level ".. config.minlevel .." to use this command.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must say what vocation you want to change into, ie !changevoc sorcerer.")
	end
	return true
end
 
Last edited by a moderator:
well, i got this error when i try it :S

errorfastomng.jpg


cool that u r testing it as well ! ;D im very happy to hear that :p

EDIT

I got the same error with the above one as on the picture in this post :S
 
Last edited:
In this part:
Lua:
db.executeQuery('UPDATE `player_skills` SET `value` = "..config.skilafter.." WHERE `player_id` = "..getPlayerGUID(cid)..";')
                    db.executeQuery('UPDATE `players` SET `maglevel`= "..config.magafter.." WHERE `id`= "..getPlayerGUID(cid)..";')
						doPlayerSave(cid)
					end	
				else

Erase that end.... Its my error.... :/
 
Try this. Its an edited version of Dantarrix's.

Code:
-----------------------CONFIG---START-----------------------------------------
local config = {
	removelevel = 1, -- Amount of level taken away.
	itemid = 11207, -- Item ID.
	efekt = 2, -- Effect shown.
	skilafter = 10, -- What skill will the player have after change.
	minlevel = 90, -- What will be min level required? 
	magafter = 5, -- What magic level will he recive after change? 
}
-----------------------CONFIG---END-------------------------------------------
 
function onSay(cid, words, param)
	local param, oldVoc = param:lower(), 0
	local voc = {
	['sorcerer'] = {hp = 5, mana = 30, cap = 10, voc = 1},
	['druid'] = {hp = 5, mana = 30, cap = 10, voc = 2},
	['paladin'] = {hp = 10, mana = 15, cap = 20, voc = 3},
	['knight'] = {hp = 15, mana = 5, cap = 25, voc = 4},
	}
 
	if(getPlayerVocation(cid) > 4)then
		oldVoc = getPlayerVocation(cid)-4
	else
		oldVoc = getPlayerVocation(cid)
	end		
 
	if(voc[param])then
		if getPlayerLevel(cid) >= config.minlevel then
			if(getPlayerItemCount(cid, config.itemid) > 0)then
				if(oldVoc ~= voc[param].voc)then
					doPlayerAddLevel(cid, -(config.removelevel)) --Set new level
					doPlayerSetVocation(cid, voc[param].voc) --Change vocation
					setCreatureMaxHealth(cid, (185+((getPlayerLevel(cid)-8)*voc[param].hp))) --Set new hp
					setCreatureMaxMana(cid, (35+((getPlayerLevel(cid)-8)*voc[param].mana))) --Set new mana
					doPlayerSetMaxCapacity(cid, (470+((getPlayerLevel(cid)-8)*voc[param].cap))) --Set new cap
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to ".. param ..".")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					doPlayerRemoveItem(cid, config.itemid, 1)
					doSendMagicEffect(getCreaturePosition(cid), config.efekt)
					doCreatureAddMana(cid, -((getCreatureMana(cid))-(getCreatureMaxMana(cid))))
					doCreatureAddHealth(cid, -((getCreatureHealth(cid))-(getCreatureMaxHealth(cid))))
					doRemoveCreature(cid)
					db.executeQuery('UPDATE `player_skills` SET `value` = "..config.skilafter.." WHERE `player_id` = "..getPlayerGUID(cid)..";')
                    db.executeQuery('UPDATE `players` SET `maglevel`= "..config.magafter.." WHERE `id`= "..getPlayerGUID(cid)..";')
					doPlayerSave(cid)
				else
					 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You already are a ".. param ..".")
				end
			else
				 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have a ".. getItemNameById(config.itemid) ..".")
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be at least level ".. config.minlevel .." to use this command.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must say what vocation you want to change into, ie !changevoc sorcerer.")
	end
	return true
end


Edit: HAHAHA Dantarrix! Got me by a few seconds rofl
 
Sodeko,
this error shows up in console:
[Error - Talkaction INterface]
data/talkactions/scripts/changevoc.lua:eek:nSay
Description:
<luaDoPlayerSave> Player not found

And it still doesnt change the magic level and skills to what they should be ;( anyway, i rep you for trying... And ill also rep Dantarrix coz he definitly deserves it ... :)
 
@sodeko: yep yep lol... xDDD

your post is like a spam, cause mine, was a little error... ¬¬ xDDD <--- joke...


Emmm... i will get a last opportunity :p


Well, this will be the last time I try to get this:
Lua:
-----------------------CONFIG---START-----------------------------------------
local config = {
	removelevel = 1, -- Amount of level taken away.
	itemid = 11207, -- Item ID.
	efekt = 2, -- Effect shown.
	skilafter = 10, -- What skill will the player have after change.
	minlevel = 90, -- What will be min level required? 
	magafter = 5, -- What magic level will he recive after change? 
	kickTime = 5, -- seconds to kick player.
}
-----------------------CONFIG---END-------------------------------------------
 
function onSay(cid, words, param)
	local param, oldVoc = param:lower(), 0
	local voc = {
	['sorcerer'] = {hp = 5, mana = 30, cap = 10, voc = 1},
	['druid'] = {hp = 5, mana = 30, cap = 10, voc = 2},
	['paladin'] = {hp = 10, mana = 15, cap = 20, voc = 3},
	['knight'] = {hp = 15, mana = 5, cap = 25, voc = 4},
	}
 
	if(getPlayerVocation(cid) > 4)then
		oldVoc = getPlayerVocation(cid)-4
	else
		oldVoc = getPlayerVocation(cid)
	end		
 
	if(voc[param])then
		if getPlayerLevel(cid) >= config.minlevel then
			if(getPlayerItemCount(cid, config.itemid) > 0)then
				if(oldVoc ~= voc[param].voc)then
					doPlayerAddLevel(cid, -(config.removelevel)) --Set new level
					doPlayerSetVocation(cid, voc[param].voc) --Change vocation
					setCreatureMaxHealth(cid, (185+((getPlayerLevel(cid)-8)*voc[param].hp))) --Set new hp
					setCreatureMaxMana(cid, (35+((getPlayerLevel(cid)-8)*voc[param].mana))) --Set new mana
					doPlayerSetMaxCapacity(cid, (470+((getPlayerLevel(cid)-8)*voc[param].cap))) --Set new cap
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your vocation has been changed to ".. param ..".")
					doSendMagicEffect(getCreaturePosition(cid), 2)
					doPlayerRemoveItem(cid, config.itemid, 1)
					doSendMagicEffect(getCreaturePosition(cid), config.efekt)
					doCreatureAddMana(cid, -((getCreatureMana(cid))-(getCreatureMaxMana(cid))))
					doCreatureAddHealth(cid, -((getCreatureHealth(cid))-(getCreatureMaxHealth(cid))))
					doRemoveCreature(cid)
					local queries = {}
					local id = getPlayerGUID(cid)
					for i = 0,6 do
						table.insert(queries, "update player_skills set value = " .. config.skilafter .. ", count = 0 where skillid = " .. i .. " and player_id = " .. id .. ";")
						table.insert(queries, "update players set maglevel = ".. config.magafter .. ", promotion = 0;")
						addEvent(reset, config.kickTime, getCreatureName(cid), queries)
					end	
				else
					 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You already are a ".. param ..".")
				end
			else
				 doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You don't have a ".. getItemNameById(config.itemid) ..".")
			end
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need to be at least level ".. config.minlevel .." to use this command.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must say what vocation you want to change into, ie !changevoc sorcerer.")
	end
	return true
end

function reset(p, queries)
	if getPlayerByName(p) ~= nil then
		doRemoveCreature(getCreatureByName(p))
		db.executeQuery("update players set online = 0 where id = " .. getPlayerGUIDByName(p) .. ";")
	end
	for i = 1, table.maxn(queries) do
		if not db.executeQuery(queries[i]) then
			print("[RESET] Unable to execute query: " .. queries[i])
		end
	end
	return true
end
 
Last edited:
Back
Top