samandriel
Active Member
- Joined
- Oct 19, 2016
- Messages
- 242
- Solutions
- 1
- Reaction score
- 46
how to get one specific item on backpack
get it charges to store in a variable
and delete it?
get it charges to store in a variable
and delete it?
getPlayerItemById(cid, deepSearch, itemId[, subType = -1])
local foundItem = getPlayerItemById(cid, false, 2164)
if foundItem then
doRemoveItem(foundItem)
end
local slotItem = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do
local slotItem = getPlayerSlotItem(cid, slot)
-- rest of the code
end
if isContainer(slotItem) then
for containerSlot = 0, getContainerSize(slotItem) - 1 do
local itemFound = getContainerItem(slotItem, containerSlot)
-- code to interact with the item
-- break or return to end the loop
-- alternatively you may use "while" loop to add more conditions
end
end
if you can equip bp in one slot only:
Code:local slotItem = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
if you can equip bp in all slots:
Code:for slot = CONST_SLOT_FIRST, CONST_SLOT_LAST do local slotItem = getPlayerSlotItem(cid, slot) -- rest of the code end
now you have to check if the item you found is a container:
Code:if isContainer(slotItem) then for containerSlot = 0, getContainerSize(slotItem) - 1 do local itemFound = getContainerItem(slotItem, containerSlot) -- code to interact with the item -- break or return to end the loop -- alternatively you may use "while" loop to add more conditions end end
If you can put bp in your hands in your server, you need to scan all eq slots to find all backpacks.
print("time to refill")
local weapons_in_backpack = getPlayerItemCount(cid,itemID)-1
if weapons_in_backpack >= 1 then
print("weapons_in_backpack: ".. weapons_in_backpack)
local slotItem = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
if isContainer(slotItem) then
print("container")
for containerSlot = 0, getContainerSize(slotItem) - 1 do
local itemFound = getContainerItem(slotItem, containerSlot)
print("itemFound: " .. itemFound)
if itemFound == itemID then
local charges = getItemAttribute(itemFound.uid, "charges")
print("charges: ".. charges)
-- over charges weapon on hands, refil:
addEvent (
function ()
local item = doCreateItemEx(ItemID, 1)
doItemSetAttribute(item, "charges", charges)
doPlayerAddItemEx(cid, item)
end, 100
)
addEvent (
function ()
doPlayerRemoveItem(cid, itemFound.uid, 1)
end, 150
)
end
end
end
wepon_hand_charges: 10
wepon_hand_charges: 8
wepon_hand_charges: 6
wepon_hand_charges: 4
wepon_hand_charges: 2
time to refill
weapons_in_backpack: 2
There's a function getPlayerItemCount(cid, itemid), but I'm not sure if it is in your server.
Edit: ok I have an idea, but I have to go now. Will answer later because I have to code it.
getPlayerItemById(cid, deepSearch, itemId[, subType = -1])
local foundItem = getPlayerItemById(cid, false, 2164)
if foundItem then
doRemoveItem(foundItem)
end
nvm, I'm overcomplicating that. Here is what you need:
getPlayerItemById(cid, deepSearch, itemId[, subType = -1])
cid - creature identifier
deepSearch - check backpacks that are in main backpack
itemId - identifier of item you're trying to find
subType - optional parameter, useful when you're looking for vials of water
example:
Code:local foundItem = getPlayerItemById(cid, false, 2164) if foundItem then doRemoveItem(foundItem) end
other functions the server have:
https://github.com/peonso/forgotten...c7e22cbb329be80f5b949/src/luascript.cpp#L1367 (starting from line 1372)
more functions:
https://github.com/peonso/forgottenserver036pl1/tree/master/data/lib