• 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!

Protection all % for onEquip and help with creating a table

Heroid

Active Member
Joined
Mar 7, 2011
Messages
332
Solutions
11
Reaction score
34
Hey, I'm wondering if someone can help me create a table for this script:

Lua:
local hp = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
hp:setParameter(CONDITION_PARAM_TICKS, -1)
hp:setParameter(CONDITION_PARAM_SUBID, 100)
hp:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 100)

local mp = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
mp:setParameter(CONDITION_PARAM_TICKS, -1)
mp:setParameter(CONDITION_PARAM_SUBID, 101)
mp:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, 100)

function onEquip(player, item, slot)
    if player:getVocation():getId() == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "+100 Mana")
        player:addCondition(mp)
        player:addMana(100)
            elseif player:getVocation():getId() == 3 or 4 then
                player:addCondition(hp)
                player:addHealth(100)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "+100 Health")
        end
    return true
end

function onDeEquip(player, item, slot)
    if player:getVocation():getId() == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "-100 Mana")
        player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, 101)
            elseif player:getVocation():getId() == 3 or 4 then
                player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, 100)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "-100 Health")
        end
    return true
end

I want a table where different item ids get different amount of HP or Mana.
If someone could also help me add the attribute Protection All % when equipping the item I would be very grateful, thanks. :d
 
Solution
How can I change this so depending on what item I equip it adds different amount of hp/mp.
Like this for example:
Lua:
local conditions = {
   [itemID] = {con = CONDITION_PARAM_STAT_MAXHITPOINTS, value = 100, subid = 100},
   [itemID] = {con = CONDITION_PARAM_STAT_MAXMANAPOINTS, value = 300, subid = 101}
}
This is probably not how it's done but you know what I mean.
Lua:
local equipment = {
    [1234] = {
        hp = {con = CONDITION_PARAM_STAT_MAXHITPOINTS, value = 100, subid = 100},
        mp = {con = CONDITION_PARAM_STAT_MAXMANAPOINTS, value = 100, subid = 101}
    }
}

local condition = {}
for itemid, conditions in pairs(equipment) do
    condition[itemid] = {}
    for i, v in pairs(conditions) do
        condition[itemid][i] =...
Lua:
local conditions = {
   hp = {con = CONDITION_PARAM_STAT_MAXHITPOINTS, value = 100, subid = 100},
   mp = {con = CONDITION_PARAM_STAT_MAXMANAPOINTS, value = 100, subid = 101}
}

local condition = {}
for i, v in pairs(conditions) do
    condition[i] = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
    condition[i]:setParameter(CONDITION_PARAM_TICKS, -1)
    condition[i]:setParameter(CONDITION_PARAM_SUBID, v.subid)
    condition[i]:setParameter(v.con, v.value)
end

function onEquip(player, item, slot)
    local vocId = player:getVocation():getId()
    if voicId == 1 then
        player:addCondition(condition['mp'])
        local mana = conditions['mp'].value
        player:addMana(mana)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "+"..mana.." Mana")
    elseif isInArray({3, 4}, vocId) then
        player:addCondition(condition['hp'])
        local health = conditions['hp'].value
        player:addHealth(health)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "+"..health.." Health")
    end
    return true
end

function onDeEquip(player, item, slot)
    local vocId = player:getVocation():getId()
    if voicId == 1 then
        local mana = conditions['mp'].value
        player:sendTextMessage(MESSAGE_INFO_DESCR, "-"..mana.." Mana")
        player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, conditions['mp'].subid)
    elseif isInArray({3, 4}, vocId) then
        local health = conditions['hp'].value
        player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, conditions['hp'].subid)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "-"..health.." Health")
    end
    return true
end
 
How can I change this so depending on what item I equip it adds different amount of hp/mp.
Like this for example:
Lua:
local conditions = {
   [itemID] = {con = CONDITION_PARAM_STAT_MAXHITPOINTS, value = 100, subid = 100},
   [itemID] = {con = CONDITION_PARAM_STAT_MAXMANAPOINTS, value = 300, subid = 101}
}
This is probably not how it's done but you know what I mean.
 
How can I change this so depending on what item I equip it adds different amount of hp/mp.
Like this for example:
Lua:
local conditions = {
   [itemID] = {con = CONDITION_PARAM_STAT_MAXHITPOINTS, value = 100, subid = 100},
   [itemID] = {con = CONDITION_PARAM_STAT_MAXMANAPOINTS, value = 300, subid = 101}
}
This is probably not how it's done but you know what I mean.
Lua:
local equipment = {
    [1234] = {
        hp = {con = CONDITION_PARAM_STAT_MAXHITPOINTS, value = 100, subid = 100},
        mp = {con = CONDITION_PARAM_STAT_MAXMANAPOINTS, value = 100, subid = 101}
    }
}

local condition = {}
for itemid, conditions in pairs(equipment) do
    condition[itemid] = {}
    for i, v in pairs(conditions) do
        condition[itemid][i] = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
        condition[itemid][i]:setParameter(CONDITION_PARAM_TICKS, -1)
        condition[itemid][i]:setParameter(CONDITION_PARAM_SUBID, v.subid)
        condition[itemid][i]:setParameter(v.con, v.value)
    end
end

function onEquip(player, item, slot)
    local id = item.itemid
    local slots = getPlayerSlotItem(player:getId(), slot)
    if slots.itemid ~= id then
        return true
    end
    if not next(equipment[id]) then
        return false
    end
    local vocId = player:getVocation():getId()   
    if voicId == 1 and next(equipment[id].mp) then
        player:addCondition(condition[id]['mp'])
        local mana = equipment[id]['mp'].value
        player:addMana(mana)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "+"..mana.." Mana")
    elseif isInArray({3, 4}, vocId) and next(equipment[id].hp) then
        player:addCondition(condition[id]['hp'])
        local health = equipment[id]['hp'].value
        player:addHealth(health)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "+"..health.." Health")
    end
    return true
end

function onDeEquip(player, item, slot)
    local id = item.itemid
    if not next(equipment[id]) then
        return false
    end
    local vocId = player:getVocation():getId()
    if voicId == 1 and next(equipment[id].mp) then
        local mana = equipment[id]['mp'].value
        player:sendTextMessage(MESSAGE_INFO_DESCR, "-"..mana.." Mana")
        player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, equipment[id]['mp'].subid)
    elseif isInArray({3, 4}, vocId) and next(equipment[id].hp) then
        local health = equipment[id]['hp'].value
        player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, equipment[id]['hp'].subid)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "-"..health.." Health")
    end
    return true
end
 
Solution
Lua:
local equipment = {
    [1234] = {
        hp = {con = CONDITION_PARAM_STAT_MAXHITPOINTS, value = 100, subid = 100},
        mp = {con = CONDITION_PARAM_STAT_MAXMANAPOINTS, value = 100, subid = 101}
    }
}

local condition = {}
for itemid, conditions in pairs(equipment) do
    condition[itemid] = {}
    for i, v in pairs(conditions) do
        condition[itemid][i] = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
        condition[itemid][i]:setParameter(CONDITION_PARAM_TICKS, -1)
        condition[itemid][i]:setParameter(CONDITION_PARAM_SUBID, v.subid)
        condition[itemid][i]:setParameter(v.con, v.value)
    end
end

function onEquip(player, item, slot)
    local id = item.itemid
    local slots = getPlayerSlotItem(player:getId(), slot)
    if slots.itemid ~= id then
        return true
    end
    if not next(equipment[id]) then
        return false
    end
    local vocId = player:getVocation():getId()  
    if voicId == 1 and next(equipment[id].mp) then
        player:addCondition(condition[id]['mp'])
        local mana = equipment[id]['mp'].value
        player:addMana(mana)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "+"..mana.." Mana")
    elseif isInArray({3, 4}, vocId) and next(equipment[id].hp) then
        player:addCondition(condition[id]['hp'])
        local health = equipment[id]['hp'].value
        player:addHealth(health)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "+"..health.." Health")
    end
    return true
end

function onDeEquip(player, item, slot)
    local id = item.itemid
    if not next(equipment[id]) then
        return false
    end
    local vocId = player:getVocation():getId()
    if voicId == 1 and next(equipment[id].mp) then
        local mana = equipment[id]['mp'].value
        player:sendTextMessage(MESSAGE_INFO_DESCR, "-"..mana.." Mana")
        player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, equipment[id]['mp'].subid)
    elseif isInArray({3, 4}, vocId) and next(equipment[id].hp) then
        local health = equipment[id]['hp'].value
        player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT, equipment[id]['hp'].subid)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "-"..health.." Health")
    end
    return true
end
Perfect, thanks alot!
 
Back
Top