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
---example script for...
I'd say set a custom attribute on the item equal to player GUID and then check it on use.So second question, How?
-- Made by Tofame
-- Gives item that is named with a player's name.
local chestStorage = 1430
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getStorageValue(chestStorage) > 1 then
return player:sendCancelMessage("You have already opened this chest!")
end
local name = player:getName()
local itemExp = player:addItem(26434, 1)
itemExp:setActionId(998)
itemExp:setAttribute("name", "" .. player:getName() .." 's Exp Scroll")
player:setStorageValue(chestStorage, 2)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have obtained an exp scroll that only you can use!")
return
end
-- Made by Tofame
-- Allows for item usage only for the owner!
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.actionid == 998 then
local itemName = item:getName()
if itemName == ("" .. player:getName() .." 's Exp Scroll") then
player:addExperience(250000)
item:remove(1)
else
return player:sendCancelMessage("This scroll exp is not yours!")
end
else
return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "ok") -- this shouldnt be shown,
-- if it shows it means scroll wont work
end
end
<action actionid="998" script="PersonalExpScroll.lua" />
<action actionid="997" script="ChestGivingScrollOnUse.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
---example script for scroll use check
function onUse(player, item, fromPosition, target, toPosition, 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
---example to obtain unique item
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
player:sendCancelMessage("Congratulations, you have found unique scroll that only you can use it.")
local reward = player:addItem(6666)
player:setUniqueItemUsage(reward)
return true
end
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
---example script for scroll use check
function onUse(player, item, fromPosition, target, toPosition, 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
---example to obtain unique item
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
player:sendCancelMessage("Congratulations, you have found unique scroll that only you can use it.")
local reward = player:addItem(6666)
player:setUniqueItemUsage(reward)
return true
end
Somehow i can't edit my post, i did a mistake, here is a fix
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 ---example script for scroll use check function onUse(player, item, fromPosition, target, toPosition, 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 ---example to obtain unique item function onUse(player, item, fromPosition, target, toPosition, isHotkey) player:sendCancelMessage("Congratulations, you have found unique scroll that only you can use it.") local reward = player:addItem(6666) player:setUniqueItemUsage(reward) return true end