• 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] with NPC

Mooosie

- Lua Scripter -
Joined
Aug 2, 2008
Messages
702
Reaction score
27
Location
Sweden
Whats wrong with this NPC?
look i want this:
if a player is level 8 with any voc, then his voc will be changed to another. and he gets items. If the player is coming back without level 20. he will say, come back when you are level 20. when he is level 20, he will get experience, and he cant do the quest again...

Here is the script:
Code:
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, 'voc') or msgcontains(msg, 'vocation')) then
		selfSay('Your First step, you will be trained as an archer {Paladin}', cid)
		talkState[talkUser] = 1
	localstrv = getPlayerStorageValue(cid, 21931)
	elseif(msgcontains(msg, 'paladin') and talkState[talkUser] == 1) then
			if getPlayerLevel(cid) <= 8 and localstrv == -1 then
				doPlayerSetVocation(cid, 3)
				doPlayerAddItem(cid, 2456, 1)
				doPlayerAddItem(cid, 2544, 100)
				doPlayerAddItem(cid, 2389, 20)
				doPlayerSetStorageValue(cid, 21931, 1)
				selfSay('Here are you\'r items to survive.',cid)
				else
				selfSay('Come back when you are level 20.',cid)
				end
	localstrv2 = getPlayerStorageValue(cid, 21932)
	elseif getPlayerLevel(cid, 20) >= 1 and localstrv2 == -1 then
				doPlayerAddExp(cid, 2000)
				doPlayerSetStorageValue(cid, 21591, 1)
				selfSay('Congratz, you can now go straight to the door to continue the quest.',cid)
				else
				selfSay('Cannot do this quest again!', cid)
				end
			end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		end
	end
end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Any erros in console?

// edit

Try this:
Code:
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, 'voc') or msgcontains(msg, 'vocation')) then
		selfSay('Your First step, you will be trained as an archer {Paladin}', cid)
		talkState[talkUser] = 1
	localstrv = getPlayerStorageValue(cid, 21931)
	elseif(msgcontains(msg, 'paladin') and talkState[talkUser] == 1) then
			if getPlayerLevel(cid) <= 8 and localstrv == -1 then
				doPlayerSetVocation(cid, 3)
				doPlayerAddItem(cid, 2456, 1)
				doPlayerAddItem(cid, 2544, 100)
				doPlayerAddItem(cid, 2389, 20)
				doPlayerSetStorageValue(cid, 21931, 1)
				selfSay('Here are you\'r items to survive.',cid)
				else
				selfSay('Come back when you are level 20.',cid)
				end
	localstrv2 = getPlayerStorageValue(cid, 21932)
	elseif getPlayerLevel(cid) >= 20 and localstrv2 == -1 then
				doPlayerAddExp(cid, 2000)
				doPlayerSetStorageValue(cid, 21591, 1)
				selfSay('Congratz, you can now go straight to the door to continue the quest.',cid)
				else
				selfSay('Cannot do this quest again!', cid)
				end
			end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
		end
	end
end
 
Last edited:
Your Script Error:
Code:
[15/03/2011 19:34:53] [Error - LuaScriptInterface::loadFile] data/npc/scripts/paladi.lua:43: '<eof>' expected near 'elseif'
[15/03/2011 19:34:53] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/paladi.lua
[15/03/2011 19:34:53] data/npc/scripts/paladi.lua:43: '<eof>' expected near 'elseif'
 
Back
Top