• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua add function,% experience bonus

Guerra

Member
Joined
May 1, 2018
Messages
69
Reaction score
9
Location
Natal/RN - Brasil
Hello Guys,

I would like to ask for help to modify a code that I use on my server. It is a movement script that adds bonuses to items when equipped. I would like to add the percentage bonus experience parameter to this script. my version of TFS is 1.3!

LUA:
--// Do not touch
local conditionSlots = {
    [CONST_SLOT_HEAD]     = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_HEAD),     id = CONDITIONID_HEAD},
    [CONST_SLOT_NECKLACE] = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_NECKLACE), id = CONDITIONID_NECKLACE},
    [CONST_SLOT_BACKPACK] = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_BACKPACK), id = CONDITIONID_BACKPACK},
    [CONST_SLOT_ARMOR]    = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_ARMOR),    id = CONDITIONID_ARMOR},
    [CONST_SLOT_RIGHT]    = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_RIGHT),    id = CONDITIONID_RIGHT},
    [CONST_SLOT_LEFT]     = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_LEFT),     id = CONDITIONID_LEFT},
    [CONST_SLOT_LEGS]     = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_LEGS),     id = CONDITIONID_LEGS},
    [CONST_SLOT_FEET]     = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_FEET),     id = CONDITIONID_FEET},
    [CONST_SLOT_RING]     = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_RING),     id = CONDITIONID_RING},
    [CONST_SLOT_AMMO]     = {condition = Condition(CONDITION_ATTRIBUTES, CONDITIONID_AMMO),     id = CONDITIONID_AMMO}
}

-- Set all conditions to infinite ticks
for i = 1, #conditionSlots do
    conditionSlots[i].condition:setParameter(CONDITION_PARAM_TICKS, -1)
end

local params = {
    CONDITION_PARAM_SKILL_MELEE,
    CONDITION_PARAM_SKILL_FIST,
    CONDITION_PARAM_SKILL_CLUB,
    CONDITION_PARAM_SKILL_SWORD,
    CONDITION_PARAM_SKILL_AXE,
    CONDITION_PARAM_SKILL_DISTANCE,
    CONDITION_PARAM_SKILL_SHIELD,
    CONDITION_PARAM_SKILL_FISHING,
    CONDITION_PARAM_STAT_MAXHITPOINTS,
    CONDITION_PARAM_STAT_MAXMANAPOINTS,
    CONDITION_PARAM_STAT_SOULPOINTS,
    CONDITION_PARAM_STAT_MAGICPOINTS,
    CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT,
    CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT,
    CONDITION_PARAM_STAT_SOULPOINTSPERCENT,
    CONDITION_PARAM_STAT_MAGICPOINTSPERCENT,
    CONDITION_PARAM_SKILL_MELEEPERCENT,
    CONDITION_PARAM_SKILL_FISTPERCENT,
    CONDITION_PARAM_SKILL_CLUBPERCENT,
    CONDITION_PARAM_SKILL_SWORDPERCENT,
    CONDITION_PARAM_SKILL_AXEPERCENT,
    CONDITION_PARAM_SKILL_DISTANCEPERCENT,
    CONDITION_PARAM_SKILL_SHIELDPERCENT,
    CONDITION_PARAM_SKILL_FISHINGPERCENT
}
--\\

-- Item config
local items = {
    -- ItemID
    [31371] = {
        -- Vocation ID 4
        [1] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, value = 102}
        },
       
        [2] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, value = 102}
        },
       
        [3] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, value = 102}
        },
       
        [4] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_MELEEPERCENT, value = 102}
        },
       
        [5] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_MELEEPERCENT, value = 102}
        },
       
        [6] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_MELEEPERCENT, value = 102},
            {param = CONDITION_PARAM_SKILL_SHIELDPERCENT, value = 102}
        },
       
        [7] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_MELEEPERCENT, value = 102}
        },
       
        [8] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_MELEEPERCENT, value = 102}
        },
       
        [9] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_DISTANCEPERCENT, value = 102}
        },
       
        [10] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_DISTANCEPERCENT, value = 102}
        },
       
        [11] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_SKILL_DISTANCEPERCENT, value = 102}
        },
       
        [12] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, value = 102}
        },
       
        [13] = {
            {param = CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, value = 103},
            {param = CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, value = 102}
        },
       
    }
}

function onEquip(player, item, slot)
    local statItem = items[item.itemid]
    local vocStats = statItem and statItem[player:getVocation():getId()]

    if not vocStats then
        return true
    end

    local condition = conditionSlots[slot].condition

    -- Remove previous parameters so all params don't get added
    for p = 1, #params do
        condition:setParameter(params[p], 0)
    end

    -- Set new parameters
    for i = 1, #vocStats do
        condition:setParameter(vocStats[i].param, vocStats[i].value)
    end

    player:addCondition(condition)
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)

    return true
end

function onDeEquip(player, item, slot)
    local conditionId = conditionSlots[slot].id
    if player:getCondition(CONDITION_ATTRIBUTES, conditionId) then
        player:removeCondition(CONDITION_ATTRIBUTES, conditionId)
    end
    return true
end

for this type of modification is it necessary to change the Source of my server? if not necessary, please help me in this situation ...
 
why not just use the Player:eek:nGainExperience function?

for example add something like (pseudo code):
LUA:
    if player:getSlotItem(CONST_SLOT_RING) == 31371 then
        exp = exp * 1.5 -- 50% bonus exp if player ring slot is item id 31371
    end
just create a lua file and paste that code? or do i have to add this to my script?
Post automatically merged:

I have a code that I used on my old tfs 0.4 server, would I have to adapt it to 1.3?

LUA:
function onEquip(cid, item, slot)
local rate = {}
if getPlayerLevel(cid) <= 1 then 
rate = 1.1
elseif getPlayerLevel(cid) > 200 and getPlayerLevel(cid) <= 280 then 
rate = 1.3
elseif getPlayerLevel(cid) > 300 then
rate = 1.5
end
doPlayerSendCancel(cid, "Your exp rate + "..((rate - 1)*100).." %") 
doPlayerSetExperienceRate(cid, rate)
return TRUE
end
function onDeEquip(cid, item, slot)
doPlayerSendTextMessage(cid, 4, "Sua experiência está de volta ao normal")   
doPlayerSetExperienceRate(cid, 1.0)
return TRUE
end

I tried to add this way to my 1.3 server and gave the following error:
error.PNG
 
Last edited:
Back
Top