• 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!

Windows Shop problem

moudy

New Member
Joined
Feb 18, 2015
Messages
40
Reaction score
3
Hi, I have a problem with the shop.
After purchasing a sms store object, I get it but we still constantly script in the game gives me the object indefinitely in a loop
 
use TFS 1.2


shop script:

function onThink(interval, lastExecution, thinkInterval)

local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")

if(result:getID() ~= -1) then
while(true) do
cid = getCreatureByName(tostring(result:getDataString("player")))
product = tonumber(result:getDataInt("product"))
itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
if isPlayer(cid) then
local id = tonumber(itemr:getDataInt("item"))
local tid = tonumber(result:getDataInt("id"))
local count = tonumber(itemr:getDataInt("count"))
local tipe = tonumber(itemr:getDataInt("type"))
local productn = tostring(itemr:getDataString("name"))
if isInArray({5,8},tipe) then
if getPlayerFreeCap(cid) >= getItemWeightById(id, count) then
if isContainer(getPlayerSlotItem(cid, 3).uid) then
received = doAddContainerItem(getPlayerSlotItem(cid, 3).uid, id,count)
if received then
doPlayerSendTextMessage(cid,19, "You recived >> "..productn.." << from Dream Shop")
db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
else
doPlayerSendTextMessage(cid,19, "Desculpe, você não tem espaço suficiente no recipiente para receber >> "..productn.." <<")
end
else
doPlayerSendTextMessage(cid,19, "Desculpe, você não tem um recipiente para receber >> "..productn.." <<")
end
else
doPlayerSendTextMessage(cid,19, "Desculpe, você não tem capacidade suficiente para receber >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
end
elseif isInArray({6,7},tipe) then
if tipe == 6 then
bcap = 8
bid = 1987
elseif tipe == 7 then
bcap = 20
bid = 1988
end
if isItemRune(id) then
count = 1
end
if getPlayerFreeCap(cid) >= (getItemWeightById(1987, 1) + getItemWeightById(id,count * bcap)) then
local bag = doCreateItemEx(bid, 1)
for i = 1,bcap do
doAddContainerItem(bag, id, count)
end
received = doPlayerAddItemEx(getPlayerSlotItem(cid, 3).uid, bag)
if received == RETURNVALUE_NOERROR then
doPlayerSendTextMessage(cid,19, "You reicived >> "..productn.." << from shop")
db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
else
doPlayerSendTextMessage(cid,19, "Desculpe, você não tem espaço suficiente para receber >> "..productn.." <<")
end
else
doPlayerSendTextMessage(cid,19, "Desculpe, você não tem capacidade suficiente para receber >> "..productn.." << (You need: "..getItemWeightById(id, count).." Capacity)")
end
end
end
itemr:free()
if not(result:next()) then
break
end
end
result:free()
end
return true
end



when buy item in sms shop, the script every moment endlessly giving me this item
I bought by sms shop on the internet Gesior acc 1.0
I bought a dragon shield



looppng_ssxnxne.png





dbpng_ssxnxeh.png



Error code in console TFS

data/globalevents/scripts/others/shop.lua:eek:nThink
data/globalevents/scripts/others/shop.lua:57: attempt to perform arithmetic on l
ocal 'storage' (a string value)
stack traceback:
[C]: in function '__add'
data/globalevents/scripts/others/shop.lua:57: in function <data/globalev
ents/scripts/others/shop.lua:7>
[Error - GlobalEvents::think] Failed to execute event: shop

 
Last edited:
Could you try navigating to the folder: "data/globalevents/scripts/others" and then open "shop.lua" and paste the contents here?
 
here

-- ### CONFIG ###
-- message send to player by script "type" (types you can check in "global.lua")
SHOP_MSG_TYPE = 18
-- time (in seconds) between connections to SQL database by shop script
SQL_interval = 30
-- ### END OF CONFIG ###
function onThink(interval, lastExecution)
local result_plr = db.storeQuery("SELECT * FROM z_ots_comunication")
if(result_plr ~= false) then
repeat
local id = tonumber(result.getDataInt(result_plr, "id"))
local action = tostring(result.getDataString(result_plr, "action"))
local delete = tonumber(result.getDataInt(result_plr, "delete_it"))
local cid = getPlayerByName(tostring(result.getDataString(result_plr, "name")))
if(cid) then
local itemtogive_id = tonumber(result.getDataInt(result_plr, "param1"))
local itemtogive_count = tonumber(result.getDataInt(result_plr, "param2"))
local container_id = tonumber(result.getDataInt(result_plr, "param3"))
local container_count = tonumber(result.getDataInt(result_plr, "param4"))
local add_item_type = tostring(result.getDataString(result_plr, "param5"))
local add_item_name = tostring(result.getDataString(result_plr, "param6"))
local storage = tostring(result.getDataString(result_plr, "param7"))
local received_item = 0
local full_weight = 0
if(add_item_type == 'container') then
container_weight = getItemWeight(container_id, 1)
if(isItemRune(itemtogive_id)) then
items_weight = container_count * getItemWeight(itemtogive_id, 1)
else
items_weight = container_count * getItemWeight(itemtogive_id, itemtogive_count)
end
full_weight = items_weight + container_weight
else
full_weight = getItemWeight(itemtogive_id, itemtogive_count)
if(isItemRune(itemtogive_id)) then
full_weight = getItemWeight(itemtogive_id, 1)
else
full_weight = getItemWeight(itemtogive_id, itemtogive_count)
end
end
local free_cap = getPlayerFreeCap(cid)
if(full_weight <= free_cap) then
if(add_item_type == 'container') then
local new_container = doCreateItemEx(container_id, 1)
local iter = 0
while(iter ~= container_count) do
doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
iter = iter + 1
end
received_item = doPlayerAddItemEx(cid, new_container)
else
local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
received_item = doPlayerAddItemEx(cid, new_item)
end
if(type(received_item) == "number" and received_item == RETURNVALUE_NOERROR) then
doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received '.. add_item_name ..' from TIBIAWS Shop.')
setPlayerStorageValue(cid,storage+555884621212,1)
db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
else
doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' from TIBIAWS Shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
end
else
doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' TIBIAWS Shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
end
end
until not result.next(result_plr)
result.free(result_plr)
end
return true
end



before I pasted over with
data/globalevent/shop.lua , now data/globalevent/other/shop.lua
 
Last edited:
Replace what you had in "data/globalevent/other/shop.lua" with:

PHP:
-- ### CONFIG ###
-- message send to player by script "type" (types you can check in "global.lua")
SHOP_MSG_TYPE = 18
-- time (in seconds) between connections to SQL database by shop script
SQL_interval = 30
-- ### END OF CONFIG ###
function onThink(interval, lastExecution)
    local result_plr = db.storeQuery("SELECT * FROM z_ots_comunication")
    if(result_plr ~= false) then
        repeat
            local id = tonumber(result.getDataInt(result_plr, "id"))
            local action = tostring(result.getDataString(result_plr, "action"))
            local delete = tonumber(result.getDataInt(result_plr, "delete_it"))
            local cid = getPlayerByName(tostring(result.getDataString(result_plr, "name")))
            if(cid) then
                local itemtogive_id = tonumber(result.getDataInt(result_plr, "param1"))
                local itemtogive_count = tonumber(result.getDataInt(result_plr, "param2"))
                local container_id = tonumber(result.getDataInt(result_plr, "param3"))
                local container_count = tonumber(result.getDataInt(result_plr, "param4"))
                local add_item_type = tostring(result.getDataString(result_plr, "param5"))
                local add_item_name = tostring(result.getDataString(result_plr, "param6"))
                local storage = tostring(result.getDataString(result_plr, "param7"))
                local received_item = 0
                local full_weight = 0
                if(add_item_type == 'container') then
                    container_weight = getItemWeight(container_id, 1)
                    if(isItemRune(itemtogive_id)) then
                        items_weight = container_count * getItemWeight(itemtogive_id, 1)
                    else
                        items_weight = container_count * getItemWeight(itemtogive_id, itemtogive_count)
                    end
                    full_weight = items_weight + container_weight
                else
                    full_weight = getItemWeight(itemtogive_id, itemtogive_count)
                    if(isItemRune(itemtogive_id)) then
                        full_weight = getItemWeight(itemtogive_id, 1)
                    else
                        full_weight = getItemWeight(itemtogive_id, itemtogive_count)
                    end
                end
                local free_cap = getPlayerFreeCap(cid)
                if(full_weight <= free_cap) then
                    if(add_item_type == 'container') then
                        local new_container = doCreateItemEx(container_id, 1)
                        local iter = 0
                        while(iter ~= container_count) do
                            doAddContainerItem(new_container, itemtogive_id, itemtogive_count)
                            iter = iter + 1
                        end
                        received_item = doPlayerAddItemEx(cid, new_container)
                    else
                        local new_item = doCreateItemEx(itemtogive_id, itemtogive_count)
                        received_item = doPlayerAddItemEx(cid, new_item)
                    end
                    if(type(received_item) == "number" and received_item == RETURNVALUE_NOERROR) then
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, 'You received '.. add_item_name ..' from TIBIAWS Shop.')
                        db.query("DELETE FROM `z_ots_comunication` WHERE `id` = " .. id .. ";")
                        db.query("UPDATE `z_shop_history_item` SET `trans_state`='realized', `trans_real`=" .. os.time() .. " WHERE id = " .. id .. ";")
                    else
                        doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' from TIBIAWS Shop is waiting for you. Please make place for this item in your backpack/hands and wait about '.. SQL_interval ..' seconds to get it.')
                    end
                else
                    doPlayerSendTextMessage(cid, SHOP_MSG_TYPE, ' '.. add_item_name ..' TIBIAWS Shop is waiting for you. It weight is '.. full_weight ..' oz., you have only '.. free_cap ..' oz. free capacity. Put some items in depot and wait about '.. SQL_interval ..' seconds to get it.')
                end
            end
        until not result.next(result_plr)
        result.free(result_plr)
    end
    return true
end
 
Not sure if you added it or not, but right before it deletes the record of the purchase it tries to run this line:
PHP:
  setPlayerStorageValue(cid,storage+555884621212,1)

Now first of all the local variable "storage" is a string, so adding a number crashes the script at that point. Thus after it has given you the item, but before it has "registered" that it sent you the item, the script crashes.

Looking at your picture of the database table, the variable "storage" is just nothing. Not sure what it is for.

You could add storage again and use the "tonumber" function. But since it wasn't properly handled before, it can be assumed that it isn't supposed to be there.
 
Back
Top Bottom