TFS 0.X how to get one specific item on backpack

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?
 
Solution
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
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
is it possible to get a item by id on backpack
then get it charges to store in a variable
then delete this item i got the charges
???
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,004
Solutions
17
Reaction score
2,127
Location
Poland
GitHub
Zbizu
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
 
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
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

"now you have to check if the item you found is a container:"
What are u mean with this?

I wanna select/get an item, for example 2164 might ring inside my backpack
and put the charges the item i selected in a variable
and then delete this item i selected
 
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
If you can put bp in your hands in your server, you need to scan all eq slots to find all backpacks.

I don't understanding...
I don't want to scan a backpack, i want to find one item inside a backpack and look for it charges...
For example, i want to check if player has 3 might rings in his backpack
Got 1 of this 3, get this charges, store in a variable and then delete this item i store the charges
U gotcha?
 
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
@zbizu i tried to work with what u gave me:
Code:
      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


but prints this:
Code:
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
 
Last edited:

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,004
Solutions
17
Reaction score
2,127
Location
Poland
GitHub
Zbizu
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.
 
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
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.

Thank you, its important to me and i have no idea about how to do this
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,004
Solutions
17
Reaction score
2,127
Location
Poland
GitHub
Zbizu
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
 
Solution
OP
samandriel

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
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

Ty!
 
Top