• 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 Reward Player on advanced skills! v.2

Elexonic

Well-Known Member
Joined
Jun 18, 2008
Messages
1,920
Reaction score
59
I bring this script to that point when players advance their skills .. , If you find a bug, or any improvement will only say it and added..

I think you can put even more understandable .. but I think it has to work well.

Code:
local config = {    points = 5,
    skillStor = 56364,
    level = 100,
    skills = {
        [SKILL__MAGLEVEL] = {level = 95, vocs = {1, 2}},
        [SKILL_FIST] = {level = 110, vocs = {1, 4}},
        [SKILL_SWORD] = {level = 110, vocs = {4}},
        [SKILL_CLUB] = {level = 110, vocs = {4}},
        [SKILL_AXE] = {level = 110, vocs = {4}},
        [SKILL_SHIELD] = {level = 110, vocs = {4}},
        [SKILL_DISTANCE] = {level = 125, vocs = {3}}
    }
}
 
function onAdvance(cid, skill, oldlevel, newlevel)
    if(getPlayerStorageValue(cid, config.skillStor) ~= 1 and getPlayerLevel(cid) >= config.level) then --Check storage and level
        if(config.skills[skill] ~= nil) then
            if(table.containsNum(getPlayerVocation(cid), config.skills[skill].vocs)) then --Check if the vocation used for this skill is an acceptable one
                if(newlevel >= config.skills[skill].level) then --Check if the player has the required skill
                    db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. config.points .. " where id=" .. getPlayerAccountId(cid))
                    doBroadcastMessage("Congratulations " .. getCreatureName(cid) .. " advanced on skill and received 5 Premium Points!", MESSAGE_STATUS_CONSOLE_RED)
                    setPlayerStorageValue(cid, config.skillStor, 1)
                end
            end
        end
    end
    return TRUE
end

Code edited by Scarlet Ayleid
 
Last edited:
does this work? I see you using a isSorcerer(and variants) variable that isn't declared, I suppose its the function isSorcerer(cid), but without parameters it wont work and always be null
also, its pretty confusing :/

here's a more simplified and organized version :)
Lua:
local config = {
    points = 5,
    skillStor = 56364,
    level = 100,
    skills = {
        SKILL__MAGLEVEL = {level = 95, vocs = {1, 2}},
        SKILL_FIST = {level = 110, vocs = {4}},
        SKILL_SWORD = {level = 110, vocs = {4}},
        SKILL_CLUB = {level = 110, vocs = {4}},
        SKILL_AXE = {level = 110, vocs = {4}},
        SKILL_SHIELD = {level = 110, vocs = {4}},
        SKILL_DISTANCE = {level = 125, vocs = {3}}
    }
}
 
 
function onAdvance(cid, skill, oldlevel, newlevel)
    if(getPlayerStorageValue(cid, config.skillStor) ~= 1 and newlevel >= config.level) then --Check storage and level
        if(config.skills[skill] ~= nil) then --In case its level or fishing
            if(table.containsNum(getPlayerVocation(cid), config.skills[skill].vocs)) then --Check if the vocation used for this skill is an acceptable one
                if(getPlayerSkillLevel(cid, skill, false) >= config.skills[skill].level) then --Check if the player has the required skill
                    db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + " .. config.points .. " where id=" .. getPlayerAccountId(cid))
                    doBroadcastMessage("Congratulations " .. getCreatureName(cid) .. " advanced on skill and received 5 Premium Points!", MESSAGE_STATUS_CONSOLE_RED)
                    setPlayerStorageValue(cid, config.skillStor, 1)
                end
            end
        end
    end
    return TRUE
end
I initially had it all in just one if with ands, but I splitted them for easier readability
 
Last edited:
does this work? I see you using a isSorcerer(and variants) variable that isn't declared, I suppose its the function isSorcerer(cid), but without parameters it wont work and always be null
also, its pretty confusing :/

here's a more simplified version :)
Lua:
local config = {
    points = 5
    skillStor = 56364
    level = 100
    sword1 = 110
    distance1 = 125
    magic1 = 95
    skills = {
        SKILL__MAGLEVEL = {level = 95, vocs = {1, 2}},
        SKILL_SWORD = {level = 110, vocs = {4}},
        SKILL_CLUB = {level = 110, vocs = {4}}, 
        SKILL_AXE = {level = 110, vocs = {4}},
        SKILL_SHIELD = {level = 110, vocs = {4}},
        SKILL_DISTANCE = {level = 125, vocs = {3}},
    }
}


function onAdvance(cid, skill, oldlevel, newlevel) 
    if(getPlayerStorageValue(cid, config.skillStor) ~= 1 and newlevel >= config.level) then
        if(table.contains(skill, config.skills)) then
            if(table.contains(getPlayerVocation(cid), config.skills[skill].vocs)) then
                if(getPlayerSkillLevel(cid, skill, false) >= config.skills[skill].level) then
                    db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid))
                    doBroadcastMessage("Congratulations " .. getCreatureName(cid) .. " advanced on skill and received 5 Premium Points !", MESSAGE_STATUS_CONSOLE_RED)
                    setPlayerStorageValue(cid, config.skillStor, 1)
                end
            end
        end
    end
    return TRUE
end

Such a nice little girl, she always makes me so proud!! :3
 
Bro you dont need a error if something tells you its doesnt work :S
 
I see, not if that line could confuse and grab the "local level"?
 
there's no confusion
config.level is level requirement while config.skills[skill].level is the skill level requirement for that specific skill
 
Have error in when you advanced in magic but no in level.. example.. magic level 120 .. and level 70 ... get error..
Lua:
[Error - CreatureScript Interface] 
[11/11/2012 15:9:46] data/creaturescripts/scripts/rewardskill.lua:onAdvance
[11/11/2012 15:9:46] Description: 
[11/11/2012 15:9:46] data/lib/012-table.lua:41: attempt to index local 'txt' (a number value)
[11/11/2012 15:9:46] stack traceback:
[11/11/2012 15:9:46] 	data/lib/012-table.lua:41: in function 'contains'
[11/11/2012 15:9:46] 	data/creaturescripts/scripts/rewardskill.lua:19: in function <data/creaturescripts/scripts/rewardskill.lua:17>

Edit- this error occurs whenever they level, skill.. onadvanced..

012 table in libs..
Lua:
table.contains = function (txt, str)
	for i, v in pairs(str) do
		if(txt:find(v) and not txt:find('(%w+)' .. v) and not txt:find(v .. '(%w+)')) then
			return true
		end
	end

	return false
end
table.isStrIn = table.contains
 
Last edited:
copy this function to your tables.lua file
Lua:
function table.containsNum(num, table)
    for i, v in pairs(table) do
        if(v == num) then
            return true
        end
    end
    return false
end

then change the table.contains in the script for table.containsNum(or just copy the script again, I edited it in my post)
should work, but give me feedback :)

also, PM or VM me next time, don't 'like' the post to get attention :p
 
Thread Update !
New script v.2 for Scarlet Ayleid
Thanks you for fix!
 
Back
Top