• 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:
I removed the picture with error. Everything works fine. Please look at the EDITS in this comment :p


EDIT SORRY MY MISTAKE... I didnt put 1 file in the correct folder.. :p no error shows atm... lemme test it now

EDIT 2

JOSEJUNIOR
I love you xD It works perfectly... it doesn't take away any lvl tho but it resets magic level to 1 and all skills to 10. :) =D i guess there is a possibility of taking some lvls away every time u change voc

ANOTHER EDIT:
could someone make exhaustement for this script? I mean like, people can use bot to say /acv ;ss and also tell me how to set so that some levels will be taken away when changing from vocation. Example. Changing from Knight to Druid and it resets ur skills, magic lvl and takes away 20 levels... But it doesnt RESET ur level to 20 but it TAKES AWAY 20 levels.

I just realized that this script doesn't take any item when using... It should take the item for changing voc and i just realized that right now.... I'd appreciate if someone could remake this script so that it takes a certain item and also takes away a certain amount of levels when changing voc.

thanks ;*
 
Last edited:
I love you xD It works perfectly... it doesn't take away any lvl tho but it resets magic level to 1 and all skills to 10. =D i guess there is a possibility of taking some lvls away every time u change voc
If you can prove, the script function from the same level, and it changes the mana and health of player, according to vocation and level (it has a calculation), so it's prepared to keep the same level of player... xD


I cant see why its taking an amount of levels...
 
I dont know if u understood me xD

I want the script to take away some levels BECAUSE it doesn't do it now... :S So

if 150 ms changes to ed... He will still have 150 lvl... And i would like the script to take away 30 levels every time someone changes voc...

So, if 150 ms changes to ed... He will have 120 lvl ed after changing.

and also, i would like this script to be for a certain item... So like, you need for example. a santa doll to change the voc... :S because now every1 can change their vocations... BUT i would also like this script to be from certain level... Hmmm, minimum level 100...

xDD
 
in lib/function.lua add this
Lua:
function doPlayerRemoveLevel(cid, amount, round)
	local experience, level, amount = 0, getPlayerLevel(cid), amount or 1
	if(amount > 0) then
		experience = getExperienceForLevel(level + amount) - (round and getPlayerExperience(cid) or getExperienceForLevel(level))
	else
		experience = -((round and getPlayerExperience(cid) or getExperienceForLevel(level)) - getExperienceForLevel(level + amount))
	end
 
	return doPlayerAddExperience(cid, -experience) and setPlayerhealth(cid)
end
and add this to your script
Lua:
doPlayerRemoveLevel(cid, amount)
 
@Up,

the line
Code:
doPlayerRemoveLevel(cid,amount)

into which script do you add this? Because if I take josejunior23's script, well, there are few of them... So this line goes into which one?

and also I would like the script that josejunior23 made to take a certain item for changing vocation... So like, santa doll is needed... :S Because now it is free... ;/ And everyone can change their vocation ;(
 
ye, i pasted that line into the ACV_lib.lua and like some huge error came up and my console got bugged and it just closed itself... ;D funny ;P

well, but i think that there is a matter of WHERE it should be put... I mean like, you can't just put it at the end of the script... ;P it has to be in the right place ;D
 
nah, nothing happens...

and i dont even see where it says how many levels it should take away in that script... Ehhh

I prefered my last script but it doesnt reset skillls... omg ;/

So if no1 can fix this script then thread can be closed... because I dont want to wait ages for it...

Thanks all for trying. :) I added reputation to those that tried to help :)
 
In ACV.lua after the function changePlayerVocation(...)...

But it will have an error.... See(numbers are only examples):

1. I'm sorcerer level 100, with 3k mana, 800 hp and 2.2k cap...
2. Use this...
a. Change vocation to knight, so i have level 100 knight, with 800 mana, 3k hp and 3.2k cap....
b. Change level, to level 10...... So i have level 10 knight with 800 MANA, 3K HP AND 3.2K CAP!!!

3. A fucking bug, dont you think so? I can be level 10 knight with like 10k hp.... :/
 
Back
Top