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

Need help with NPC script (tfs 0.2.15)

ibkfly

New Member
Joined
Jan 1, 2010
Messages
69
Reaction score
4
Hey, so ive made an NPC that trades 1000 cyan crystal fragments for an Armor set, i.e. Paladin Set, Knight Set or Mage Set.

I don't get any errors when running tfs or anything but the NPC just doesn't appear on the map after i put him there on RME. Ive tried several places to place him but he just isnt there.

Ill post the xml and lua so you guys can see if there is any error.

barzo.xml:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="[Cyan Crystal Merchant]Barzo" script="data/npc/scripts/cyancrystalmerchant.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="145" addons="3" head="67" body="34" legs="67" feet="34" corpse="2317"/>
<parameters>
<parameter key="message_greet" value="Hello, I'm trading your cyan fragments for vocation armor sets, Do you want to trade?"/>
</parameters>
</npc>

cyancrystalmerchant.lua:

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

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

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, 'paladin set')) then
selfSay('Do you want to give me 1000 cyan fragments for an abyss armor set for paladins?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 18419) >= 1000) then
if(doPlayerRemoveItem(cid, 18419, 1000)) then
doPlayerAddItem(cid, 11301, 1)
doPlayerAddItem(cid, 11302, 1)
doPlayerAddItem(cid, 11303, 1)
doPlayerAddItem(cid, 11304, 1)
selfSay('Here you are.', cid)
else
selfSay('Sorry, you don\'t have enough cyan fragments.', cid)
end
else
selfSay('Sorry, you don\'t have cyan fragments.', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end

if(msgcontains(msg, 'mage set')) then
selfSay('Do you want to give me 1000 cyan fragments for an abyss armor set for magicians?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 18419) >= 1000) then
if(doPlayerRemoveItem(cid, 18419, 1000)) then
doPlayerAddItem(cid, 7902, 1)
doPlayerAddItem(cid, 7892, 1)
doPlayerAddItem(cid, 7896, 1)
doPlayerAddItem(cid, 7897, 1)
selfSay('Here you are.', cid)
else
selfSay('Sorry, you don\'t have enough cyan fragments.', cid)
end
else
selfSay('Sorry, you don\'t have cyan fragments.', 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

if(msgcontains(msg, 'knight set')) then
selfSay('Do you want to give me 1000 cyan fragments for an abyss armor set for knights?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 18419) >= 1000) then
if(doPlayerRemoveItem(cid, 18419, 1000)) then
doPlayerAddItem(cid, 2342, 1)
doPlayerAddItem(cid, 9776, 1)
doPlayerAddItem(cid, 9777, 1)
doPlayerAddItem(cid, 12646, 1)
selfSay('Here you are.', cid)
else
selfSay('Sorry, you don\'t have enough cyan fragments.', cid)
end
else
selfSay('Sorry, you don\'t have cyan fragments.', 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

I hope someone will be able to help me:)
 
I get error in console when i summon the NPC, it says
could not load script data/npc/scripts/cyancrystalmerchant.lua:6: function arguments expected near ':'
 

Attachments

/sigh

Read the error message you posted.

Line 1 tells you why the NPC isn't spawning.
Line 2 tells you where to look for the problem.
 
try this one

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, "paladin set")) then
        npcHandler:say("Do you want to give me 1000 cyan fragments for an abyss armor set for paladins?", cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, "knight set")) then
        npcHandler:say("Do you want to give me 1000 cyan fragments for an abyss armor set for knights?", cid)
        talkState[talkUser] = 2
    elseif(msgcontains(msg, "mage set")) then
        npcHandler:say("Do you want to give me 1000 cyan fragments for an abyss armor set for magicians?", cid)
        talkState[talkUser] = 3
    end
 
    if(msgcontains(msg, 'yes')) then
        if(talkState[talkUser] == 1) then
            if(getPlayerItemCount(cid, 18419) >= 1000) then
                doPlayerRemoveItem(cid, 18419, 1000)
        doPlayerAddItem(cid, 11301, 1)
        doPlayerAddItem(cid, 11302, 1)
        doPlayerAddItem(cid, 11303, 1)
        doPlayerAddItem(cid, 11304, 1)
                npcHandler:say("There you go!", cid)
            else
                npcHandler:say("You dont have enough cyan fragments!", cid)
            end
        elseif(talkState[talkUser] == 2) then
            if(getPlayerItemCount(cid, 18419) >= 1000) then
                doPlayerRemoveItem(cid, 18419, 1000)
        doPlayerAddItem(cid, 2342, 1)
        doPlayerAddItem(cid, 9776, 1)
        doPlayerAddItem(cid, 9777, 1)
        doPlayerAddItem(cid, 12646, 1)
                npcHandler:say("There you go!", cid)
            else
                npcHandler:say("You dont enough cyan fragments!", cid)
            end
    elseif(talkState[talkUser] == 3) then
            if(getPlayerItemCount(cid, 18419) >= 1000) then
                doPlayerRemoveItem(cid, 18419, 1000)
        doPlayerAddItem(cid, 7902, 1)
        doPlayerAddItem(cid, 7892, 1)
        doPlayerAddItem(cid, 7896, 1)
        doPlayerAddItem(cid, 7897, 1)
                npcHandler:say("There you go!", cid)
            else
                npcHandler:say("You dont enough cyan fragments!", cid)
            end                   
        end
     
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no')) then
        if(talkState[talkUser] ~= 0) then
            npcHandler:say("Maybe later?", cid)
        end
     
        talkState[talkUser] = 0
    end
return true
end

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