• 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 Advanced OnAdvance: The Best OnAdvance

hodleo

Formerly cbrm -Crypto enthusiast, Retired scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,598
Solutions
3
Reaction score
955
Location
Caribbean Sea
[|> Author: Cybermaster

If you plan to use this script, remove the other OnAdvance scripts.

What is it about?
[> Saves character's data into db whenever the player levels up a skill.
[> Shows an amazing, 1.4 secs animated effect when leveling up, like absorbing power.
[> Effects vary depending of the skill.
[> Recovers player's health and mana when the player levels up the Lvl skill.
[> The idea of this script was to merge all necessary onAdvance scripts into one.

1. Add to data/creaturescripts/creaturescripts.xml
Lua:
<event type="advance" name="advance" event="script" value="advance.lua"/>

2. Register the event data/creaturescripts/scripts/login.lua
Lua:
registerCreatureEvent(cid, 'advance')

3. Add data/creaturescripts/scripts/advanced.lua
Lua:
--[[ / / / / / / / / / / / / / / / / / / / / / /
               Advanced OnAdvance
        The Best OnAdvance Creaturescript
	    Scripted by Cybermaster
	     @The Forgotten Server
	 	  OTLand.net
/ / / / / / / / / / / / / / / / / / / / / / ]]--


local config = 
	{ 
		--message, distance shoot effect
		[0] = {'+Fist', 38},
		[1] = {'+Mace', 26},
		[2] = {'+Swrd', 24},
		[3] = {'+Axe', 25},
		[4] = {'+Dist', 2},
		[5] = {'+Def', 11},
		[6] = {'+Fish', 12},
		[7] = {'+ML', 35},
		[8] = {'+LvL', 37} 
	}

function onAdvance(cid, skill, oldlevel, newlevel)
    if skill == SKILL__LEVEL then
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
        doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
    end

	local p = getThingPos(cid)
	local positions = 
	{	--do not touch
        [1] = {
			{x=p.x+1,y=p.y,z=p.z}, 100, 900
		},
        [2] = {
			{x=p.x+1,y=p.y+1,z=p.z}, 200, 980
		},
        [3] = {
			{x=p.x,y=p.y+1,z=p.z}, 300, 1060
		},
        [4] = {
			{x=p.x-1,y=p.y+1,z=p.z}, 400, 1140
		},
        [5] = {
			{x=p.x-1,y=p.y,z=p.z}, 500, 1220
		},
        [6] = {
			{x=p.x-1,y=p.y-1,z=p.z}, 600, 1300
		},
        [7] = {
			{x=p.x,y=p.y-1,z=p.z}, 700, 1380
		},
        [8] = {
			{x=p.x+1,y=p.y-1,z=p.z}, 800, 1460
		} 
	}
       
    for i = 1, 8 do
        addEvent(doSendDistanceShoot, positions[i][2], positions[i][1], p, config[skill][2])
        addEvent(doSendDistanceShoot, positions[i][3], positions[i][1], p, config[skill][2])
    end
	
    addEvent(doSendMagicEffect, 900, p, 49)
    doSendAnimatedText(p, config[skill][1]..'['..newlevel..']', math.random(255))
    doPlayerSave(cid, true)    
    return true
end

Fancy Edition:
Lua:
--[[ / / / / / / / / / / / / / / / / / / / / / /
		Advanced OnAdvance Fancy Edition
	   The Best OnAdvance Creaturescript
			Scripted by Cybermaster
/ / / / / / / / / / / / / / / / / / / / / / ]]--
 
local area, data = 
{
	{0, 1, 1, 1, 0},
	{1, 1, 1, 1, 1},
	{1, 1, 1, 1, 1},
	{1, 1, 1, 1, 1},
	{0, 1, 1, 1, 0}
},
{
	[SKILL_FIST] = 'FISTUP!',
	[SKILL_CLUB] = 'CLUBUP!',
	[SKILL_SWORD] = 'SWORDUP!',
	[SKILL_AXE] = 'AXEUP!',
	[SKILL_DISTANCE] = 'DISTANCEUP!',
	[SKILL_SHIELD] = 'SHIELDUP!',
	[SKILL_FISHING] = 'FISHINGUP!',
	[SKILL__MAGLEVEL] = 'MAGICUP!',
	[SKILL__LEVEL] = 'LEVELUP!'
}
  
function onAdvance(cid, skill, oldLevel, newLevel)
    doPlayerSave(cid)
	local center, data = {}, data[skill] --function doSendMagicEffectInArea of Mock
    center.y = math.floor(table.getn(area)/2)+1
    for y = 1, table.getn(area) do
        for x = 1, table.getn(area[y]) do
            if area[y][x] > 0 then
                center.x = math.floor(table.getn(area[y])/2)+1
                doSendMagicEffect({x=getThingPos(cid).x+x-center.x,y=getThingPos(cid).y+y-center.y,z= getThingPos(cid).z},math.random(28,30),cid)
            end
        end
    end	
    for i = 1, #data do
		addEvent(doSendAnimatedText, i*150, getThingPos(cid), data:sub(i,i), i%2 == 0 and TEXTCOLOR_RED or TEXTCOLOR_ORANGE)
    end
    return true
end
 
Last edited:
Improved version.
Lua:
local CONFIG = {
	[0] = {"+fist", 38},
	[1] = {"+club", 26},
	[2] = {"+sword", 24},
	[3] = {"+axe", 25},
	[4] = {"+distance", 2},
	[5] = {"+defense", 11},
	[6] = {"+fishing", 12},
	[7] = {"+magic", 35},
	[8] = {"+level", 37}
}
local USE_EFFECTS = true
function onAdvance(cid, skill, oldlevel, newlevel)
	if skill == SKILL__LEVEL then
		doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
		doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))
	end
	if not CONFIG[skill] or USE_EFFECTS == false then
		return true
	end
	local p = getPlayerPosition(cid)
	local POSITIONS = { 
		[1] = {pos={x=p.x+1,y=p.y,z=p.z}, delay = 100, delay2 = 900},
		[2] = {pos={x=p.x+1,y=p.y+1,z=p.z}, delay = 200, delay2 = 980},
		[3] = {pos={x=p.x,y=p.y+1,z=p.z}, delay = 300, delay2 = 1060},
		[4] = {pos={x=p.x-1,y=p.y+1,z=p.z}, delay = 400, delay2 = 1140},
		[5] = {pos={x=p.x-1,y=p.y,z=p.z}, delay = 500, delay2 = 1220},
		[6] = {pos={x=p.x-1,y=p.y-1,z=p.z}, delay = 600, delay2 = 1300},
		[7] = {pos={x=p.x,y=p.y-1,z=p.z}, delay = 700, delay2 = 1380},
		[8] = {pos={x=p.x+1,y=p.y-1,z=p.z}, delay = 800, delay2 = 1460}
	} 
	for i = 1, #POSITIONS do
		addEvent(doSendDistanceShoot, POSITIONS[i].delay, POSITIONS[i].pos, p, CONFIG[skill][2])
		addEvent(doSendDistanceShoot, POSITIONS[i].delay2, POSITIONS[i].pos, p, CONFIG[skill][2])
	end 
	addEvent(doSendMagicEffect, 900, p, 49)
	doSendAnimatedText(p, CONFIG[skill][1] .. "["..newlevel.."]", math.random(255))
	doPlayerSave(cid, true)	
	return true
end

But there's a problem. Animated text handles only 9 letters (so far I know) :p
 
@up

if not CONFIG[skill] or USE_EFFECTS == false then
return true
end

the 'not CONFIG[skill]' is unnecessary since all onAdvance events happen when a skill is leveled up
 
If (due to misconfiguration or whatever) table CONFIG[skill] is nil, script will end and it won't show any error.
 
maybe use doCreatureSay with orange text ;d(yeah, no random color, but handles long texts)
 
Good work.

Code:
doSendAnimatedText(p, CONFIG[skill][1] .. "["..newlevel.."]", math.random(CONST_ME_LAST))
 
This code:

Lua:
local config = {
	savePlayersOnAdvance = true
}

function onAdvance(cid, skill, oldLevel, newLevel)
	if(config.savePlayersOnAdvance) then
		doPlayerSave(cid, true)
	end

	return true
end

Saves the player after each level or skill gained or losed?
 
onadvance = only when a skill is leveled up
 
put an exhaust time on it, such as 5 minutes to prevent lag/double saves etc.. for higher rate servers?

health/mana isnt restored after skill up.
 
Last edited:
how do i turn off the message to tell people their new skill i removed
Code:
  .. "["..newlevel.."]", math.random(255)

and it just gives me an error message in the console but doesnt effect anything, any help?
 
Lua:
doSendAnimatedText(p, ""..config[skill].msg.."["..newlevel.."]", math.random(1,255))
 
yeah i dont want it to say eg: dist 12 dist 13
as they advance
just see the normal you advanced in distance fighting. and the spell effect
 
<.< but I just posted the line you need to delete
 
Back
Top