8408323
Hoster
- Joined
- Mar 6, 2009
- Messages
- 432
- Reaction score
- 26
Hello,
I'm trying to create a script which can load the players items. I get this error in the console.
This is the code,
and I've added this into global.lua
Somehow I can not make the script to load "db.getResult". Anyone know how I can load the db into the lua?
I've tried adding this into global.lua as well, which is kind of useless though. After adding this I shouldn't need to write db.storeQuery, right?
Thanks in advice,
8408323
I'm trying to create a script which can load the players items. I get this error in the console.
Code:
Attempt to call field 'getResult' <a nil value>
Code:
function getItemsInContainer(cont, sep)
local text = ""
local tsep = ""
local count = ""
for i=1, sep do
tsep = tsep.."-"
end
tsep = tsep..">"
for i=0, getContainerSize(cont.uid)-1 do
local item = getContainerItem(cont.uid, i)
if isContainer(item.uid) == FALSE then
if item.type > 1 then
count = " ("..item.type.."x)"
end
text = text.."\n"..tsep..getItemName(item.itemid)..""..count.." ("..item.itemid..")"
else
if getContainerSize(item.uid) > 0 then
text = text.."\n"..tsep..getItemName(item.itemid).." ("..item.itemid..")"
text = text..getItemsInContainer(item, sep+2)..""
else
text = text.."\n"..tsep..getItemName(item.itemid).." ("..item.itemid..")"
end
end
end
return text
end
function onSay(cid, words, param)
if(param == '') then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
return false
end
local slotName = {"Head", "Amulet", "Backpack", "Armor", "Right Hand", "Left Hand", "Legs", "Feet", "Ring", "Ammo Slot"}
local t = param:split(', ')
if getPlayerGroupId(cid) >= 3 then
id = getItemIdByName(t[1])
if not id then
doPlayerSendCancel(cid, "The "..t[1].." not exist. ")
return false
end
local resultID = db.storeQuery("SELECT name FROM players WHERE id IN (SELECT player_id FROM player_items WHERE itemtype = ".. id.. ");")
local msg = "Search results by item ".. getItemName(id) .." in your database:\n\n"
if resultID then
while true do
local name = result:getDataString(resultID, 'name')
msg = msg .. 'name' .."\n"
if not resultID then
break
end
end
else
msg = msg .. "The item was not found in any player."
end
doShowTextDialog(cid, id, msg)
end
end
return true
end
Code:
-- Check player --
function getPlayerNameByGUID(guid)
local name = 0
local resultId = db.getResult("SELECT `name` FROM `players` WHERE `id` = " .. guid)
if(resultId:getID() ~= -1) then
name = resultId.getDataString(resultId, "name")
resultId:free()
end
return name
end
-- End Check player --
I've tried adding this into global.lua as well, which is kind of useless though. After adding this I shouldn't need to write db.storeQuery, right?
Code:
db.getResult = db.storeQuery
Thanks in advice,
8408323
Last edited: