data/events/scripts/player.lua
local bindableItems = {1111, 2222, 3333, 4444} -- itemId's
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
return true
end
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
-- filter out all items that are not bindable
if not table.contains(bindableItems, item:getId()) then
return true
end
-- check to ensure that the item is being moved to an equippable inventory slot
if toPosition.x ~= CONTAINER_POSITION then
return true
end
if toPosition.y == CONST_SLOT_BACKPACK and self:getSlotItem(CONST_SLOT_BACKPACK) then
return true
end
if toPosition.y > CONST_SLOT_AMMO then
return true
end
-- now we check for item binding
local playerName = self:getName()
local boundItem = item:getCustomAttribute("BoundItem")
if not boundItem then
item:setCustomAttribute("BoundItem", playerName)
self:sendTextMessage(MESSAGE_STATUS_SMALL, "This item is now bound to this character.")
return true
end
if boundItem ~= playerName then
self:sendTextMessage(MESSAGE_STATUS_SMALL, "Unable to equip. This item is already bound to another character.")
return false
end
return true
end
function Player:onLook(thing, position, distance)
local description = "You see " .. thing:getDescription(distance)
if self:getGroup():getAccess() then
.
.
.
end
self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
function Player:onLookInTrade(partner, item, distance)
self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance))
end
function Player:onLook(thing, position, distance)
local description = "You see " .. thing:getDescription(distance)
if thing:isItem() and table.contains(bindableItems, thing:getId()) then
local boundItem = thing:getCustomAttribute("BoundItem")
if not boundItem then
description = string.format("%s\nItem is currently not bound.", description)
else
description = string.format("%s\nItem is currently bound to %s.", description, boundItem)
end
end
if self:getGroup():getAccess() then
.
.
.
end
self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
function Player:onLookInTrade(partner, item, distance)
self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance))
if table.contains(bindableItems, item:getId()) then
local boundItem = item:getCustomAttribute("BoundItem")
if not boundItem then
description = string.format("%s\nItem is currently not bound.", description)
else
description = string.format("%s\nItem is currently bound to %s.", description, boundItem)
end
end
end
I will try laterTry this.
data/events/scripts/player.lua
Put this at the top of the script, above all functions.
ChangeLua:local bindableItems = {1111, 2222, 3333, 4444} -- itemId's
ToLua:function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder) return true end
Lua:function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder) -- filter out all items that are not bindable if not table.contains(bindableItems, item:getId()) then return true end -- check to ensure that the item is being moved to an equippable inventory slot if toPosition.x ~= CONTAINER_POSITION then return true end if toPosition.y == CONST_SLOT_BACKPACK and self:getSlotItem(CONST_SLOT_BACKPACK) then return true end if toPosition.y > CONST_SLOT_AMMO then return true end -- now we check for item binding local playerName = self:getName() local boundItem = item:getCustomAttribute("BoundItem") if not boundItem then item:setCustomAttribute("BoundItem", playerName) self:sendTextMessage(MESSAGE_STATUS_SMALL, "This item is now bound to this character.") return true end if boundItem ~= playerName then self:sendTextMessage(MESSAGE_STATUS_SMALL, "Unable to equip. This item is already bound to another character.") return false end return true end
Change these 2 functions
Lua:function Player:onLook(thing, position, distance) local description = "You see " .. thing:getDescription(distance) if self:getGroup():getAccess() then . . . end self:sendTextMessage(MESSAGE_INFO_DESCR, description) end
toLua:function Player:onLookInTrade(partner, item, distance) self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance)) end
Lua:function Player:onLook(thing, position, distance) local description = "You see " .. thing:getDescription(distance) if thing:isItem() and table.contains(bindableItems, thing:getId()) then local boundItem = thing:getCustomAttribute("BoundItem") if not boundItem then description = string.format("%s\nItem is currently not bound.", description) else description = string.format("%s\nItem is currently bound to %s.", description, boundItem) end end if self:getGroup():getAccess() then . . . end self:sendTextMessage(MESSAGE_INFO_DESCR, description) end
Lua:function Player:onLookInTrade(partner, item, distance) self:sendTextMessage(MESSAGE_INFO_DESCR, "You see " .. item:getDescription(distance)) if table.contains(bindableItems, item:getId()) then local boundItem = item:getCustomAttribute("BoundItem") if not boundItem then description = string.format("%s\nItem is currently not bound.", description) else description = string.format("%s\nItem is currently bound to %s.", description, boundItem) end end end
Let me know how it goes.I will try later
i have changed functionLet me know how it goes.
thing:getCustomAttribute("BoundItem") to thing:getAttribute("BoundItem")
item:setCustomAttribute("BoundItem", playerName) to item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, ("BoundItem %s"):format(item:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION), playerName))
end
i have add the functions required, work perfectlyAh. I did not realize 1.2 didn't have custom attributes.
I can't competently make this system without testing stuff in that case.
Sorry lol