• 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 Vocational Item Bonus's -> using RevScripts

nefinoo

Carnage.flv
Joined
Sep 11, 2010
Messages
549
Solutions
1
Reaction score
58
Location
Lo Mochis, Sinaloa
@Xikini

Lua:
local config  = {
    [2496] = { -- itemid
        slot = "head", -- ("head", "necklace", "backpack", "armor", "shield", "weapon", "legs", "feet", "ring", "ammo")
        {
            [{1, 5}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{2, 6}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{3, 7}] = {["statMain"] = {{"distance", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{4, 8}] = {["statMain"] = {{"axe", 5},{"sword", 5},{"club", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        }
    },
    [8821] = {
        slot = "armor",
        {
            [{1, 5}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{2, 6}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{3, 7}] = {["statMain"] = {{"distance", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{4, 8}] = {["statMain"] = {{"axe", 5},{"sword", 5},{"club", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        }
    },
    [8923] = {
        slot = "legs",
       {
            [{1, 5}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{2, 6}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{3, 7}] = {["statMain"] = {{"distance", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
           
            [{4, 8}] = {["statMain"] = {{"axe", 5},{"sword", 5},{"club", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leechamount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        }
    }
}

local function convertSlotTextToNumber(slot)
    local text = nil
    if slot == "head" then
        slot = 1
    elseif slot == "necklace" then
        slot = 2
    elseif slot == "backpack" then
        slot = 3
    elseif slot == "armor" then
        slot = 4
    elseif slot == "shield" then
        slot = 5
    elseif slot == "weapon" then
        slot = 6
    elseif slot == "legs" then
        slot = 7
    elseif slot == "feet" then
        slot = 8
    elseif slot == "ring" then
        slot = 9
    elseif slot == "ammo" then
        slot = 10
    end
    return slot
end

local condition_ids = {
    CONDITIONID_HEAD,
    CONDITIONID_NECKLACE,
    CONDITIONID_BACKPACK,
    CONDITIONID_ARMOR,
    CONDITIONID_RIGHT,
    CONDITIONID_LEFT,
    CONDITIONID_LEGS,
    CONDITIONID_FEET,
    CONDITIONID_RING,
    CONDITIONID_AMMO
}

local conditions = {
    ["life increase"] = {CONDITION_PARAM_STAT_MAXHITPOINTS},
    ["mana increase"] = {CONDITION_PARAM_STAT_MAXMANAPOINTS},
    ["speed"] = {CONDITION_PARAM_SPEED},
    ["magic"] = {CONDITION_PARAM_STAT_MAGICPOINTS},
    ["melee"] = {CONDITION_PARAM_SKILL_MELEE},
    ["fist"] = {CONDITION_PARAM_SKILL_FIST},
    ["club"] = {CONDITION_PARAM_SKILL_CLUB},
    ["sword"] = {CONDITION_PARAM_SKILL_SWORD},
    ["axe"] = {CONDITION_PARAM_SKILL_AXE},
    ["distance"] = {CONDITION_PARAM_SKILL_DISTANCE},
    ["shield"] = {CONDITION_PARAM_SKILL_SHIELD},
    ["fishing"] = {CONDITION_PARAM_SKILL_FISHING},
    ["critical hit chance"] = {CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE},
    ["critical hit damage"] = {CONDITION_PARAM_SPECIALSKILL_CRITICALHITAMOUNT},
    ["life leech chance"] = {CONDITION_PARAM_SPECIALSKILL_LIFELEECHCHANCE},
    ["life leech amount"] = {CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT},
    ["mana leech chance"] = {CONDITION_PARAM_SPECIALSKILL_MANALEECHCHANCE},
    ["mana leech amount"] = {CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT},
    ["life increase percent"] = {CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT},
    ["mana increase percent"] = {CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT},
    ["magic percent"] = {CONDITION_PARAM_STAT_MAGICPOINTSPERCENT},
    ["melee percent"] = {CONDITION_PARAM_SKILL_MELEEPERCENT},
    ["fist percent"] = {CONDITION_PARAM_SKILL_FISTPERCENT},
    ["club percent"] = {CONDITION_PARAM_SKILL_CLUBPERCENT},
    ["sword percent"] = {CONDITION_PARAM_SKILL_SWORDPERCENT},
    ["axe percent"] = {CONDITION_PARAM_SKILL_AXEPERCENT},
    ["distance percent"] = {CONDITION_PARAM_SKILL_DISTANCEPERCENT},
    ["shield percent"] = {CONDITION_PARAM_SKILL_SHIELDPERCENT},
    ["fishing percent"] = {CONDITION_PARAM_SKILL_FISHINGPERCENT},
    ["life regen"] = {CONDITION_PARAM_HEALTHGAIN, CONDITION_PARAM_HEALTHTICKS},
    ["mana regen"] = {CONDITION_PARAM_MANAGAIN, CONDITION_PARAM_MANATICKS},
    ["soul regen"] = {CONDITION_PARAM_SOULGAIN, CONDITION_PARAM_SOULTICKS}
}

local main_attributes = {CONDITION_ATTRIBUTES, CONDITION_HASTE, CONDITION_REGENERATION, CONDITION_SOUL}
local main_stats = {"statMain", "statSpeed", "statRegen", "statSoulRegen"}

local function giveItemBonus(playerid)
    local player = Player(playerid)
    local player_equipment = {}

    -- find all player equipment
    for i = 1, 10 do
        local slotItem = player:getSlotItem(i)
        if slotItem then
            slotItem = slotItem.itemid
            if not config[slotItem] or convertSlotTextToNumber(config[slotItem].slot) ~= i then
                slotItem = 0
            end
        else
            slotItem = 0
        end
        table.insert(player_equipment, slotItem)
    end

    -- remove all buffs from armor
    for i = 1, 10 do
        for n = 1, 4 do
            if player:getCondition(main_attributes[n], condition_ids[i]) then
                player:removeCondition(main_attributes[n], condition_ids[i])
            end
        end
    end

    -- add all buffs from equipment
    local vocation = player:getVocation():getId()
    for i = 1, 10 do
        local itemID = player_equipment[i]
        if itemID ~= 0 then
            for voc, _ in pairs(config[itemID][1]) do
                if isInArray(voc, vocation) then
                    for n = 1, 4 do
                        if config[itemID][1][voc][main_stats[n]] then
                            local condition = Condition(main_attributes[n], condition_ids[i])
                            condition:setParameter(CONDITION_PARAM_TICKS, -1)
                            local itemBonusIndex = config[itemID][1][voc][main_stats[n]]
                            for h = 1, #itemBonusIndex do
                                for p = 1, #conditions[itemBonusIndex[h][1]] do
                                    condition:setParameter(conditions[itemBonusIndex[h][1]][p], itemBonusIndex[h][2])
                                end
                            end
                            player:addCondition(condition)
                        end
                    end
                end
            end
        end
    end
    return true
end


-- HEAD -------------------------------------------------------------------------------
local onEquip_Head = MoveEvent()

function onEquip_Head.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Head:slot("head")
onEquip_Head:id(2496)
onEquip_Head:register()


local onDeEquip_Head = MoveEvent()

function onDeEquip_Head.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Head:slot("head")
onDeEquip_Head:id(2496)
onDeEquip_Head:register()



-- NECKLACE -------------------------------------------------------------------------------
local onEquip_Necklace = MoveEvent()

function onEquip_Necklace.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Necklace:slot("necklace")
onEquip_Necklace:id()
onEquip_Necklace:register()


local onDeEquip_Necklace = MoveEvent()

function onDeEquip_Necklace.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Necklace:slot("necklace")
onDeEquip_Necklace:id()
onDeEquip_Necklace:register()


-- BACKPACK -------------------------------------------------------------------------------
local onEquip_Backpack = MoveEvent()

function onEquip_Backpack.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Backpack:slot("backpack")
onEquip_Backpack:id()
onEquip_Backpack:register()


local onDeEquip_Backpack = MoveEvent()

function onDeEquip_Backpack.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Backpack:slot("backpack")
onDeEquip_Backpack:id()
onDeEquip_Backpack:register()


-- ARMOR -------------------------------------------------------------------------------
local onEquip_Armor = MoveEvent()

function onEquip_Armor.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Armor:slot("armor")
onEquip_Armor:id(8821)
onEquip_Armor:register()


local onDeEquip_Armor = MoveEvent()

function onDeEquip_Armor.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Armor:slot("armor")
onDeEquip_Armor:id(8821)
onDeEquip_Armor:register()


-- WEAPONS AND SHIELDS (hands) --------------------------------------------------------
local onEquip_Hands = MoveEvent()

function onEquip_Hands.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Hands:slot("hand")
onEquip_Hands:id()
onEquip_Hands:register()

local onDeEquip_Hands = MoveEvent()

function onDeEquip_Hands.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Hands:slot("hand")
onDeEquip_Hands:id()
onDeEquip_Hands:register()

-- LEGS -------------------------------------------------------------------------------
local onEquip_Legs = MoveEvent()

function onEquip_Legs.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Legs:slot("legs")
onEquip_Legs:id(8923)
onEquip_Legs:register()


local onDeEquip_Legs = MoveEvent()

function onDeEquip_Legs.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Legs:slot("legs")
onDeEquip_Legs:id(8923)
onDeEquip_Legs:register()


-- FEET -------------------------------------------------------------------------------
local onEquip_Feet = MoveEvent()

function onEquip_Feet.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Feet:slot("feet")
onEquip_Feet:id()
onEquip_Feet:register()


local onDeEquip_Feet = MoveEvent()

function onDeEquip_Feet.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Feet:slot("feet")
onDeEquip_Feet:id()
onDeEquip_Feet:register()


-- RING -------------------------------------------------------------------------------
local onEquip_Ring = MoveEvent()

function onEquip_Ring.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Ring:slot("ring")
onEquip_Ring:id()
onEquip_Ring:register()


local onDeEquip_Ring = MoveEvent()

function onDeEquip_Ring.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Ring:slot("ring")
onDeEquip_Ring:id()
onDeEquip_Ring:register()


-- AMMO -------------------------------------------------------------------------------
local onEquip_Ammo = MoveEvent()

function onEquip_Ammo.onEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onEquip_Ammo:slot("ammo")
onEquip_Ammo:id()
onEquip_Ammo:register()


local onDeEquip_Ammo = MoveEvent()

function onDeEquip_Ammo.onDeEquip(player, item, slot, isCheck)
    if not isCheck then
        addEvent(giveItemBonus, 0, player:getId())
    end
    return true
end

onDeEquip_Ammo:slot("ammo")
onDeEquip_Ammo:id()
onDeEquip_Ammo:register()


-- LOGIN ------------------------------------------------------------------------------
local loginEvent = CreatureEvent("newLoginEvent")
loginEvent:type("login")

function loginEvent.onLogin(player)
    addEvent(giveItemBonus, 0, player:getId())
    return true
end

loginEvent:register()

got this

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...vbr-global-develop\data\scripts\movements\bonusitems.lua:157: attempt to get length of a nil value
stack traceback:
[C]: in function '__len'
...vbr-global-develop\data\scripts\movements\bonusitems.lua:157: in function <...vbr-global-develop\data\scripts\movements\bonusitems.lua:117>
 
@Xikinigot this

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...vbr-global-develop\data\scripts\movements\bonusitems.lua:157: attempt to get length of a nil value
stack traceback:
[C]: in function '__len'
...vbr-global-develop\data\scripts\movements\bonusitems.lua:157: in function <...vbr-global-develop\data\scripts\movements\bonusitems.lua:117>
Add some prints please.

Need to know what item you're using, what vocation you're using, and what buff it's trying to add/create

between line 155 and 156
Lua:
local itemBonusIndex = config[itemID][1][voc][main_stats[n]]
for h = 1, #itemBonusIndex do
add
Lua:
local itemBonusIndex = config[itemID][1][voc][main_stats[n]]
print("itemID = " .. itemID .. ", voc = " .. voc .. ", stat = " .. main_stats[n] .. "")
for h = 1, #itemBonusIndex do
 
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...vbr-global-develop\data\scripts\movements\bonusitems.lua:156: attempt to concatenate local 'voc' (a table value)
stack traceback:
        [C]: in function '__concat'
        ...vbr-global-develop\data\scripts\movements\bonusitems.lua:156: in function <...vbr-global-develop\data\scripts\movements\bonusitems.lua:117>
now i get this
 
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
...vbr-global-develop\data\scripts\movements\bonusitems.lua:156: attempt to concatenate local 'voc' (a table value)
stack traceback:
        [C]: in function '__concat'
        ...vbr-global-develop\data\scripts\movements\bonusitems.lua:156: in function <...vbr-global-develop\data\scripts\movements\bonusitems.lua:117>
now i get this
In your main table is the issue.

You've typed
"life leechamount"

correct is
"life leech amount"

here's your table, with corrected words.
Lua:
local config  = {
    [2496] = { -- itemid
        slot = "head", -- ("head", "necklace", "backpack", "armor", "shield", "weapon", "legs", "feet", "ring", "ammo")
        {
            [{1, 5}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{2, 6}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{3, 7}] = {["statMain"] = {{"distance", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{4, 8}] = {["statMain"] = {{"axe", 5},{"sword", 5},{"club", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        }
    },
    [8821] = {
        slot = "armor",
        {
            [{1, 5}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{2, 6}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{3, 7}] = {["statMain"] = {{"distance", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{4, 8}] = {["statMain"] = {{"axe", 5},{"sword", 5},{"club", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        }
    },
    [8923] = {
        slot = "legs",
    {
            [{1, 5}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{2, 6}] = {["statMain"] = {{"magic", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{3, 7}] = {["statMain"] = {{"distance", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        
            [{4, 8}] = {["statMain"] = {{"axe", 5},{"sword", 5},{"club", 5},{"critical hit chance", 5},{"critical hit damage", 5},{"life leech chance", 5},{"life leech amount", 5},{"mana leech chance", 5},{"mana leech amount", 5}}},
        }
    }
}
 
Back
Top