• 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 Little error

azzkaban

Monster Maker
Joined
Feb 23, 2010
Messages
1,101
Reaction score
194
Location
Iquique Chile
Hi, can you help me?

Error:
Code:
[14/12/2013 19:9:49] [Error - LuaInterface::loadFile] data/npc/scripts/Travel NPC/Ledtheron.lua:21: 'end' expected (to close 'function' at line 11) near 'elseif'
[14/12/2013 19:9:49] [Warning - NpcEvents::NpcEvents] Cannot load script: data/npc/scripts/Travel NPC/Ledtheron.lua
[14/12/2013 19:9:49] data/npc/scripts/Travel NPC/Ledtheron.lua:21: 'end' expected (to close 'function' at line 11) near 'elseif'

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
local city = {{x=100,y=100,z=7},"Thais",50}
if(msgcontains(msg, city[2])) then
selfSay('Do you want to travel to '..k..' for '..v.cost..' gold coins?', cid)
talkState[talkUser] = v.talk
end
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == v.talk) then
if hasCondition(cid, CONDITION_INFIGHT) then
if getPlayerPremiumDays(cid) > 0 then
if(doPlayerRemoveMoney(cid, city[3]) == TRUE) then
doTeleportThing(cid, city[1], FALSE)
selfSay('Traveled to '..city[2] ..'.', cid)
else
selfSay('Sorry, you don\'t have enough gold coins.', cid)
end
else
selfSay("Sorry, you need premium.",cid)
talkState[talkUser] = 0
end
else
selfSay("Sorry, you have pz!",cid)
talkState[talkUser] = 0
end
elseif(msgcontains(msg, 'no') and isInArray({v.talk}, talkState[talkUser]) == TRUE) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
end

return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Here you go, next time tab the script, its difficult to read it.
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
    local city = {{x=100,y=100,z=7},"Thais",50}
    if(msgcontains(msg, city[2])) then
        selfSay('Do you want to travel to '..k..' for '..v.cost..' gold coins?', cid)
        talkState[talkUser] = v.talk
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == v.talk) then
    if hasCondition(cid, CONDITION_INFIGHT) then
        if getPlayerPremiumDays(cid) > 0 then
            if(doPlayerRemoveMoney(cid, city[3]) == TRUE) then
                doTeleportThing(cid, city[1], FALSE)
                selfSay('Traveled to '..city[2] ..'.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold coins.', cid)
            end
        else
            selfSay("Sorry, you need premium.",cid)
            talkState[talkUser] = 0
        end
    else
        selfSay("Sorry, you have pz!",cid)
        talkState[talkUser] = 0
    end
    elseif(msgcontains(msg, 'no') and isInArray({v.talk}, 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())
 
Thank you! But:

Code:
[15/12/2013 13:58:35] [Error - NpcScript Interface]
[15/12/2013 13:58:35] data/npc/scripts/Travel NPC/Ledtheron.lua:onCreatureSay
[15/12/2013 13:58:35] Description:
[15/12/2013 13:58:35] data/npc/scripts/Travel NPC/Ledtheron.lua:18: attempt to index global 'v' (a nil value)
[15/12/2013 13:58:35] stack traceback:
[15/12/2013 13:58:35]    data/npc/scripts/Travel NPC/Ledtheron.lua:18: in function 'callback'
[15/12/2013 13:58:35]    data/npc/lib/npcsystem/npchandler.lua:456: in function 'onCreatureSay'
[15/12/2013 13:58:35]    data/npc/scripts/Travel NPC/Ledtheron.lua:8: in function <data/npc/scripts/Travel NPC/Ledtheron.lua:8>
 
Here you go:
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, "Thais") then
            selfSay('Do you want to travel to Thais for 50 gold coins?', cid)
            talkState[talkUser] = 1
        elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
            if hasCondition(cid, CONDITION_INFIGHT) then
                if getPlayerPremiumDays(cid) > 0 then
                        if doPlayerRemoveMoney(cid, 50) == TRUE then
                            doTeleportThing(cid, {x=100,y=100,z=7}, FALSE)
                            selfSay('Traveled to Thais.', cid)
                    talkState[talkUser] = 0
                        else
                            selfSay('Sorry, you don\'t have enough gold coins.', cid)
                        end
                else
                        selfSay("Sorry, you need premium.",cid)
                        talkState[talkUser] = 0
                end
            else
                selfSay("Sorry, you have pz!",cid)
                talkState[talkUser] = 0
            end
        elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
            talkState[talkUser] = 0
            selfSay('Ok then.', cid)
        end
        return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Thank you! NPC work but he reply :
Sorry, you have pz!

I was in protetion zone and NPC say:
Sorry, you have pz!

I test without gold coins and same:
Sorry, you have pz!

 
Back
Top