whitevo
Feeling good, thats what I do.
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
Creature is in game and walks around but seeing him gives errors and trying to talk to him, gives errors.
NPC file tree
Priest2.XML
default.lua
npc.lua
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
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
<?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>
<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>
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler
nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler
nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler
nCreatureSay(cid, type, msg) end
function onThink() npcHandler
nThink() end
npcHandler:addModule(FocusModule:new())
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler
function onCreatureDisappear(cid) npcHandler
function onCreatureSay(cid, type, msg) npcHandler
function onThink() npcHandler
npcHandler:addModule(FocusModule:new())
-- 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
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: