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

Lua getPlayerItemCount

Hanoger

Member
Joined
Mar 7, 2011
Messages
247
Reaction score
6
Hello, I've got a small problem, learning LUA right now..
I want, if the player have item X, or item Y, or item Z, then doPlayerAddItem XXXX
I have got the script, working with one item, but if I want to only this, that or another item it don't work...
Lua:
if getPlayerItemCount(cid, XXXX) >= X

I thought it works like
Lua:
if getPlayerItemCount(cid, XXXX) >= X or getPlayerItemCount(cid, XXXX) >= X or getPlayerItemCount(cid, XXXX) >= X

But it not, thanks for reply.
 
Last edited:
Lua:
function onSay(cid, words, param)
if getPlayerItemCount(cid, 7634) >= 100 or getPlayerItemCount(cid, 7635) >= 100 or getPlayerItemCount(cid, 7636) >= 100 then
doPlayerRemoveItem(cid, 7634, 100) or doPlayerRemoveItem(cid, 7635, 100) or doPlayerRemoveItem(cid, 7636, 100)
end
doPlayerAddItem(cid, 5957, 1)
doSendMagicEffect(getPlayerPosition(cid), 45)
doCreatureSay(cid, "Good luck!", TALKTYPE_ORANGE_1, false, 0)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have changed 100 empty potion flasks for a lottery ticket!")
else
doPlayerSendCancel(cid, "You dont have 100 empty potion flasks!")
end
return FALSE
end
 
Lua:
function onSay(cid, words, param)
	local prem = 0
	if(getPlayerItemCount(cid, 7634) == 100) then
		doPlayerRemoveItem(cid, 7634, 100) 
		prem = prem + 1
	end
	if(getPlayerItemCount(cid, 7635) == 100) then
		doPlayerRemoveItem(cid, 7635, 100) 	
		prem = prem + 1
	end
	if(getPlayerItemCount(cid, 7636) == 100) then
		doPlayerRemoveItem(cid, 7636, 100)
		prem = prem + 1
	end
	if(prem == 0) then
		doPlayerSendCancel(cid, "You dont have 100 empty potion flasks!")
		return true
	end
	doPlayerAddItem(cid, 5957, prem)
	doSendMagicEffect(getPlayerPosition(cid), 45)
	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have changed " .. 100 * prem .. " empty potion flasks for " .. prem .. " lottery ticket!")
	return true
end

idk why just made this way
 
Ehh, @up replied before me xD well my post was: (but now i see that im wrong i think xd so nevermind my post - i just didnt see josejunior's post)

Lua:
function onSay(cid, words, param)
if getPlayerItemCount(cid, 7634) >= 100 or getPlayerItemCount(cid, 7635) >= 100 or getPlayerItemCount(cid, 7636) >= 100 then
doPlayerRemoveItem(cid, 7634, 100) or doPlayerRemoveItem(cid, 7635, 100) or doPlayerRemoveItem(cid, 7636, 100)
end
doPlayerAddItem(cid, 5957, 1)
doSendMagicEffect(getPlayerPosition(cid), 45)
doCreatureSay(cid, "Good luck!", TALKTYPE_ORANGE_1, false, 0)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have changed 100 empty potion flasks for a lottery ticket!")
else
doPlayerSendCancel(cid, "You dont have 100 empty potion flasks!")
end
return FALSE
end
Are you sure you're supposed to end the function of removing the items? shouldn't there be return true?
I mean like, u didn't set any function for giving the item after removing the item.


try this:
Lua:
function onSay(cid, words, param)
if getPlayerItemCount(cid, 7634) >= 100 or getPlayerItemCount(cid, 7635) >= 100 or getPlayerItemCount(cid, 7636) >= 100 then
doPlayerRemoveItem(cid, 7634, 100) or doPlayerRemoveItem(cid, 7635, 100) or doPlayerRemoveItem(cid, 7636, 100)
return true
doPlayerAddItem(cid, 5957, 1)
doSendMagicEffect(getPlayerPosition(cid), 45)
doCreatureSay(cid, "Good luck!", TALKTYPE_ORANGE_1, false, 0)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have changed 100 empty potion flasks for a lottery ticket!")
else
doPlayerSendCancel(cid, "You dont have 100 empty potion flasks!")
end
return FALSE
end

I'm not a professionalist so I might be wrong. I'm also learning lua but I'm also trying to learn c++ ;D So don't blame me if I made this wrong xd
 
Back
Top