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

CreatureEvent [HOT] LevelUp Reward [VocCheck,LevelCheck,Effects,Save,Heal] --All in one!

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,286
Location
Sweden?
Hello,

Ive searched around the forum found similar scripts, but i didn't like them much so i made a new one.

I made this because traning how to make tables, Thanks to Limos for his link!

First go to creaturescripts/creaturescripts.xml and copy the line below:
Lua:
<event type="advance" name="LevelUp" event="script" value="levelup.lua"/>

Then go to creaturescripts/scripts/login.lua and paste the line below:
Lua:
registerCreatureEvent(cid, "LevelUp")

Now at creaturescripts/scripts and create new lua and name it {levelup.lua} and paste the code below:
Lua:
--//Credits: Printer//--
local config = {
	savePlayer = true, --Save Player When The Gain Level!
	healPlayerOnLevel = true, --Heal Players Hp And Mana On Level!
    	effectOnLevel = true, --Fireworks Effect On Level!
    	getServerVersionUnder860 = true, --If the server is 860 and lower than that, leave it true! If its over 860, use false!
    	levelText = "LEVEL UP!", --Gain Level Text!
	Sorcerer = { 
        Vocsid = {1,5}, --Vocs id for Wizards     
		[20] = {item = 2160, count = 100, storage = 3000}, --///[Level] = {item = ItemId, count = ItemCount}///--
		[40] = {item = 2152, count = 100, storage = 3001} --///[Level] = {item = ItemId, count = ItemCount}///--
	},
	Druid = {  
        Vocsid = {2,6}, --Vocs id for Mages     
		[20] = {item = 2160, count = 100, storage = 3002}, --///[Level] = {item = ItemId, count = ItemCount}///--
		[40] = {item = 2152, count = 100, storage = 3003} --///[Level] = {item = ItemId, count = ItemCount}///--
	},
	Paladin = {  
        Vocsid = {3,7}, --Vocs id for Rangers      
		[20] = {item = 2160, count = 100, storage = 3004}, --///[Level] = {item = ItemId, count = ItemCount}///--
		[40] = {item = 2152, count = 100, storage = 3005} --///[Level] = {item = ItemId, count = ItemCount}///--
	},
	Knight = {  
        Vocsid = {4,8}, --Vocs id for Warriors    
		[20] = {item = 2160, count = 100, storage = 3006}, --///[Level] = {item = ItemId, count = ItemCount}///--
		[40] = {item = 2152, count = 100, storage = 3007} --///[Level] = {item = ItemId, count = ItemCount}///--
	},
}
 
function onAdvance(cid, skill, oldLevel, newLevel)
	if(skill == SKILL__EXPERIENCE) then
		return true
	end
        if(newLevel < oldLevel)then return true end
 
	if(skill == SKILL__LEVEL and config.healPlayerOnLevel) then
		doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
		doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
		doSendMagicEffect(getCreaturePosition(cid), math.random(28, 30))
	if config.getServerVersionUnder860 then
		doSendAnimatedText(getCreaturePosition(cid), config.levelText, math.random(1,255))
	else
        doCreatureSay(cid,config.levelText,TALKTYPE_ORANGE_1)
        end
	end
 
	if(config.savePlayer) then
		doPlayerSave(cid, true)
	end
 
	local sorc,druid,pally,knight = config.Sorcerer[getPlayerLevel(cid)],config.Druid[getPlayerLevel(cid)],config.Paladin[getPlayerLevel(cid)],config.Knight[getPlayerLevel(cid)]
	if (isInArray(config.Sorcerer.Vocsid, getPlayerVocation(cid)) or isInArray(config.Druid.Vocsid, getPlayerVocation(cid)) or isInArray(config.Paladin.Vocsid, getPlayerVocation(cid)) or isInArray(config.Knight.Vocsid, getPlayerVocation(cid))) then
	if (sorc and isInArray(config.Sorcerer.Vocsid, getPlayerVocation(cid)) and (getPlayerStorageValue(cid,config.Sorcerer.storage) == -1)) then
		doPlayerAddItem(cid,sorc.item,sorc.count)
		setPlayerStorageValue(cid, config.sorc.storage,1)
		doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have recived "..sorc.count.."x "..getItemNameById(sorc.item).."." )
	elseif (druid and isInArray(config.Druid.Vocsid, getPlayerVocation(cid)) and (getPlayerStorageValue(cid,config.Druid.storage) == -1)) then
		doPlayerAddItem(cid,druid.item,druid.count)
		setPlayerStorageValue(cid, config.druid.storage,1)
		doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have recived "..druid.count.."x "..getItemNameById(druid.item).."." )
	elseif (pally and isInArray(config.Paladin.Vocsid, getPlayerVocation(cid)) and (getPlayerStorageValue(cid,config.Paladin.storage) == -1)) then
		doPlayerAddItem(cid,pally.item,pally.count)
		setPlayerStorageValue(cid, config.pally.storage,1)
		doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have recived "..pally.count.."x "..getItemNameById(pally.item).."." )
	elseif (knight and isInArray(config.Knight.Vocsid, getPlayerVocation(cid)) and (getPlayerStorageValue(cid,config.Knight.storage) == -1)) then
		doPlayerAddItem(cid,knight.item,knight.count)
		setPlayerStorageValue(cid, config.knight.storage,1)
		doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You have recived "..knight.count.."x "..getItemNameById(knight.item).."." )
	end
	else
	    print("Your vocation id doesn't exsist: "..getPlayerVocation(cid)..".")
	end
	return true
end
 
Last edited:
Great script! For future reference, you can eliminate all of that messy "elseif" with the following:

Lua:
doPlayerAddItem(cid, isSorcerer(cid) and 2152 or isDruid(cid) and 2160 or isPaladin(cid) and 2152 or isKnight(cid) and 2160, 1)

doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have received a " .. (isSorcerer(cid) and "" .. getItemInfo(sorc.item).name .. "" or isDruid(cid) and "" .. getItemInfo(druid.item).name .. "" or isPaladin(cid) and "" .. getItemInfo(pally.item).name .. "" or isKnight(cid) and "" .. getItemInfo(knight.item).name .. "") .. "!")
There's an even better way than this, but it requires a complete makeover of the script. ;)
 
Last edited:
Omg thank you!! Teach me more :)

Ill edit tomorrow thanks J.Dre
 
Hey Printer, there's a bug:
If i up to level 20 i will recive the reward, but if i stay in lvl 20 and anyone of my skills advance, i obtain the reward again.
For example:
I recive 2 crystal coins at lvl 20.
If I stay in lvl 20 and my sword fighting advances 1 level, i will get again the 2 crystal coins, and before I up to level 21, everytime my sword fighting or any other skill advances I will win again the 2 crystal coins.
I've tried to fix this but im not able to do it. Can you fix it, please? Thanks^^
 
[Warning - BaseEvents::loadFromXml] Cannot open creaturescripts.xml file.
[20/04/2013 12:23:15] Line: 12, Info: Premature end of data in tag creaturescripts line 2
HELP ME !
 
Ive edited the script and added storage, so you recive the item once.
 
Hey im having this console error:

Code:
[29/04/2013 10:43:23] [Error - CreatureScript Interface] 
[29/04/2013 10:43:23] data/creaturescripts/scripts/levelup.lua:onAdvance
[29/04/2013 10:43:23] Description: 
[29/04/2013 10:43:23] data/creaturescripts/scripts/levelup.lua:67: attempt to index field 'pally' (a nil value)
[29/04/2013 10:43:23] stack traceback:
[29/04/2013 10:43:23] 	data/creaturescripts/scripts/levelup.lua:67: in function <data/creaturescripts/scripts/levelup.lua:34>

Here is my 34th line:
Code:
function onAdvance(cid, skill, oldLevel, newLevel)

And my 67th:
Code:
setPlayerStorageValue(cid, config.pally.storage,1)

Thanks
 
Code:
[02/05/2013 22:51:07] [Error - LuaScriptInterface::loadFile] data/creaturescripts/scripts/levelup.lua:37: '}' expected (to close '{' at line 2) near 'function'
[02/05/2013 22:51:07] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/levelup.lua)
[02/05/2013 22:51:07] data/creaturescripts/scripts/levelup.lua:37: '}' expected (to close '{' at line 2) near 'function'
???
 
Code:
[02/05/2013 22:51:07] [Error - LuaScriptInterface::loadFile] data/creaturescripts/scripts/levelup.lua:37: '}' expected (to close '{' at line 2) near 'function'
[02/05/2013 22:51:07] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/levelup.lua)
[02/05/2013 22:51:07] data/creaturescripts/scripts/levelup.lua:37: '}' expected (to close '{' at line 2) near 'function'
???

Make sure you copy the whole script!
 
Haha, now I see, everything looks OK but the "reward", it didn't give anything..
Does it work like if I set the reward at lvl 50, and the player advances from lvl 48 to lvl 52?
Asking because I didn't get any, even if I advanced to the lvl which I have put in the script.
 
Haha, now I see, everything looks OK but the "reward", it didn't give anything..
Does it work like if I set the reward at lvl 50, and the player advances from lvl 48 to lvl 52?
Asking because I didn't get any, even if I advanced to the lvl which I have put in the script.

Well, that is the problem with tables. Cant figure out how to make, if player advance over the configured level :S
 
Back
Top