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

[Help] getPlayerItemCount(), boolean

olavo

New Member
Joined
May 29, 2007
Messages
74
Reaction score
0
I have this code:
Lua:
function checaItens()
	local items = {{id = 2160, count = 2}, {id = 2152, count = 5}}
	local retorna = true
	for i, item in ipairs(items) do
		if(retorna == true) then
 			if(getPlayerItemCount(cid, item.id) < item.count) then
				retorna = false
			end
		end
	end
	return retorna
end
why its returning this error:
[22/08/2009 23:52:46] Lua Script Error: [Npc interface]
[22/08/2009 23:52:46] mods/npc/2promotion/missao1.lua:eek:nCreatureSay

[22/08/2009 23:52:46] mods/npc/2promotion/missao1.lua:33: attempt to compare boolean with number
[22/08/2009 23:52:46] stack traceback:
[22/08/2009 23:52:46] mods/npc/2promotion/missao1.lua:33: in function 'checaItens'
[22/08/2009 23:52:46] mods/npc/2promotion/missao1.lua:62: in function 'callback'
[22/08/2009 23:52:46] data/npc/lib/npcsystem/npchandler.lua:383: in function 'onCreatureSay'
[22/08/2009 23:52:46] mods/npc/2promotion/missao1.lua:12: in function <mods/npc/2promotion/missao1.lua:12>
getPlayerItemCount(...) may not return a number? whats worng here?
Using TFS 0.3.5 pl1
 
Last edited:
I dont think it's necessary, as the npc is not 100% done and the error are that getPlayerItemCount(...) are returning boolean, not number...
 
Lua:
function checaItens()
        local items = {{id = 2160, count = 2}, {id = 2152, count = 5}}
        local retorna = true
        for i, item in ipairs(items) do
                if(retorna == true) then
                        if(getPlayerItemCount(cid, item.id[i]) < item.count[i]) then
                                retorna = false
                        end
                end
        end
        return retorna
end
You forgot the "".
 
Sorry Shawak you are worng...
cant be there!
PS.
I changed
Lua:
if(getPlayerItemCount(cid, item.id) < item.count) then
to
Lua:
if(getPlayerItemCount(cid, 2152) < 3) then
for test and retuned the same error. :(
 
huahuaha
I found what was wrong :p
this:
Lua:
function checaItens()
should be
Lua:
function checaItens(cid)
because of
Lua:
if(getPlayerItemCount([b]cid[/b], item.id) < item.count) then
. Sorry my mastake :p
 
I like how you write "Items" as "Itens."
It confuses me when I try to read it, I think that is the main error.
 
Well that funcion return TRUE or FALSE (boolean).
I dont know how you are using the function on the npc script but it only must be like:

Lua:
if(chekaItens(cid)) then

OR

Lua:
if(chekaItens(cid) == FALSE) then
 
Back
Top