• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua could someone look this over i cannot understand the error im sure it's simple

Jknot

Member
Joined
Feb 18, 2008
Messages
170
Solutions
1
Reaction score
13
Location
South Carolina
Blacksmith2.lua:25: unexpected symbol near 'if'
Blacksmith2.lua:59: 'end' expected (to close 'if' at line 37) near '<eof>'

these are the errors it's throwing
LUA:
 -- Scripted by Jknot --

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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

item = 'this must be a scamm.'
done = 'This turned out perfect enjoy your item.'

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
        if msgcontains(msg, 'job') then
        selfSay('I Exchange items for powerful equipment.', cid)
         -----------items to be checked---------------
            elseif msgcontains(msg, 'relic sword') then
            if getPlayerItemCount(cid,6527) >= 10 then
            if getPlayerItemCount(cid,2160) >= 100 then
            if getPlayerItemCount(cid,2152) >= 60 then
                selfSay('Did you bring me the required items?', cid)
                talk_state = 1
            else
                selfSay('You do not have the required items.', cid)
                talk_state = 0
            end

            elseif msgcontains(msg, 'yes') and talk_state == 1 then
            talk_state = 0
            ---------items to be checked---------
            if getPlayerItemCount(cid,6527) >= 10 then
            if getPlayerItemCount(cid,2160) >= 100 then
            if getPlayerItemCount(cid,2152) >= 60 then
                -------items to be removed-------
            if doPlayerRemoveItem(cid,6527, 10) == TRUE then
            if doPlayerRemoveItem(cid,2160, 100) == TRUE then
            if doPlayerRemoveItem(cid,2152, 60) == TRUE then
                            selfSay(done, cid)
          --------items to be added to player------
            doPlayerAddItem(cid, 7383, 1)
            end
            
            else
                selfSay(item, cid)
            end
            
            elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Another time then.')
            talk_state = 0
        end
  
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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


local talk_state = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

        --chat--
    if msgcontains(msg, 'job') then
        selfSay('I exchange items for powerful equipment. Tell me if you want a {relic sword}.', cid)
        talk_state[talkUser] = 0

        --item check--
    elseif msgcontains(msg, 'relic sword') then
        -- We check if they have the items before proceeding
        if getPlayerItemCount(cid, 6527) >= 10 and getPlayerItemCount(cid, 2160) >= 100 and getPlayerItemCount(cid, 2152) >= 60 then
            selfSay('Did you bring me the 10 Valaxians Tokens, 100 crystal coins, and 60 platinum coins?', cid)
            talk_state[talkUser] = 1
        else
            selfSay('You do not have the required items for this trade {10 Valaxians Tokens} {100 Crystal Coins} and{60 Platinum Coins}This seems like a scam.', cid)
            talk_state[talkUser] = 0
        end

        --item-confirmation--
    elseif msgcontains(msg, 'yes') and talk_state[talkUser] == 1 then
        --check-befor-remove--
        if getPlayerItemCount(cid, 6527) >= 10 and getPlayerItemCount(cid, 2160) >= 100 and getPlayerItemCount(cid, 2152) >= 60 then
            doPlayerRemoveItem(cid, 6527, 10)
            doPlayerRemoveItem(cid, 2160, 100)
            doPlayerRemoveItem(cid, 2152, 60)
            
            doPlayerAddItem(cid, 7383, 1)
            selfSay('This turned out perfect! Enjoy your Relic Sword.', cid)
        else
            selfSay('You seem to have forgotten the items i asked for since we last spoke.', cid)
        end
        talk_state[talkUser] = 0

        --player-refuses--
    elseif msgcontains(msg, 'no') and talk_state[talkUser] == 1 then
        selfSay('Another time then.', cid)
        talk_state[talkUser] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

Blacksmith2.lua:25: unexpected symbol near 'if'
Blacksmith2.lua:59: 'end' expected (to close 'if' at line 37) near '<eof>'

these are the errors it's throwing
LUA:
 -- Scripted by Jknot --

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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

item = 'this must be a scamm.'
done = 'This turned out perfect enjoy your item.'

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
   
        if msgcontains(msg, 'job') then
        selfSay('I Exchange items for powerful equipment.', cid)
         -----------items to be checked---------------
            elseif msgcontains(msg, 'relic sword') then
            if getPlayerItemCount(cid,6527) >= 10 then
            if getPlayerItemCount(cid,2160) >= 100 then
            if getPlayerItemCount(cid,2152) >= 60 then
                selfSay('Did you bring me the required items?', cid)
                talk_state = 1
            else
                selfSay('You do not have the required items.', cid)
                talk_state = 0
            end

            elseif msgcontains(msg, 'yes') and talk_state == 1 then
            talk_state = 0
            ---------items to be checked---------
            if getPlayerItemCount(cid,6527) >= 10 then
            if getPlayerItemCount(cid,2160) >= 100 then
            if getPlayerItemCount(cid,2152) >= 60 then
                -------items to be removed-------
            if doPlayerRemoveItem(cid,6527, 10) == TRUE then
            if doPlayerRemoveItem(cid,2160, 100) == TRUE then
            if doPlayerRemoveItem(cid,2152, 60) == TRUE then
                            selfSay(done, cid)
          --------items to be added to player------
            doPlayerAddItem(cid, 7383, 1)
            end
           
            else
                selfSay(item, cid)
            end
           
            elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Another time then.')
            talk_state = 0
        end
 
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Post automatically merged:

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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


local talk_state = {}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local talkUser = cid

        --chat--
    if msgcontains(msg, 'job') then
        selfSay('I exchange items for powerful equipment. Tell me if you want a {relic sword}.', cid)
        talk_state[talkUser] = 0

        --item check--
    elseif msgcontains(msg, 'relic sword') then
        -- We check if they have the items before proceeding
        if getPlayerItemCount(cid, 6527) >= 10 and getPlayerItemCount(cid, 2160) >= 100 and getPlayerItemCount(cid, 2152) >= 60 then
            selfSay('Did you bring me the 10 Valaxians Tokens, 100 crystal coins, and 60 platinum coins?', cid)
            talk_state[talkUser] = 1
        else
            selfSay('You do not have the required items for this trade {10 Valaxians Tokens} {100 Crystal Coins} and{60 Platinum Coins}This seems like a scam.', cid)
            talk_state[talkUser] = 0
        end

        --item-confirmation--
    elseif msgcontains(msg, 'yes') and talk_state[talkUser] == 1 then
        --check-befor-remove--
        if getPlayerItemCount(cid, 6527) >= 10 and getPlayerItemCount(cid, 2160) >= 100 and getPlayerItemCount(cid, 2152) >= 60 then
            doPlayerRemoveItem(cid, 6527, 10)
            doPlayerRemoveItem(cid, 2160, 100)
            doPlayerRemoveItem(cid, 2152, 60)
           
            doPlayerAddItem(cid, 7383, 1)
            selfSay('This turned out perfect! Enjoy your Relic Sword.', cid)
        else
            selfSay('You seem to have forgotten the items i asked for since we last spoke.', cid)
        end
        talk_state[talkUser] = 0

        --player-refuses--
    elseif msgcontains(msg, 'no') and talk_state[talkUser] == 1 then
        selfSay('Another time then.', cid)
        talk_state[talkUser] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
the second code is the correct solution sorry to repost on my own post guys
 
Last edited:
Learn to tabulate your code. It will make errors such as missing close brackets/ends more obvious, and just makes the overall readability of the script much cleaner.

Personally, I ignore all requests of code that is messy/not tabulated. There are programs/IDE's that even do it for you these days, so there is no excuse.
 
Back
Top