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

Modifying this NPC script to only respond for certain levels.

Status
Not open for further replies.

Vikarious

New Member
Joined
Dec 16, 2008
Messages
93
Reaction score
2
I wish to make this script, but adding a form that the NPC will check level, and if its under allowed level, NPC will send normla msg, if player is under level, then NPC will say "I'm only recruiting players from level 10 to 15 to this task, come back after..."

and if player is above allowed level, then NPC should display a message like this:

"You are above level 15 maybe you got more importants things to do"

Or similar. This part is important. and I really need it,

And in a secondary form I would like that when player receive experience, appear in red letters in screen or in default channel, (is the same), "You received 100 experience points."


The secondary part only if its possible, but about levels I really need it...

Here follow the scripts:

PD: The storage values are set in a form the quest can be done so many times as player want, so it is not a mistake it were done intentionally.


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 tokenid = 2676
local storage = 5819
local getstorage = getPlayerStorageValue(cid, storage)
local sorrymessage = "Sorry, you don't have enough to share..."
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, 'task') then
if getstorage == 3 then
npcHandler:say("Im not hungry anymore.", cid)
elseif getstorage < 3 then
npcHandler:say("Make days I don't eat nothing, could you bring me like five bananas? I will return you 100 experience points.", cid)
talkState[talkUser] = 1
end
elseif msgcontains(msg, 'yes') then
if talkState[talkUser] == 1 then
setPlayerStorageValue(cid, storage, 1)
if getstorage == 1 then
if doPlayerRemoveItem(cid, tokenid, 5) == TRUE then
setPlayerStorageValue(cid, storage, 2)
doPlayerAddExp(cid, 100)
npcHandler:say("Here you have, 100 experience points. Thank you.", cid)
setPlayerStorageValue(cid, storage, 1)
talkState[talkUser] = 0
elseif doPlayerRemoveItem(cid, tokenid, 5) == FALSE then
npcHandler:say(sorrymessage, cid)
talkState[talkUser] = 0
end
end
end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
npcHandler:say("Ok than.", cid)
talkState[talkUser] = 0
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Really hope some help, rep++ for sure!!
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState = {}
local tokenid = 2676
local sorrymessage = "Sorry, you don't have enough to share..."
local levelRange = {10, 15}

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 greetCallback(cid)
	if getPlayerLevel(cid) < levelRange[1] then
		npcHandler:say("I'm only recruiting players from level 10 to 15 to this task, come back after...", cid, TRUE)
	elseif getPlayerLevel(cid) > levelRange[2] then
		npcHandler:say("You are above level 15 maybe you got more importants things to do" , cid, TRUE)
	else
		local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
		talkState[talkUser] = 0
		return true
	end
	return false
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, 'task') then
		local getstorage = getPlayerStorageValue(cid, storage)
		if getstorage == 3 then
			npcHandler:say("I'm not hungry anymore.", cid)
			talkState[talkUser] = 0
		elseif getstorage < 3 then
			npcHandler:say("Make days I don't eat nothing, could you bring me like five bananas? I will give you 100 experience points in return.", cid)
			talkState[talkUser] = 1
		end
	elseif talkState[talkUser] == 1 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, tokenid, 5) == TRUE then
				doPlayerAddExp(cid, 100)
				doSendAnimatedText(getCreaturePosition(cid), "100", TEXTCOLOR_WHITE_EXP)
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You received 100 experience points.")
				npcHandler:say("Here you have, 100 experience points. Thank you.", cid)
			else
				npcHandler:say(sorrymessage, cid)
			end
		else
			npcHandler:say("Ok then.", cid)
		end
		talkState[talkUser] = 0
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
It works perfectly when player is above or under allowed level, but when players is have the allowd level, npc just dont react, and in TFS console I receive this message:

[17/11/2009 20:24:30] Lua Script Error: [Npc interface]
[17/11/2009 20:24:30] data/npc/scripts/testandoquest.lua:eek:nCreatureSay

[17/11/2009 20:24:30] data/npc/scripts/testandoquest.lua:1: attempt to index global 'Topic' (a nil value)
[17/11/2009 20:24:30] stack traceback:
[17/11/2009 20:24:30] data/npc/scripts/testandoquest.lua:1: in function 'callback'
[17/11/2009 20:24:30] data/npc/lib/npcsystem/npchandler.lua:333: in function 'greet'
[17/11/2009 20:24:30] data/npc/lib/npcsystem/npchandler.lua:499: in function 'onGreet'
[17/11/2009 20:24:30] data/npc/lib/npcsystem/modules.lua:224: in function 'callback'
[17/11/2009 20:24:30] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[17/11/2009 20:24:30] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[17/11/2009 20:24:30] data/npc/lib/npcsystem/keywordhandler.lua:128: in function 'processMessage'
[17/11/2009 20:24:30] data/npc/lib/npcsystem/npchandler.lua:380: in function 'onCreatureSay'
[17/11/2009 20:24:30] data/npc/scripts/testandoquest.lua:1: in function <data/npc/scripts/testandoquest.lua:1>



My TFS version is 0.3.5 Crying Damson.

Can you help me please?
 
sorry bro', isn't working I dont know why.

When I ask for the task, npc shows message and then if I say 'no' npc send message and end conversation, but if I say 'yes' npc dont react, even if I have or not have the 5 bananas, it just stay stucked... I'm trying to fix but I really dont know nothing about programming =/

Hope you even have a little of patience to help me with this...

Thanks for all your attention =)

----------------

Edit:

I made some modifications in the script and it worked, but now NPC olny check if player have right level when you ask for task (I use <parameters> in the .xml of this npc for greet message), so first he will ask you for make a task and then, when you say 'task' NPC say if you have or not the right level, and npc dont finish conversation when you say 'no' or when you have not enough items for the quest, You must say "bye"

How I said I don't understand much of scripting, so, If it is possible to introduce that functions, I would be very glad =)

Thanks once and again =)

The script modified:

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 tokenid = 2676
local storage = 5819
local getstorage = getPlayerStorageValue(cid, storage)
local sorrymessage = "Sorry, you don't have enough to share..."
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local levelRange = {10, 15}
if getPlayerLevel(cid) < levelRange[1] then
		npcHandler:say("I'm only recruiting players from level 10 to 15 to this task, come back after...", cid, TRUE)
	elseif getPlayerLevel(cid) > levelRange[2] then
		npcHandler:say("You are above level 15 maybe you got more importants things to do" , cid, TRUE)
	return false	
	end
if msgcontains(msg, 'task') then
if getstorage == 3 then
npcHandler:say("Im not hungry anymore.", cid)
elseif getstorage < 3 then
npcHandler:say("Make days I don't eat nothing, could you bring me like five bananas? I will return you 100 experience points.", cid)
talkState[talkUser] = 1
end
elseif msgcontains(msg, 'yes') then
if talkState[talkUser] == 1 then
setPlayerStorageValue(cid, storage, 1)
if getstorage == 1 then
if doPlayerRemoveItem(cid, tokenid, 5) == TRUE then
setPlayerStorageValue(cid, storage, 2)
					doPlayerAddExp(cid, 100)
					doSendAnimatedText(getCreaturePosition(cid), "+100", TEXTCOLOR_WHITE)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You received 100 experience points.")
doPlayerAddExp(cid, 100)
npcHandler:say("Here you have, 100 experience points. Thank you.", cid)
setPlayerStorageValue(cid, storage, 1)
talkState[talkUser] = 0
elseif doPlayerRemoveItem(cid, tokenid, 5) == FALSE then
npcHandler:say(sorrymessage, cid)
talkState[talkUser] = 0
end
end
end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
npcHandler:say("Ok than.", cid)
talkState[talkUser] = 0
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
It's your fault, because you modified the script to work like that. I've removed the storage part, it should work now.
 
Status
Not open for further replies.
Back
Top