• 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+ [1.3] can't send item to store inbox from store

Cornwallis

Member
Joined
Jan 3, 2010
Messages
480
Reaction score
16
Hello, I'm trying to send the item to the store inbox. I'm either accessing the store inbox with this script wrong, or something in sources, but i don't know because i don't get any errors. NOTE: i can move items freely to the store inbox( i did this to make sure it wasn't some equip error ), i have it defined as a slot, i have the store inbox item there. here's the code that adds the item:
Code:
function onRender(player, offer)
    return true
end

function onBuy(player, offer)
    local itemType = ItemType(offer:getName())
    if itemType:getId() == 0 then
        player:sendStoreError(STORE_ERROR_PURCHASE, "Item not found. Please contact an administrator.")
        return false
    end
    local storeBox = Container(player:getSlotItem(CONST_SLOT_STORE_INBOX))
    local gameItem = Game.createItem(itemType:getId(), 1)
    local storeBoxAddItem  = storeBox:addItemEx(gameItem)
    if storeBoxAddItem then
        return true
    end
end
If it's not this script then i'll find it.
 
Hello, I'm trying to send the item to the store inbox. I'm either accessing the store inbox with this script wrong, or something in sources, but i don't know because i don't get any errors. NOTE: i can move items freely to the store inbox( i did this to make sure it wasn't some equip error ), i have it defined as a slot, i have the store inbox item there. here's the code that adds the item:
Code:
function onRender(player, offer)
    return true
end

function onBuy(player, offer)
    local itemType = ItemType(offer:getName())
    if itemType:getId() == 0 then
        player:sendStoreError(STORE_ERROR_PURCHASE, "Item not found. Please contact an administrator.")
        return false
    end
    local storeBox = Container(player:getSlotItem(CONST_SLOT_STORE_INBOX))
    local gameItem = Game.createItem(itemType:getId(), 1)
    local storeBoxAddItem  = storeBox:addItemEx(gameItem)
    if storeBoxAddItem then
        return true
    end
end
If it's not this script then i'll find it.
Well, addItemEx creates a virtual item in memory, but not a physical item in the game.
Use addItem instead.
 
i tried addItem and it didn't work, for whatever reason I can't get it to acknowledge the storebox, like getSlotItem isn't looking there. I tried to target regular backpack, CONST_SLOT_BACKPACK, but I couldn't get that to work either, so i feel like i'm defining it wrong.
 
Container(uid)
C++:
int LuaScriptInterface::luaContainerCreate(lua_State* L)
{
    // Container(uid)
    uint32_t id = getNumber<uint32_t>(L, 2);

    Container* container = getScriptEnv()->getContainerByUID(id);
    if (container) {
        pushUserdata(L, container);
        setMetatable(L, -1, "Container");
    } else {
        lua_pushnil(L);
    }
    return 1;
}

Short story, change Container(player:getSlotItem(CONST_SLOT_STORE_INBOX)) to player:getSlotItem(CONST_SLOT_STORE_INBOX)
 
Last edited:
this is working
Code:
function onRender(player, offer)
    local itemType = ItemType(offer:getName())
    if itemType:getId() == 0 then
        return false, "Item not found. Please contact an administrator."
    end

    return true
end

function onBuy(player, offer)
    local itemType = ItemType(offer:getName())
    local itemWeight = itemType:getWeight()
    if itemWeight > player:getFreeCapacity() then
        player:sendStoreError(STORE_ERROR_PURCHASE, "Please make sure you have enough capacity for this item.")
        return false
    end
    local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX)
    if inbox and inbox:getEmptySlots() >= 1 then
        local playerItem = inbox:addItem(itemType:getId(), 1)
        if playerItem then
            return true
        else
            player:sendStoreError(STORE_ERROR_PURCHASE, "Get rekt kid.")
            return false        
        end
    else
        player:sendStoreError(STORE_ERROR_PURCHASE, "Please make sure you have free slots in your store inbox.")
        return false
    end

    return true
end
 
Last edited:
Back
Top