• 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 NPC Quickfix

Ward_214

Pro PvP
Joined
Dec 11, 2008
Messages
297
Reaction score
0
Okay...

Im getting this error in the console
Code:
 [31/07/2011 05:17:46] [Error - LuaScriptInterface::loadFile] data/npc/scripts/donors1.lua:40: '<eof>' expected near 'npcHandler'
[31/07/2011 05:17:46] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/donors1.lua


This is the script:
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
 
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. I buy Kiwi tokens for donator items! I can sell you a {Crusader Armor}.") 
 
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, 'crusader armor') or msgcontains(msg, 'crus armor')) then
		selfSay('Do you want to buy a Crusader Armor for 2 Kiwi tokens?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if doPlayerRemoveItem(cid, 6527, 2) == true then				doPlayerAddItem(cid, 2053, 1)
				selfSay('Here you are.', cid)
			else
	end
		else
			selfSay('Sorry, you don\'t have enough Kiwi Tokens.', cid)
			end
		end
		talkState[talkUser] = 0
	if(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end
 
	return true
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
you have an end out of place, remove the end thats below
Code:
selfSay('Sorry, you don\'t have enough Kiwi Tokens.', cid)
and add another one after return true

Should work :)
 
It does work!

Now this happens:
Code:
Admin: buy crusader armor
Elynir Donator Seller: Do you want to buy a Crusader Armor for 2 Kiwi tokens?
Admin: yes
Elynir Donator Seller: Sorry, you don't have enough Kiwi Tokens.


I do have the tokens on me!!
 
ur script was all messy, so ur elses were all swapped, this should work :)

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
 
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. I buy Kiwi tokens for donator items! I can sell you a {Crusader Armor}.") 
 
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, 'crusader armor') or msgcontains(msg, 'crus armor')) then
        selfSay('Do you want to buy a Crusader Armor for 2 Kiwi tokens?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if doPlayerRemoveItem(cid, 6527, 2) == true then
                doPlayerAddItem(cid, 2053, 1)
                selfSay('Here you are.', cid)
        else
            selfSay('Sorry, you don\'t have enough Kiwi Tokens.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Hahaha yeah, I took a script that I found on here.. And wrote from knowledge that I knew about LUA.. Im definitely not a pro. so THANK YOU!
 
Back
Top