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

NPC problem

Alucard

New Member
Joined
Nov 18, 2007
Messages
17
Reaction score
0
Hi,

I'm having a slight problem with a NPC I just scripted (with help of the default TFS NPC's). I have added alot of items that can be bought/sold to it's script, but the NPC only responds when I say hi/bye for some reason. I believe it's because of my .lua script, since there's not much in there tho. I'm not that familiar with .lua scripts, so if anyone could help me out a bit...

This is my .lua script (I took the same .lua script as one of the default TFS NPC's tho):

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())
 
Bump. Come on, I really need someone's help with this. Do I have to add 'shopModule:addBuyableItem' and 'shopModule:addSellableItem' to the .lua script?
 
Last edited:
You can do it in either *.xml or *.lua file of the npc.

Here is the *.xml part (add it in between <parameters></parameters>):

PHP:
<parameter key="module_shop" value="1"/>
		<parameter key="shop_sellable" value="keyword(item name),itemID,price;itemName(keyword),itemID,price"/>
<parameter key="shop_buyable" value="itemName,itemID,itemPrice;itemName,itemID,itemPrice"/>

sellable - all the items npc will buy.
buyable - all the items npc will sell.

and now the *.lua part:

PHP:
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

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

shopModule:addBuyableItem({'itemName', 'itemName'}, 		itemID, itemPrice, 		'itemName(this one NPC will say)')
shopModule:addBuyableItem({'itemName', 'itemName', 'itemName'}, 		itemID, itemPrice, 	itemType(eg. 7 for manafluid), 	'same as above')

npcHandler:addModule(FocusModule:new())
 
I've added those 2 shopmodules (buy and sell) but it doesn't work :S. I'll show you the .xml script and .lua script (don't pay attention to my large .xml file xD).

I've added 2 items which both can be bought and sold to the .lua script, but still my npc only responds on hi and bye

.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Alexander" script="data/npc/scripts/Armory.lua" autowalk="1" floorchange="0">
	<health now="100" max="100"/>
	<look type="134" head="39" body="122" legs="125" feet="57" addons="0"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. What can I do for you?"/>
		<parameter key="message_needmoremoney" value="I'm sorry, but you do not have enough money. Maybe you want to buy something less expensive."/>
		<parameter key="message_decline" value="Very well then. Do you wish to buy anything else?"/>
		<parameter key="module_shop" value="1"/>
		<parameter key="shop_buyable" value="Brass Helmet,2460,120;Chain Helmet,2458,52;Dark Helmet,2490,1000;Helmet of the Deep,5461,5000;Iron Helmet,2459,390;Leather Helmet,2461,12;Party Hat,6578,600;Soldier Helmet,2481,110;Steel Helmet,2457,580;Studded Helmet,2482,63;Viking Helmet,2473,265;"/>
		<parameter key="shop_sellable" value="Beholder Helmet,3972,7500;Brass Helmet,2460,30;Chain Helmet,2458,17;Charmer's Tiara,3971,900;Crown Helmet,2491,2500;Crusader Helmet,2497,6000;Dark Helmet,2490,250;Demon Helmet,2493,95;Devil Helmet,2462,1000;Feather Headdress,3970,850;Golden Helmet,2471,420;Helmet of the Deep,5461,5000;Horned Helmet,2496,155;Horseman Helmet,3969,280;Iron Helmet,2459,150;Krimhorn Helmet,7461,200;Leather Helmet,2461,4;Legion Helmet,2480,22;Mystic Turban,2663,150;Pirate Hat,6096,1000;Ragnir Helmet,7462,400;Royal Helmet,2498,30000;Skull Helmet,5741,40000;Soldier Helmet,2481,16;Steel Helmet,2457,293;Strange Helmet,2479,500;Studded Helmet,2482,20;Tribal Mask,3967,250;Viking Helmet,2473,66;Warrior Helmet,2475,5000;Winged Helmet,2474,320;"/>
	</parameters>
</npc>

.lua
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

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

shopModule:addBuyableItem({'Brass Helmet'}, 2460, 120, 'Brass Helmet')
shopModule:addSellableItem({'Brass Helmet'}, 2460, 120, 'Brass Helmet')

npcHandler:addModule(FocusModule:new())
 
Try to write them in lowercase only, and remove ';' those from the end of your *.xml parts (sellable/buyable)
 
Try to write them in lowercase only, and remove ';' those from the end of your *.xml parts (sellable/buyable)

Probably it was because of the uppercase thing. I just tested it and it worked. About those ';', they are ment to be there, I'm sure of that, as they seperate the items.

Thanks alot for helping me out :D.
 
Back
Top