• 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 WAR NPC

Saint Spear

Veteran OT User
Joined
Jun 22, 2016
Messages
1,547
Solutions
18
Reaction score
379
Hello guys, I am making an npc which should sell War Weapons
i place it in temple
and all works fine untill i click ok , it wont take to me ( it wont sell )
so here's lua, also i took it from eryn ( npc for supplies )
<?xml version="1.0" encoding="UTF-8"?>
<npc name="War NPC" nameDescription="War Items" script="waritems.lua" walkinterval="2000" floorchange="0" skull="red">
<health now="100" max="100"/>
<look type="130" head="39" body="122" legs="125" feet="57" addons="3"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. I sell Weapons for War"/>
<parameter key="message_decline" value="Is |TOTALCOST| gold coins too much for you? Get out of here!"/>
</parameters>
</npc>

____________________________________________________________________________
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'War Wand', 'Wand'}, 2453, 20000, 'War Wand')
shopModule:addBuyableItem({'War Star', 'Star'}, 7366, 20000, 'War Star')
shopModule:addBuyableItem({'War Sword', 'Sword'}, 6528, 20000, 'War Sword')
shopModule:addBuyableItem({'War Axe', 'Axe'}, 2454, 20000, 'War Axe')

local items = {[1] = 2190, [2] = 2182, [5] = 2190, [6] = 2182}
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, 'first rod') or msgcontains(msg, 'first wand')) then
if(isSorcerer(cid) or isDruid(cid)) then
if(getPlayerStorageValue(cid, 30002) <= 0) then
selfSay('So you ask me for a {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '} to begin your advanture?', cid)
talkState[talkUser] = 1
else
selfSay('What? I have already gave you one {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '}!', cid)
end
else
selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
end
elseif(msgcontains(msg, 'yes')) then
if(talkState[talkUser] == 1) then
doPlayerAddItem(cid, items[getPlayerVocation(cid)], 1)
selfSay('Here you are young adept, take care yourself.', cid)
setPlayerStorageValue(cid, 30002, 1)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
selfSay('Ok then.', cid)
talkState[talkUser] = 0
end

return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
after to npc i click "ok" on selected item , in my tfs 0.3.6 console it says
[30/01/2017 18:02:37] [Error - Npc interface]
[30/01/2017 18:02:37] (Unknown script file)
[30/01/2017 18:02:37] Description:
[30/01/2017 18:02:37] data/npc/lib/npcsystem/modules.lua:1152: bad argument #2 to 'error' (number expected, got string)
[30/01/2017 18:02:37] stack traceback:
[30/01/2017 18:02:37] [C]: in function 'error'
[30/01/2017 18:02:37] data/npc/lib/npcsystem/modules.lua:1152: in function 'callbackOnBuy'
[30/01/2017 18:02:37] data/npc/lib/npcsystem/npchandler.lua:263: in function 'processModuleCallback'
[30/01/2017 18:02:37] data/npc/lib/npcsystem/npchandler.lua:440: in function 'onBuy'
[30/01/2017 18:02:37] data/npc/lib/npcsystem/modules.lua:1293: in function <data/npc/lib/npcsystem/modules.lua:1292>
 
Back
Top