• 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 [0.4] Item who buff skills

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
I have a custom item on my server (ID 5152) I would like to create a script for it that gives the following benefit (for 30 minutes) varying by vocation, for example:

ED/MS: ML +5
Knight: all skills +30
Paladin: distance +15 and ml +3

After the 30 minute period has passed, the skills will return to normal.
 
Solution
Lua:
--<action itemid="XXXX" event="script" value="script.lua"/>
local config = {
    level = false,
    remove = true,
    time = 30, -- Time is in minutes
    message = {MESSAGE_EVENT_ADVANCE, "You feel the power growing."},
    conditions = {}
}

-- Sorcerer
config.conditions[1] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[1], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[1], CONDITION_PARAM_STAT_MAGICLEVEL, 5)
setConditionParam(config.conditions[1], CONDITION_PARAM_BUFF, true)
-- Druid
config.conditions[2] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[2], CONDITION_PARAM_TICKS, config.time * 1000 * 60)...
Take a look and do a little studying on how skill rings work in your own files. I bet you can figure it out

I thought about doing this, but I had two problems with the script logic: 1) filter by vocation, as each vocation will have a different boost 2) the item will be used and gone, it will not be like an enchanted ring
 
@potinho What version are you using?
For the vocation problem, if you are using tfs 0.4, you can try something like this:

Lua:
if isInArray({4,8}, getPlayerVocation(cid)) then -- Knights

Or

Lua:
if isDruid(cid) or isSorcerer(cid) then
 
Lua:
--<action itemid="XXXX" event="script" value="script.lua"/>
local config = {
    level = false,
    remove = true,
    time = 30, -- Time is in minutes
    message = {MESSAGE_EVENT_ADVANCE, "You feel the power growing."},
    conditions = {}
}

-- Sorcerer
config.conditions[1] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[1], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[1], CONDITION_PARAM_STAT_MAGICLEVEL, 5)
setConditionParam(config.conditions[1], CONDITION_PARAM_BUFF, true)
-- Druid
config.conditions[2] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[2], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[2], CONDITION_PARAM_STAT_MAGICLEVEL, 5)
setConditionParam(config.conditions[2], CONDITION_PARAM_BUFF, true)
-- Paladin
config.conditions[3] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[3], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[3], CONDITION_PARAM_SKILL_DISTANCE, 15)
setConditionParam(config.conditions[3], CONDITION_PARAM_STAT_MAGICLEVEL, 3)
setConditionParam(config.conditions[3], CONDITION_PARAM_BUFF, true)
-- Knight
config.conditions[4] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[4], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[4], CONDITION_PARAM_SKILL_CLUB, 30)
setConditionParam(config.conditions[4], CONDITION_PARAM_SKILL_SWORD, 30)
setConditionParam(config.conditions[4], CONDITION_PARAM_SKILL_AXE, 30)
setConditionParam(config.conditions[4], CONDITION_PARAM_BUFF, true)

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if config.level then
        if getPlayerLevel(cid) < config.level then
            return doPlayerSendCancel(cid, "You need to be level " .. config.level .. " or higher.")
        end
    end
    if hasCreatureCondition(cid, CONDITION_ATTRIBUTES) then
        return doPlayerSendCancel(cid, "You cannot use this item more than once.")
    end
    if config.remove then
        doRemoveItem(item.uid, 1)
    end
    if config.message then
        doPlayerSendTextMessage(cid, config.message[1], config.message[2])
    end
    local voc = (getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5) and 1 or (getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 6) and 2 or (getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7) and 3 or (getPlayerVocation(cid) == 4 or getPlayerVocation(cid) == 8) and 4
    doAddCondition(cid, config.conditions[voc])
    return true
end
 
Last edited:
Solution
Lua:
--<action itemid="XXXX" event="script" value="script.lua"/>
local config = {
    level = false,
    remove = true,
    time = 30, -- Time is in minutes
    conditions = {}
}

-- Sorcerer
config.conditions[1] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[1], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[1], CONDITION_PARAM_STAT_MAGICLEVEL, 5)
setConditionParam(config.conditions[1], CONDITION_PARAM_BUFF, true)
-- Druid
config.conditions[2] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[2], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[2], CONDITION_PARAM_STAT_MAGICLEVEL, 5)
setConditionParam(config.conditions[2], CONDITION_PARAM_BUFF, true)
-- Paladin
config.conditions[3] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[3], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[3], CONDITION_PARAM_SKILL_DISTANCE, 15)
setConditionParam(config.conditions[3], CONDITION_PARAM_STAT_MAGICLEVEL, 3)
setConditionParam(config.conditions[3], CONDITION_PARAM_BUFF, true)
-- Knight
config.conditions[4] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(config.conditions[4], CONDITION_PARAM_TICKS, config.time * 1000 * 60)
setConditionParam(config.conditions[4], CONDITION_PARAM_SKILL_CLUB, 30)
setConditionParam(config.conditions[4], CONDITION_PARAM_SKILL_SWORD, 30)
setConditionParam(config.conditions[4], CONDITION_PARAM_SKILL_AXE, 30)
setConditionParam(config.conditions[4], CONDITION_PARAM_BUFF, true)

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if config.level then
        if getPlayerLevel(cid) < config.level then
            return doPlayerSendCancel(cid, "You need to be level " .. config.level .. " or higher.")
        end
    end
    if hasCreatureCondition(cid, CONDITION_ATTRIBUTES) then
        return doPlayerSendCancel(cid, "You cannot use this item more than once.")
    end
    if config.remove then
        doRemoveItem(item.uid, 1)
    end
    local voc = (getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 5) and 1 or (getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 6) and 2 or (getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 7) and 3 or (getPlayerVocation(cid) == 4 or getPlayerVocation(cid) == 8) and 4
    doAddCondition(cid, config.conditions[voc])
    return true
end
Works perfectly Alberto, thanks. Just one more thing, where i put a message when players uses? Like on use "You feel the power growing"
 
Back
Top