• 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 1.X+ Removing a backpack with items NPC Function

manuloku

New Member
Joined
Nov 12, 2008
Messages
31
Reaction score
4
The code works like this: When I say YES The NPC trades a bunch of items (runes) from my Backpack and give me a item... This part is working fine at all..

There are two things not working as i want: First one is that if I have more than the necessary number of items (runes) in table it will remove them all, and not just the required number of items (20 runes). How can i Limit it to remove JUST the required ones? (20 runes)

Here is the table:

Code:
['ultimate healing rune'] = {cost = 20, items = {{2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}, {2273,2}}, outfit_female = 26612, outfit_male = 26612, addon = 1, storageID = 10042},

(Just ignore the outfit names, just overwrited an addon script)

Lua:
outfit_male = 26612
This is the given item (when trading the 20 items)

Here is the code:

Lua:
    elseif msgcontains(msg, "yes") or msgcontains(msg, "sim") then
        if (talkState[talkUser] > 10010 and talkState[talkUser] < 10100) then
            local items_number = 0
            if table.maxn(addoninfo[rtnt[talkUser]].items) > 0 then
                for i = 1, table.maxn(addoninfo[rtnt[talkUser]].items) do
                    local item = addoninfo[rtnt[talkUser]].items[i]
                    if (getPlayerItemCount(cid,item[1]) >= item[2]) then
                        items_number = items_number + 1
                    end
                end
            end
            if(getPlayerMoney(cid) >= addoninfo[rtnt[talkUser]].cost) and (items_number == table.maxn(addoninfo[rtnt[talkUser]].items)) then
                doPlayerRemoveMoney(cid, addoninfo[rtnt[talkUser]].cost)
                if table.maxn(addoninfo[rtnt[talkUser]].items) > 0 then
                    for i = 1, table.maxn(addoninfo[rtnt[talkUser]].items) do
                        local item = addoninfo[rtnt[talkUser]].items[i]
                        doPlayerRemoveItem(cid,item[1],item[2])
                        if container:getSize() == 0 then
                            container:remove()
                        end                        
                    end    
                end
                doPlayerAddItem(cid, addoninfo[rtnt[talkUser]].outfit_male)
                npcHandler:say('Aqui está seu pacote.', cid)
            else
                npcHandler:say('Você não tem as runas, cargas ou o dinheiro necessário!', cid)
            end
            rtnt[talkUser] = nil
            talkState[talkUser] = 0
            npcHandler:resetNpc()
            return true
        end

Also, I'm looking for some function to remove the BACKPACK that had the 20 items inside too, so the server wont have tons of backpack on the floor...

Sorry for my BAD English, at least i tried...

Thanks a lot!
 
Last edited:
Back
Top