• 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.2 NPC Trade

Felipe Monteiro

Webmaster
Joined
Feb 27, 2009
Messages
460
Reaction score
59
Location
Brasil
I got an erro with traderequest, when I set to with backpacks..
Npc give me only backpack empty !

Code:
if items[item].buyPrice <= player:getMoney() then
                if inBackpacks then
                    local container = Game.createItem(1988, 1)
                    local bp = player:addItemEx(container)
                    if(bp ~= 1) then
                        return player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You don\'t have enough container.')
                    end
                    for i = 1, amount do
                        container:addItem(items[item].itemId, items[item])
                    end
                else
                    return
                    player:addItem(items[item].itemId, amount, false, items[item]) and
                    player:removeMoney(amount * items[item].buyPrice) and
                    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
                end
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
                player:removeMoney(amount * items[item].buyPrice)
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You do not have enough money.')
            end

the "not backpack" part is working fine, only with backpack part is not working.
And sorry by the tag!
 
Last edited by a moderator:
This script is not good at all, you should not return a function unless you are 100% sure what it will return (ex a function you made).
Use player:addItem insted of Game.CreateItem and player:addItemEx.
The functions does not ever return 1, if you expect the return value then actually write out the return value.

At the "not backpack function" remove the return including all the "and", once again you should not return things you are not 100% sure what they will return.

Also do NOT tag people not related to the post aswell as don't double post.
 
Back
Top