• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

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
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
???
 
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 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
 
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?
 
@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:
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.
 
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
 
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
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!
 
Back
Top