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

RevScripts unique usage

T

Tibia Demon

Guest
i try use this by @Dakos but i get error. i need make 1 forth function too for remove the custom attribute using other item gem or key and make it normal item for all player
and i try add item description for say item found by playername or belong playername.
24: attempt to index global 'self' (a nil value)
Lua:
local tryfornextquest2 = Action()
function tryfornextquest2.onUse(player, item, fromPos, target, toPos, isHotkey)
    local reward = player:addItem(7723)
    player:setUniqueItemUsage(reward)
    player:sendCancelMessage("Congratulations, you have found unique scroll that only you can use it.")
    -- can add decription when look in item it say [belong to playername] or [found by playername]
    return true
end

tryfornextquest2:id(7722)
tryfornextquest2:register()
Lua:
UNIQUE_CUSTOM_ATTRIBUTE = "CUSTOM_UNIQUE_USAGE"

function Player.canUseUniqueItem(item)
    if not item then
        return nil
    end

    local attr = item:getCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    if attr and attr == self:getGuid() then
        return true
    end
    return false
end

function Player.setUniqueItemUsage(item)
    if not item then
        return nil
    end

    return item:setCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE, self:getGuid())
end

function Item.getUniqueUsage()
    local attr = self:getCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    if attr then
        return attr
    end

    return false
end

--[[
function Item.removeUniqueUsage()
 
    i cant make this.
    i need to make 1 gem when i use in any uniqueUsageitem to remove [unique] and make it normal item for all players
 
    return false
end
]]
local tryfornextquest = Action()

function tryfornextquest.onUse(player, item, fromPos, target, toPos, isHotkey)
    if item:getUniqueUsage() then
        if not player:canUseUniqueItem(item) then
            player:sendCancelMessage("You are not allowed to use this item.")
            return true
        end

        player:addExperience(666)
        item:remove(1)
        player:sendCancelMessage("blabla congratulations.")
    end

    return true
end

tryfornextquest:id(1948)
tryfornextquest:register()
i tried add the new functions to global.lua-compat.lua and data/core/player.lua still all error
 
Last edited by a moderator:
Solution
Lua:
UNIQUE_CUSTOM_ATTRIBUTE = "CUSTOM_UNIQUE_USAGE"

function Player.canUseUniqueItem(self, item)
    if not item then
        return nil
    end

    local attr = item:getCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    if attr and attr == self:getGuid() then
        return true
    end
    return false
end

function Player.setUniqueItemUsage(self, item)
    if not item then
        return nil
    end

    return item:setCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE, self:getGuid())
end

function Item.getUniqueUsage(self)
    local attr = self:getCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    if attr then
        return attr
    end

    return false
end

Remove Unique Usage:
Lua:
function Item.removeUniqueUsage(self)
    local attr =...
Lua:
UNIQUE_CUSTOM_ATTRIBUTE = "CUSTOM_UNIQUE_USAGE"

function Player.canUseUniqueItem(self, item)
    if not item then
        return nil
    end

    local attr = item:getCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    if attr and attr == self:getGuid() then
        return true
    end
    return false
end

function Player.setUniqueItemUsage(self, item)
    if not item then
        return nil
    end

    return item:setCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE, self:getGuid())
end

function Item.getUniqueUsage(self)
    local attr = self:getCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    if attr then
        return attr
    end

    return false
end

Remove Unique Usage:
Lua:
function Item.removeUniqueUsage(self)
    local attr = self:getCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    if attr then
        return self:removeCustomAttribute(UNIQUE_CUSTOM_ATTRIBUTE)
    end
    return false
end

Try.

About "look on description" give me your
Code:
default_onLook.lua
that can be found in data/scripts/eventcallbacks/player
 
Last edited:
Solution
thank you! all 4 function work
this is my onlook
Lua:
local ec = EventCallback

ec.onLook = function(self, thing, position, distance, description)
    local description = "You see " .. thing:getDescription(distance)
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end

            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end

            local itemType = thing:getType()

            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:isPlayer() and thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end

        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: %d, %d, %d",
            description, position.x, position.y, position.z
        )

        if thing:isCreature() then
            if thing:isPlayer() then
                description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
            end
        end
    end
    return description
end

ec:register()
fixed
 
Last edited by a moderator:
Back
Top