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

[modern acc]Shop System

dfs1

Member
Joined
Aug 27, 2011
Messages
82
Solutions
1
Reaction score
8
help with my shop system as when buying one item sige sending it
please veses countless
use modern acc:p

aki dejo mi shop.lua
HTML:
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 have received >> "..productn.." << from our shop system")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										else
											doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space on container to receive >> "..productn.." <<")
										end
									else
										doPlayerSendTextMessage(cid,19, "Sorry, you don't have a container to receive >> "..productn.." <<")
									end
								else
									doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..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 have received >> "..productn.." << from our shop system")
											db.executeQuery("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
										else
											doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space to receive >> "..productn.." <<")
										end
									else
										doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..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
 
try this:
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 have received >> "..productn.." << from voldaria's shop system.")
db.query("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
else
doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space on container to receive >> "..productn.." <<")
end
else
doPlayerSendTextMessage(cid,19, "Sorry, you don't have a container to receive >> "..productn.." <<")
end
else
doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..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 have received >> "..productn.." << from our shop system")
db.query("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
else
doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough space to receive >> "..productn.." <<")
end
else
doPlayerSendTextMessage(cid,19, "Sorry, you don't have enough capacity to receive >> "..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
 
sorry but I put your shop but sent me the following error in the console

Code:
[26/12/2012 01:53:27] [Error - GlobalEvent Interface] 
[26/12/2012 01:53:27] data/globalevents/scripts/shop.lua:onThink
[26/12/2012 01:53:27] Description: 
[26/12/2012 01:53:27] data/lib/004-database.lua:100: [Result:free] Result not set!
[26/12/2012 01:53:27] stack traceback:
[26/12/2012 01:53:27] 	[C]: in function 'error'
[26/12/2012 01:53:27] 	data/lib/004-database.lua:100: in function 'free'
[26/12/2012 01:53:27] 	data/globalevents/scripts/shop.lua:60: in function <data/globalevents/scripts/shop.lua:1>
[26/12/2012 01:53:27] [Error - GlobalEvents::think] Couldn't execute event: shop
 
Try this 004-database.lua

if(result == nil) then
print("> WARNING: Couldn't load database lib.")
return
end

Result = createClass(nil)
Result:setAttributes({
id = -1,
query = ""
})

function Result:getID()
return self.id
end

function Result:setID(_id)
self.id = _id
end

function Result:getQuery()
return self.query
end

function Result:setQuery(_query)
self.query = _query
end

function Result:create(_query)
self:setQuery(_query)
local _id = db.storeQuery(self:getQuery())
if(_id) then
self:setID(_id)
end

return self:getID()
end

function Result:getRows(free)
local free = free or false
if(self:getID() == -1) then
error("[Result:getRows] Result not set!")
end

local c = 0
repeat
c = c + 1
until not self:next()

local _query = self:getQuery()
self:free()
if(not free) then
self:create(_query)
end

return c
end

function Result:getDataInt(s)
if(self:getID() == -1) then
error("[Result:getDataInt] Result not set!")
end

return result.getDataInt(self:getID(), s)
end

function Result:getDataLong(s)
if(self:getID() == -1) then
error("[Result:getDataLong] Result not set!")
end

return result.getDataLong(self:getID(), s)
end

function Result:getDataString(s)
if(self:getID() == -1) then
error("[Result:getDataString] Result not set!")
end

return result.getDataString(self:getID(), s)
end

function Result:getDataStream(s)
if(self:getID() == -1) then
error("[Result:getDataStream] Result not set!")
end

return result.getDataStream(self:getID(), s)
end

function Result:next()
if(self:getID() == -1) then
error("[Result:next] Result not set!")
end

return result.next(self:getID())
end

function Result:free()
if(self:getID() == -1) then
error("[Result:free] Result not set!")
end

self:setQuery("")
local ret = result.free(self:getID())
self:setID(-1)
return ret
end

Result.numRows = Result.getRows
function db.getResult(query)
if(type(query) ~= 'string') then
return nil
end

local ret = Result:new()
ret:create(query)
return ret
end
 
sorry but the error persists and continues to send console demacioados items: S




Code:
[26/12/2012 15:39:35] [Error - GlobalEvent Interface] 
[26/12/2012 15:39:35] data/globalevents/scripts/shop.lua:onThink
[26/12/2012 15:39:35] Description: 
[26/12/2012 15:39:35] data/lib/004-database.lua:100: [Result:free] Result not set!
[26/12/2012 15:39:35] stack traceback:
[26/12/2012 15:39:35] 	[C]: in function 'error'
[26/12/2012 15:39:35] 	data/lib/004-database.lua:100: in function 'free'
[26/12/2012 15:39:35] 	data/globalevents/scripts/shop.lua:60: in function <data/globalevents/scripts/shop.lua:1>
[26/12/2012 15:39:35] [Error - GlobalEvents::think] Couldn't execute event: shop
 
I don't know what the problem can be but are you sure that you've added the things you need in the db?
 
I despair with this problem and switch to ai ai Gesior acc but I found the same problem with lua shop do not have the shop of Gesior?
 
I despair with this problem and switch to ai ai Gesior acc but I found the same problem with lua shop do not have the shop of Gesior?

I think that it's very easy to fix, just search on the forum.
 
Back
Top