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

Solved how to put new NPC in game

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,454
Solutions
1
Reaction score
627
Location
Estonia
im using TFS 1.0

I made new NPC "priest2", im using the Elimes's Editor for that.
Attached TFS 1.0 default.lua script to it.

I imported priest2.xml to map > placed it down > started server > ERROR

onCreatureAppear: attepempt to index local 'creature' (a number value)
this is the line it refers to
Code:
    function NpcHandler:onCreatureAppear(creature)
        local cid = creature:getId()

Creature is in game and walks around but seeing him gives errors and trying to talk to him, gives errors.

NPC file tree
3451kc3.jpg
Priest2.XML
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Priest" script="default.lua" walkinterval="2000" speed="100" walkradius="4" floorchange="0">
<health max="100" now="100"/>
<look type="148" head="94" body="0" legs="79" feet="94" addons="1" mount="0"/>
<parameters>
<!--MESSAGES-->
<parameter key="message_greet" value="Greetings, |PLAYERNAME|."/>
<parameter key="message_farewell" value="Good bye, |PLAYERNAME|."/>
<parameter key="message_buy" value="Do you want to buy |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?"/>
<parameter key="message_onbuy" value="Here you are."/>
<parameter key="message_bought" value="Bought |ITEMCOUNT|x |ITEMNAME| for |TOTALCOST| gold."/>
<parameter key="message_sell" value="Do you want to sell |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?"/>
<parameter key="message_onsell" value="Here you are, |TOTALCOST| gold."/>
<parameter key="message_sold" value="Sold |ITEMCOUNT|x |ITEMNAME| for |TOTALCOST| gold."/>
<parameter key="message_missingmoney" value="You don't have enough money."/>
<parameter key="message_needmoney" value="You don't have enough money."/>
<parameter key="message_missingitem" value="You don't have so many."/>
<parameter key="message_needitem" value="You do not have this object."/>
<parameter key="message_needspace" value="You do not have enough capacity."/>
<parameter key="message_needmorespace" value="You do not have enough capacity for all items."/>
<parameter key="message_idletimeout" value="Good bye."/>
<parameter key="message_decline" value="Then not."/>
<parameter key="message_sendtrade" value="Have a look."/>
<parameter key="message_noshop" value="Sorry, I'm not offering anything."/>
<parameter key="message_oncloseshop" value="Thank you, come back whenever you're in need of something else."/>
<parameter key="message_alreadyfocused" value="|PLAYERNAME|, I am already talking to you."/>
<parameter key="message_walkaway_male" value="Good bye."/>
<parameter key="message_walkaway_female" value="Good bye."/>
<!--KEYWORDS-->
<parameter key="module_keywords" value="1"/>
<parameter key="keywords" value="heal"/>
<parameter key="keyword_reply1" value="Let the gods guide you."/>
</parameters>
</npc>
default.lua
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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

npcHandler:addModule(FocusModule:new())
npc.lua
-- Including the Advanced NPC System
dofile('data/npc/lib/npcsystem/npcsystem.lua')

isPlayerPremiumCallback = isPremium

function msgcontains(message, keyword)
local message, keyword = message:lower(), keyword:lower()
if message == keyword then
return true
end

return message:find(keyword) and not message:find('(%w+)' .. keyword)
end

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
local amount, subType, ignoreCap, item = amount or 1, subType or 0, ignoreCap and TRUE or FALSE, 0
ignoreCap = FALSE
if isItemStackable(itemid) then
if(inBackpacks) then
stuff = doCreateItemEx(backpack, 1)
item = doAddContainerItem(stuff, itemid, math.min(100, amount))
else
stuff = doCreateItemEx(itemid, math.min(100, amount))
end
return doPlayerAddItemEx(cid, stuff, ignoreCap) ~= RETURNVALUE_NOERROR and 0 or amount, 0
end

local a = 0
if(inBackpacks) then
local container, b = doCreateItemEx(backpack, 1), 1
for i = 1, amount do
local item = doAddContainerItem(container, itemid, subType)
if(isInArray({(getContainerCapById(backpack) * b), amount}, i) == TRUE) then
if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
b = b - 1 --
break
end
a = i -- a = a + i
if(amount > i) then
container = doCreateItemEx(backpack, 1)
b = b + 1
end
end
end
return a, b
end

for i = 1, amount do -- normal method for non-stackable items
local item = doCreateItemEx(itemid, subType)
if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
break
end
a = i
end
return a, 0
end

local func = function(pars)
if isPlayer(pars.pcid) == TRUE then
doCreatureSay(pars.cid, pars.text, pars.type, false, pars.pcid, getCreaturePosition(pars.cid))
pars.e.done = TRUE
end
end

function doCreatureSayWithDelay(cid, text, type, delay, e, pcid)
if isPlayer(pcid) == TRUE then
e.done = FALSE
e.event = addEvent(func, delay < 1 and 1000 or delay, {cid=cid, text=text, type=type, e=e, pcid=pcid})
end
end

function doPlayerTakeItem(cid, itemid, count)
if getPlayerItemCount(cid,itemid) < count then
return LUA_ERROR
end

while count > 0 do
local tempcount = 0
if isItemStackable(itemid) then
tempcount = math.min (100, count)
else
tempcount = 1
end

local ret = doPlayerRemoveItem(cid, itemid, tempcount)
if ret ~= LUA_ERROR then
count = count - tempcount
else
return LUA_ERROR
end
end

if count ~= 0 then
return LUA_ERROR
end
return LUA_NO_ERROR
end

function doPlayerSellItem(cid, itemid, count, cost)
if doPlayerTakeItem(cid, itemid, count) == LUA_NO_ERROR then
if not doPlayerAddMoney(cid, cost) then
error('Could not add money to ' .. getPlayerName(cid) .. '(' .. cost .. 'gp)')
end
return LUA_NO_ERROR
end
return LUA_ERROR
end

function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
if not doPlayerRemoveMoney(cid, cost) then
return LUA_ERROR
end

for i = 1, count do
local container = doCreateItemEx(containerid, 1)
for x = 1, getContainerCapById(containerid) do
doAddContainerItem(container, itemid, charges)
end

if doPlayerAddItemEx(cid, container, true) ~= RETURNVALUE_NOERROR then
return LUA_ERROR
end
end
return LUA_NO_ERROR
end

function getCount(string)
local b, e = string:find("%d+")
return b and e and tonumber(string:sub(b, e)) or -1
end

as you can see all the files expect priest2.XML
are the same when comparing to TFS1 npc folder in github.
You will find the lua files i did not post here, in the github too posted by ninja
http://otland.net/threads/how-to-put-new-npc-in-game.227930/#post-2195765
 
Last edited:
This is the default script, why would you want the id? what are you trying to do?
Code:
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

npcHandler:addModule(FocusModule:new())
 
Forgot to add the script. (you posted correct script, same i have)

What im trying to do is to make it work..
it gives errors to me, what i wrote in post 1.
 
Forgot to add the script. (you posted correct script, same i have)

What im trying to do is to make it work..
it gives errors to me, what i wrote in post 1.
But your not telling us what you want it to do, just because you put code inside a script even though it might work elsewhere doesn't mean will work in everything.
 
but then NPC does nothing but walk.. (if i take the script away)

i just want NPC to respond if i say "hi"
that would be start.
 
Last edited by a moderator:
i am using these, but i will redownload and see if it fixes.

Did not fix the issue

my NPC.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Priest" script="default.lua" walkinterval="2000" speed="100" walkradius="4" floorchange="0">
    <health max="100" now="100"/>
    <look type="148" head="94" body="0" legs="79" feet="94" addons="1" mount="0"/>
    <parameters>
        <!--MESSAGES-->
        <parameter key="message_greet" value="Greetings, |PLAYERNAME|."/>
        <parameter key="message_farewell" value="Good bye, |PLAYERNAME|."/>
        <parameter key="message_buy" value="Do you want to buy |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?"/>
        <parameter key="message_onbuy" value="Here you are."/>
        <parameter key="message_bought" value="Bought |ITEMCOUNT|x |ITEMNAME| for |TOTALCOST| gold."/>
        <parameter key="message_sell" value="Do you want to sell |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?"/>
        <parameter key="message_onsell" value="Here you are, |TOTALCOST| gold."/>
        <parameter key="message_sold" value="Sold |ITEMCOUNT|x |ITEMNAME| for |TOTALCOST| gold."/>
        <parameter key="message_missingmoney" value="You don't have enough money."/>
        <parameter key="message_needmoney" value="You don't have enough money."/>
        <parameter key="message_missingitem" value="You don't have so many."/>
        <parameter key="message_needitem" value="You do not have this object."/>
        <parameter key="message_needspace" value="You do not have enough capacity."/>
        <parameter key="message_needmorespace" value="You do not have enough capacity for all items."/>
        <parameter key="message_idletimeout" value="Good bye."/>
        <parameter key="message_decline" value="Then not."/>
        <parameter key="message_sendtrade" value="Have a look."/>
        <parameter key="message_noshop" value="Sorry, I'm not offering anything."/>
        <parameter key="message_oncloseshop" value="Thank you, come back whenever you're in need of something else."/>
        <parameter key="message_alreadyfocused" value="|PLAYERNAME|, I am already talking to you."/>
        <parameter key="message_walkaway_male" value="Good bye."/>
        <parameter key="message_walkaway_female" value="Good bye."/>
        <!--KEYWORDS-->
        <parameter key="module_keywords" value="1"/>
        <parameter key="keywords" value="heal"/>
        <parameter key="keyword_reply1" value="Let the gods guide you."/>
    </parameters>
</npc>
 
Last edited by a moderator:
You are using the files from TFS 1.1. But should be using the ones from TFS 1.0. I guess you somehow didn't manage to change to the library files Ninja suggested you to download.
 
o wow.

now i get it..

i was wondering how people use tfs 1.1 when there are only tfs 1.0 files in github..

i have been using 1.1 data folder entire time with my tfs 1.0 exe file
i though some bugs are common and must be fixed by person itself xD
 
You can actually choose to browse the 1.0 branch on github as well.
P2Lo4N3.png

The master branch is the most recent TFS and is currently known as TFS 1.1 (but it's not done yet)
 
Back
Top