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

Advanced NPC ? Any good scripter, check it !

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,855
Solutions
18
Reaction score
671
Hello.
I want an Advanced NPC.

TFS 0.3.5pl1
Talon ID: 2687
Fish ID: 2667
Storage for quest: 10555

Explain:

First option i need to be in NPC:
Player: Hi
NPC: Welcome in my tower dear adventurer.
Player: Offer
NPC: I can sell you talons {buy x talons}, also I can buy fishes from you.
Player: Buy 100 talons
NPC are selling talons about 200gp/ea
NPC: Do you want buy 100 talons for 200000 gold coins ?
Player: Yes
NPC: Here you are.

Second option i need to be in NPC:
Player: Sell X fish
NPC: What ? I dont have enough respect to you to buy from you fishes, where to know you not selling acid fishes... you must do an favor for gain respect... you can do {favor} ?

if Player say {favor}:
NPC: Okey... huh... im very hungry... I could do this myself but i cannot walking... You must bring me 100 fishes first, if they are be good i can give you permission to buy more from you. Can you do this favor, {yes} ?

if Player say {yes}:
if Player got 100 fishes:
NPC: Thanks a lot! Hmmm... <tastes one of fish>, its great! If you have more fishes i buy it from you !

NPC set storage, and player can now type to NPC: Sell x fish
NPC: Do you want sell 100 fish for 100000 gold coins ?
NPC buy from player normally :)


if Player doesnt got 100 fishes (if quest(favor) is doesnt complete):
NPC check storage, if player dont have storage then:
NPC: Please come back when you got it, otherwise i cannot buy fishes from you!


I hope you can do it ?
Thanks in above!
Fresh.
You can gain 5 reputation points (from my other acc`s ofc):)
 
Last edited:
First
LUA:
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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
end
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, 'offer') then
		selfSay('I can sell you talons {buy x talons}, also I can buy fishes from you.', cid)
	elseif msgcontains(msg, 'buy 100 talons') then
		selfSay('Do you want buy 100 talons for 200000 gold coins ?', cid)
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveMoney(cid,200000) == TRUE then
				doPlayerAddItem(cid, 2687, 100)
				selfSay('Here you are', cid)
			else
			selfSay('You don\'t have enough money.', cid)
			end
		elseif msgcontains(msg, 'no') then
		selfSay('Ok then...', cid)
		end
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

And the greet change in xml
for example
Code:
<npc name="Tet" script="data/npc/scripts/tet.lua" walkinterval="20" floorchange="0" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
	<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="[COLOR="RoyalBlue"]Welcome in my tower dear adventurer.[/COLOR]" />
</parameters>
</npc>
 
Fresh can you use interaction npcs? like this:

THIS IS A EXAMPLE NPC
LUA:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Olle" walkinterval="2000" floorchange="0">
		<health now="150" max="150"/>
	<look type="129" head="114" body="119" legs="114" feet="114" corpse="2212"/>
    
	<interaction range="3" idletime="30">
	<include file="npcchannel.xml"/>
		<interact keywords="hi" focus="1">
		<keywords>hello</keywords>
		<keywords>greet</keywords>
			<response>
				<action name="script" ><![CDATA[
if isPlayer(cid) == true then
		selfSay("Hello, ".. getCreatureName(cid).." If you don't know where to flow, say {travel}." ,cid)
	_state.topic = 1
	return true
end
	 ]]></action>
      </response>
	</interact>
	
	<interact keywords="travel" topic="1">
			<response>
				<action name="script"><![CDATA[
	if isPlayer(cid) == true then
		selfSay("You can sail to West and Swampis.",cid )
		_state.topic = 10
	return true
end
	 ]]></action>
      </response>
	</interact>
	
		<interact keywords="West" topic="1, 10">
			<response>
				<action name="script"><![CDATA[
	if isPlayer(cid) == true then
		selfSay("Do you realy want to go on a trip to West?",cid )
	_state.topic = 2
	return true
end
	 ]]></action>
      </response>
	</interact>
	
	<interact keywords="swampis" topic="1, 10">
			<response>
				<action name="script"><![CDATA[
	if isPlayer(cid) == true then
		selfSay("Do you realy want to go on a trip to Swampis?" ,cid)
	_state.topic = 3
	return true
end
	 ]]></action>
      </response>
	</interact>
	
	<interact keywords="Yes" topic="2">
			<response>
				<action name="script"><![CDATA[
	if isPlayer(cid) == true then
	west = {x = 985, y = 1209, z = 6}
		selfSay("Okey, have a nice trip." ,cid)
		doTeleportThing(cid, west, false)
	_state.topic = 4
	return true
end
	 ]]></action>
      </response>
	</interact>
	
	<interact keywords="yes" topic="3">
			<response>
				<action name="script"><![CDATA[
	if isPlayer(cid) == true then
	swampis = {x = 639, y = 998, z = 6}
		selfSay("Okey, have a nice trip.",cid )
		doTeleportThing(cid, swampis, false)
	_state.topic = 5
	return true
end
	 ]]></action>
      </response>
	</interact>
	
	<interact> 
	  <response>
        <action name="idle" value="1"/>
      </response>
    </interact>
	
    <interact keywords="bye" focus="0">
      <keywords>farewell</keywords>
      <response text="Good bye. Recommend us, if you were satisfied with our service."/>
    </interact>


    <!--This event triggers if the player goes to far away from the npc/logout/idle timeout-->
    <interact event="onPlayerLeave" focus="0">
      <response text="Bye, hope to see you later!"/>
    </interact>
	
  </interaction>
</npc>
this is a free travler npc you can try to see if you can use interactions insted of parameters
if you can then I can help you.
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic, Amount, Price, Type = {}, {}, {}, {}
local storage = 10555

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 getCount(string)
	local b, e = string:find("%d+")
	return b and e and tonumber(string:sub(b, e))
end

function greetCallback(cid)
	local id = getPlayerGUID(cid)
	Topic[id], Type[id], Amount[id], Price[id] = 0, 0, 0, 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	end
	
	local id = getPlayerGUID(cid) 

	if msgcontains(msg, 'offer') then
		npcHandler:say('I\'m selling talons for 200 gold each. I can also buy fishes from you.', cid)
		Topic[id] = 0
	elseif msgcontains(msg, 'talon') then
		Amount[id] = getCount(msg) and math.max(1, math.min(getCount(msg), 500)) or 1
		Price[id] = Amount[id] * 200
		Topic[id] = 1
		Type[id] = 2687
		npcHandler:say("Do you want to buy " .. (Amount[id] == 1 and "a talon" or Amount[id] .. " talons") .. " for " .. Price[id] .. " gold?", cid)
	elseif (getPlayerStorageValue(cid, storage) < 1 or msgcontains(msg, 'sell')) and msgcontains(msg, 'fish') then
		if getPlayerStorageValue(cid, storage) < 1 then
			npcHandler:say("What? I don't trust you enough to buy fish from you. Who knows if you're selling acid fishes... You must do me a {favor} in order to gain my trust.", cid)
			Topic[id] = 2
		else
			Amount[id] = getCount(msg) and math.max(1, math.min(getCount(msg), 500)) or 1
			Price[id] = Amount[id] * 1000
			Topic[id] = 4
			Type[id] = 2667
			npcHandler:say("Do you want to sell " .. (Amount[id] == 1 and "a fish" or Amount[id] .. " fish") .. " for " .. Price[id] .. " gold?", cid)
		end
	elseif msgcontains(msg, 'favor') and Topic[id] == 2 then
		npcHandler:say("Okay, huh... I'm very hungry, I could do this myself but I can't walk. You must bring me 100 fish first, if they are be good I'll give you permission for selling fish to me. Can you do this favor, {yes}?", cid)
		Topic[id] = 3
	elseif msgcontains(msg, 'yes') and Topic[id] == 3 then
		if doPlayerRemoveItem(cid, 2667, 100) then
			setPlayerStorageValue(cid, storage, 1)
			npcHandler:say("Thanks a lot! Hmmm, <tastes one of fish> ... It's great! If you have more fish, I'll buy them from you!", cid)
		else
			npcHandler:say("Please come back when you got them, otherwise I won't buy fish from you!", cid)
		end
		Topic[id] = 0
	elseif Topic[id] == 1 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveMoney(cid, Price[id]) then
				npcHandler:say("Thank you. Here it is.", cid)
				doPlayerAddItem(cid, Type[id], Amount[id])
			else
				npcHandler:say("Sorry, you do not have enough gold.", cid)
			end
		else
			npcHandler:say("Maybe you will buy it another time.", cid)
		end
		Topic[id], Type[id], Amount[id], Price[id] = 0, nil, nil, nil
	elseif Topic[id] == 4 then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, Type[id], Amount[id]) then
				npcHandler:say("Ok. Here is your money.", cid)
				doPlayerAddMoney(cid, Price[id])
			else
				npcHandler:say("Sorry, you do not " .. (Amount[id] > 1 and "so many" or "have one") .. ".", cid)
			end
		else
			npcHandler:say("Maybe next time.", cid)
		end
		Topic[id], Type[id], Amount[id], Price[id] = 0, nil, nil, nil
	end
	return true
end

npcHandler:setMessage(MESSAGE_GREET, "Welcome to my tower, dear adventurer.")

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Okey.
But what i must write in fields:
PHP:
local Topic, Amount, Price, Type = {}, {}, {}, {}
???
 
Last edited:
@Up
Man i dont know what you mean from me ?
You having complexes ?
Or You are stupid loader of posts... -.-"
You posts doesn't have sense,
and if you have such a trauma to the word "fucking" its not my problem, i dont get fucked from anyone...
 
Back
Top