• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

NPC who checks amount of storages

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,012
Solutions
8
Reaction score
3,060
Location
Netherlands
I need a code to make a npc check how much quests someone did.
For example: storage 7000 till 7200, if someone has storage 7002, 7030, 7050, 7160, 7195, the npc will see that the player has done 5 quests.

Rep +
 
Thanks, I made it now like this. but it doesn't use the part, like it isn't in the script. So I'm probable doing something wrong :p

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid)			end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid)			end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg)		end
function onThink()					npcHandler:onThink()					end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		selfSay('Oh, did you do your missions?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
            if(getPlayerLevel(cid) >= 30) then
		local number=0
		for i=7000, 7200 do
		if(getPlayerStorageValue(cid, i)>1) then
		number=number+1
		end
		end
                npcHandler:say("Nice.", cid)
                doPlayerAddExp(cid, 5000)
		else
			selfSay('You have to be level 30.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Then not!', cid)
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Thought of that too, but still same problem. I think I have to make a cancel part somewhere for the storage too, but it doesn't allow me to do it in the normal way.
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		selfSay('Oh, did you do your missions?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerLevel(cid) >= 30) then
			local number=0
			for i=7000, 7200 do
				if(getPlayerStorageValue(cid, i)>0) then
				number=number+1
				end
			end
			
			npcHandler:say("Nice.", cid)
			doPlayerAddExp(cid, 5000)
		else
		
		selfSay('You have to be level 30.', cid)
		end
		talkState[talkUser] = 0
		
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Then not!', cid)
	end
 
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Try it, tell me back exactly what the npc does, and what you did.
 
Thanks for your reply. but I already tried the way you did it. I will try to explain.
There are 200 quests with storage 7000 till 7200. If a player has done 5 of the quests, doesn't matter which one, he can go to the npc (who checks if the player has 5 of those 200 storages) and the player will get 5000 exp. Of course someone can only do this once, but I can add that myself later.
The problem is that the script doesn't look at the parts that checks the storage, it just skips it, like it isn't in the script. No mather what kind of storage I use I always get the exp and the npc message "nice".
 
Oh no, just for 5 quest someone will get 5000 exp. If someone did 4 quests, then he gets nothing, if he done 6, then he will also get 5000 exp, just if someone has done at least 5 quests.
 
No the storages will stay. Only difference from a normal storage script is that it has to check the amount of storages between 7000 and 7200, instead of just 1. After someone get the exp its just done. He can't get the exp again, but I can add this part myself.
 
Try this:

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg) end
function onThink()					npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	lvl,stor,n = 30,9745474,0
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) then
		selfSay('Oh, did you do your missions?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerLevel(cid) >= lvl) then
		if getPlayerStorageValue(cid, stor) == -1 then setPlayerStorageValue(cid, stor, 0) end
		for i= 7000,7200 do
		if getPlayerStorageValue(cid, i) >= 1 then 
		n = n+1
		end
		end
		if n >= (getPlayerStorageValue(cid, stor)+5) then
			npcHandler:say("Nice.", cid)
			doPlayerAddExp(cid, 5000)
			setPlayerStorageValue(cid, stor, getPlayerStorageValue(cid, stor)+5)
			talkState[talkUser] = 0
		else
		selfSay('you must finish at least 5 quest.', cid)
		end
		else
		selfSay('You have to be level '..lvl, cid)
		end
	elseif (msgcontains(msg, 'no') and talkState[talkUser] >= 1) then
		talkState[talkUser] = 0
		selfSay('Then not!', cid)
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Hey, if you were to modify the script posted above to change the cid of the quest (for quest chains), how would you do it? Nice script btw :)
 
Back
Top