RevScript Identification System

Alex

Miembro del equipo
Webdesigner
LV
58
 
Awards
38
Hola a todos

Os comparto el sistema para augmentar un objeto o bien identificarlo,

Me explico,
Tenemos una Golden Armor, al utilizar por ejemplo un SOIL ( o cualquier item que desean ) este tiene X probabilidad de convertir la Golden Armor en una Magic Plate armor.
Esto funciona con un % de probabilidad que ustedes pueden augmentar o disminuir.

Puede servir también como script de identificación de items,

Código:
local action = Action()

local config = {
    messages = {
        success = {
            text  = 'The Item has been identified!',
            talkType = MESSAGE_INFO_DESCR,
            effect   = 48
        },

        fail = {
            text  = 'Identification failed. The item was destroyed. Next time use a Luminous concoction to avoid break an unidentified item!',
            talkType = MESSAGE_INFO_DESCR,
            effect   = 3
        }

    },

    gear = {
        [12807] = {tier = 1, upgraderType = 'rune', chance = 30,
            items = {
                [39148] = 35197, 
            }
        },
    }
}

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Using player's position if the target item is located in a container, otherwise use the item's position located on the map
    local pos = target:getPosition().x == 65535 and player:getPosition() or target:getPosition()
    -- Make sure the player is not attempting to target a creature
    if not target:isItem() then
        player:sendCancelMessage('You must select an item.')
        pos:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    -- Attempt to get the config based on which key id the player is using
    local keyConfig = config.gear[item:getId()]
    -- Adding article to full item name if possible, ex: "a sword"
    local name  = (target:getArticle() ~= '') and string.format('%s %s', target:getArticle(), target:getName()) or target:getName()
    if keyConfig then
        -- Directly attempt to access the item id to upgrade to by indexing the item list with the target item's id
        local upgradeId = keyConfig.items[target:getId()]
        -- Prevent attempting to upgrade an item that isn't in config
        if not upgradeId then
            player:sendCancelMessage(string.format('You are unable to identificate %s with %d %s.', (name == '') and 'this' or name, keyConfig.tier, keyConfig.upgraderType))
            pos:sendMagicEffect(249)
            return true
        end
        if target:getCount() > 1 then
            player:sendCancelMessage('You may only identificate this item one at a time.')
            pos:sendMagicEffect(CONST_ME_POFF)
            return true
        end
        -- Use the "success" table in config if the random value is less than or equal to the chance, otherwise use the "fail" table
        local confKey = (math.random(100) <= keyConfig.chance and 'success' or 'fail')
        local resultConfig = config.messages[confKey]
        pos:sendMagicEffect(resultConfig.effect)
        player:sendTextMessage(MESSAGE_INFO_DESCR, resultConfig.text)
        if confKey == 'success' then
            target:transform(upgradeId)
            target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, ItemType(target:getId()):getDescription().."\nIdentified by "..player:getName()..".")
        end
        if confKey == 'fail' then 
            target:remove(1)
        end
        item:remove(1)
    end
    return true
end


for keyId, _ in pairs(config.gear) do
    action:id(keyId)
end
action:aid(12807) -- El item que hara upgrade
action:register()
 
Última edición:
Arriba