• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC [help] me please with my NPC script

kaspertje100

Member
Joined
May 8, 2008
Messages
236
Reaction score
7
Hi peeps,

I would like to ask you a favor!

So I get this error msg in my console: (using TFS 0.3.6)


Code:
[Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/Fly.lua
data/npc/scripts/Fly.lua:29: unexpected symbol near 'if'

and using this 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, 'fly')) then
		selfSay('Do you want to learn to fly for 10000 gold coins?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if getPlayerStorageValue(uid, 10201) == -1 then
			if(doPlayerRemoveMoney(cid, 10000)) then
				setPlayerStorageValue(cid, 102015,1)
				selfSay('You can now fly.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		elseif if getPlayerStorageValue(uid, 10201) == -1)) then
			if(doPlayerRemoveMoney(cid, 10000)) then
				setPlayerStorageValue(cid, 102015,1)
				selfSay('You can now fly.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you aren\'t vip.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

To explain a lil more:

This script should make a person able to use flying system, the storage of flying system = 102015. But the npc should check if the player is VIP and have 10000 gold coins. Well golds coins I won't have to explain xD but ehm the storage ID of VIP == 10201.

IF someone could help I would be really pleased!

Yours,
Kasper
 
Code:
    elseif if getPlayerStorageValue(uid, 10201) == -1)) then
change it to:
Code:
    elseif getPlayerStorageValue(uid, 10201) == -1 then
 
[Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/Fly.lua
data/npc/scripts/Fly.lua:29: unexpected symbol near 'if'

Are u fucking kidding me?
U really don't understand this error? u have somethink near if in line 29. -.-
 
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, 'fly') then
		selfSay('Do you want to learn to fly for 10000 gold coins?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if getPlayerStorageValue(uid, 10201) == -1 then
			if(doPlayerRemoveMoney(cid, 10000)) then
				setPlayerStorageValue(cid, 102015,1)
				selfSay('You can now fly.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		elseif if getPlayerStorageValue(uid, 10201) == -1 then
			if(doPlayerRemoveMoney(cid, 10000) then
				setPlayerStorageValue(cid, 102015,1)
				selfSay('You can now fly.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you aren\'t vip.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top