nefinoo
Carnage.flv
Using a example, i have a key with actionid = 1234 and the same key without actionid, how can remove the onlyone with actionid,
both keys has the itemid = 2973 (Bone key)
both keys has the itemid = 2973 (Bone key)
-- example
local key = findItemOnPlayerWithActionId(player, 2973, 1234)
if key then
-- key found, do something
key:remove(1)
end
-- potentially very heavy function, if player has many many items on them.
local function findItemOnPlayerWithActionId(player, itemId, actionId)
if not player:isPlayer() then
return false
end
for slot = 1, 10 do
local slotItem = player:getSlotItem(slot)
if slotItem then
local slotItemId = slotItem:getId()
if slotItemId == itemId...
-- example
local key = findItemOnPlayerWithActionId(player, 2973, 1234)
if key then
-- key found, do something
key:remove(1)
end
-- potentially very heavy function, if player has many many items on them.
local function findItemOnPlayerWithActionId(player, itemId, actionId)
if not player:isPlayer() then
return false
end
for slot = 1, 10 do
local slotItem = player:getSlotItem(slot)
if slotItem then
local slotItemId = slotItem:getId()
if slotItemId == itemId and slotItem:getActionId() == actionId then
return slotItem
end
if ItemType(slotItemId):isContainer() then
local containerItems = slotItem:getItems(true)
for i = 1, #containerItems do
local item = containerItems[i]
if item:getId() == itemId and item:getActionId() == actionId then
return item
end
end
end
end
end
return false
end
knight with level 200 and loads of backpacks:Untested..
But basically it loops through all the equipment slots of the player, and checks for the itemId and actionId combo.
If any of those items is a container, it checks all the items inside as well.
Lua:-- example local key = findItemOnPlayerWithActionId(player, 2973, 1234) if key then -- key found, do something key:remove(1) end
Lua:-- potentially very heavy function, if player has many many items on them. local function findItemOnPlayerWithActionId(player, itemId, actionId) if not player:isPlayer() then return false end for slot = 1, 10 do local slotItem = player:getSlotItem(slot) if slotItem then local slotItemId = slotItem:getId() if slotItemId == itemId and slotItem:getActionId() == actionId then return slotItem end if ItemType(slotItemId):isContainer() then local containerItems = slotItem:getItems(true) for i = 1, #containerItems do local item = containerItems[i] if item:getId() == itemId and item:getActionId() == actionId then return item end end end end end return false end
Feel free to post a cleaner solution.knight with level 200 and loads of backpacks:
just add check to check only first container and give error that it was not found in first backback instead of infinitely iterating over everything and using server res? or yet better to make the action smoother make sure player has it in his hand it only makes sense the player is "handing" the key right? pure RPG vibeFeel free to post a cleaner solution.
It all depends on what the OP requires. If he needs the key deleted no matter what, then recursion is the only option.just add check to check only first container and give error that it was not found in first backback instead of infinitely iterating over everything and using server res? or yet better to make the action smoother make sure player has it in his hand it only makes sense the player is "handing" the key right? pure RPG vibe
yeah but if the recursion doesnt finish and player removes backpacks /trades them etc? or changes positions in bpIt all depends on what the OP requires. If he needs the key deleted no matter what, then recursion is the only option.
what on earth are you talking about? This operation is sync... nothing else happens until the script is finished, and it all happens in milliseconds.yeah but if the recursion doesnt finish and player removes backpacks /trades them etc? or changes positions in bp
miliseconds until its evo ots with 999999capwhat on earth are you talking about? This operation is sync... nothing else happens until the script is finished, and it all happens in milliseconds.
Very true. But then it comes down to not allowing mis-use of the script, i.e adding exhausts etc.miliseconds until its evo ots with 999999cap
-- potentially very heavy function, if player has many many items on them.
-- set deepSearch to false, to only check the top layer of containers.
local function findItemOnPlayerWithActionId(player, itemId, actionId, deepSearch)
if not player:isPlayer() then
return false
end
deepSearch = deepSearch == nil and true or deepSearch
for slot = 1, 10 do
local slotItem = player:getSlotItem(slot)
if slotItem then
local slotItemId = slotItem:getId()
if slotItemId == itemId and slotItem:getActionId() == actionId then
return slotItem
end
if ItemType(slotItemId):isContainer() then
local containerItems = slotItem:getItems(deepSearch)
for i = 1, #containerItems do
local item = containerItems[i]
if item:getId() == itemId and item:getActionId() == actionId then
return item
end
end
end
end
end
return false
end