• 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!

TFS 1.X+ BUG ON NPC

Igor Milagres

Member
Joined
May 12, 2018
Messages
72
Reaction score
20
Good night, I have the following error in my npc that sells bps of runes, already tried but does not solve, the following error appears in the logs: If anyone knows what to do, it would help a lot, thank you. Attach the script

[Error - LuaInterface :: loadFile] data / npc / scripts / runenpc.lua: 194: 'end' expected (to close 'if' at line 161) near ''
[Warning - NpcEvents :: NpcEvents] Can not load script: data / npc / scripts / runenpc.lua
data / npc / scripts / runenpc.lua: 194: 'end' expected (to close 'if' at line 161) near ''


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

-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
-- OTServ event handling functions end

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

if msgcontains(msg, 'bp of ultimate healing') then
npcHandler:say('Do you want to buy a backpack of ultimate healing rune for 3000 gold coins?')
talk_state = 1

elseif msgcontains(msg, 'yes') and talk_state == 1 then
if getPlayerMoney(cid) >= 3000 then
blue_bp = doPlayerAddItem(cid, 2002, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doAddContainerItem(blue_bp, 2273, 1)
doPlayerRemoveMoney(cid, 3000)
npcHandler:say('Thank you for buying.')
talk_state = 0
else
npcHandler:say('You don\'t have enough money.')
talk_state = 0
end
end

if msgcontains(msg, 'bp of sudden death') then
npcHandler:say('Do you want to buy a backpack of sudden death rune for 6000 gold coins?')
talk_state = 2

elseif msgcontains(msg, 'yes') and talk_state == 2 then
if getPlayerMoney(cid) >= 5500 then
grey_bp = doPlayerAddItem(cid, 2003, 1)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doAddContainerItem(grey_bp, 2268, 3)
doPlayerRemoveMoney(cid, 5500)
npcHandler:say('Thank you for buying.')
talk_state = 0
else
npcHandler:say('You don\'t have enough money.')
talk_state = 0
end
end

if msgcontains(msg, 'bp of heavy magic missile') then
npcHandler:say('Do you want to buy a backpack of heavy magic missile rune for 2000 gold coins?')
talk_state = 3

elseif msgcontains(msg, 'yes') and talk_state == 3 then
if getPlayerMoney(cid) >= 2000 then
purple1_bp = doPlayerAddItem(cid, 2001, 1)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doAddContainerItem(purple1_bp, 2311, 5)
doPlayerRemoveMoney(cid, 2000)
npcHandler:say('Thank you for buying.')
talk_state = 0
else
npcHandler:say('You don\'t have enough money.')
talk_state = 0
end
end

if msgcontains(msg, 'bp of great fireball') then
npcHandler:say('Do you want to buy a backpack of great fireball rune for 3000 gold coins?')
talk_state = 4

elseif msgcontains(msg, 'yes') and talk_state == 4 then
if getPlayerMoney(cid) >= 3000 then
red_bp = doPlayerAddItem(cid, 2000, 1)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doAddContainerItem(red_bp, 2304, 4)
doPlayerRemoveMoney(cid, 3000)
npcHandler:say('Thank you for buying.')
talk_state = 0
else
npcHandler:say('You don\'t have enough money.')
talk_state = 0
end
end

if msgcontains(msg, 'bp of explosion') or msgcontains(msg, 'bp of explo') then
npcHandler:say('Do you want to buy a backpack of explosion rune for 4000 gold coins?')
talk_state = 5

elseif msgcontains(msg, 'yes') and talk_state == 5 then
if getPlayerMoney(cid) >= 4000 then
purple2_bp = doPlayerAddItem(cid, 2001, 1)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doAddContainerItem(purple2_bp, 2313, 3)
doPlayerRemoveMoney(cid, 4000)
npcHandler:say('Thank you for buying.')
talk_state = 0
else
npcHandler:say('You don\'t have enough money.')
talk_state = 0
end
 
Simplify
Lua:
function sendItemToInventory(func, amount, ...)
    for i = 1, amount or 20 do
        func(...)
    end
end

sendItemToInventory(doAddContainerItem, 20, blue_bp, 2273, 1)
 
pretty sure u are only missing an "end" at the end of your script, but yeah format your shit or noone will really want to help you
 
You were missing 2 (ends) to the function and the if statement

I really recommend using a table than this hard-coded function.
THERE are TONS of tutorials on lua either on OTLand or lua-users. Check them and start digging! Cheers!
 

Attachments

Back
Top