What's new

[TFS 0.3.5] Npc?

sputerkarol

Advanced User
Joined
Oct 25, 2008
Messages
479
Reaction score
29
Witam, mam taki problem z npc.
A wi?c przenios?em tfs'a 0.2 na 0.3.5.
Npc w og?le nie odpisywa?y.
Postanowi?em przenie?? skrypty z lib typu keywordhandler.lua itd. z 0.3.5.
Wklei?em te? npc, oraz ich skrypty z owego tfs'a.
I teraz taki problem.
Npc dzia?a, lecz nie reaguje na yes. Przy wpisaniu yes wyskakuje :
data/lib/function.lua:72: attempt to call global 'isPlayer' (a nil value)
stack traceback:
data/lib/function.lua:72: in function 'isPlayerPremiumCallback'
data/npc/scripts/addons.lua:20: in function 'callback'
data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
data/npc/lib/npcsystem/keywordhandler.lua:128: in function 'processMessage'
data/npc/lib/npcsystem/npchandler.lua:380: in function 'onCreatureSay'
data/npc/scripts/addons.lua:7: in function <data/npc/scripts/addons.lua:7>
 

Sigon

Active User
Joined
Jul 26, 2009
Messages
82
Reaction score
3
Odp: [TFS 0.3.5] Npc?

Eee, m?wisz tfs 0.3.5... Prosz? o to 2 sposoby zrobienia npc...

1) Npc... Uwaga: Ten Npc nie sprzedaje runek...
Npc.xml


<?xml version="1.0" encoding="UTF-8"?>
<npc name="Npc" script="data/npc/scripts/Npc_Shop.lua" walkinterval="2000" floorchange="0">
<health now="150" max="150"/>
<look type="139" head="132" body="79" legs="97" feet="132" corpse="2212"/>
<parameters>
<parameter key="module_shop" value="1"/>
<parameter key="message_greet" value="Hello |PLAYERNAME|. Say {trade} to see what I can offer you."/>
<parameter key="shop_sellable" value="

Nazwa Itemu,ID Itemu,Za Ile Item; "/>

<parameter key="shop_buyable" value="

Nazwa Itemu,ID Itemu,Za Ile Item; "/>

</parameters>
</npc>

Npc_Shop.lua

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

npcHandler:addModule(FocusModule:new())


2) Npc kt?ry mo?e sprzedawa? runki...

Npc.xml

<?xml version="1.0"?>
<npc name="Npc" script="data/npc/scripts/Npc_Shop.lua" speed="40" access="3" floorchange="0" walkinterval="2000">
<health now="100" max="100"/>
<look type="133" head="114" body="114" legs="114" feet="114" addons="1"/>
<parameters>
<parameter key="message_greet" value="Hello, |PLAYERNAME|. Im selling Premium and Promotion! Say {trade} to see what I can offer you." /> </parameters>
</npc>

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

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

shopModule:addSellableItem({'Nazwa Itemu', 'Tu rodzaj np Rune'}, Id Itemu, Cena, 'Nazwa Itemu')

shopModule:addBuyableItem({'Nazwa Itemu', 'Tu rodzaj np Rune'}, Id Itemu, Cena, 'Nazwa Itemu')

npcHandler:addModule(FocusModule:new())

Prosz?... Tam gdzie mamy Sellable to jest skup przez npc a gdzie Buyable to sprzeda? przez npc... Oczywi?cie to s? scripity na Trade Chanel :p . Je?li nie chcesz na Trade Chanel to napisz na PW a ci wy?le scripit...
 
Last edited:

sputerkarol

Advanced User
Joined
Oct 25, 2008
Messages
479
Reaction score
29
Odp: [TFS 0.3.5] Npc?

Wszystkie skrypty na npc addons.lua etc. wrzuci?em z tfs'a 0.3.5.
Zdaje mi si?, ?e to co? z keywordhandler.lua
PS:
Nie dzia?a mi tylko.
Varkhal,
Johnny.
Potrzebuje skrypt?w pod tfs'a 0.3.5 : addons.lua, promotion.lua.
Addons.lua ma by? w formie : hi>first addon>yes.
 
Last edited:

Hulala

Senior User
Joined
May 2, 2008
Messages
539
Reaction score
37
Age
32
Odp: [TFS 0.3.5] Npc?

Sprawd? czy Ci dzia?a:
Addon.lua
Code:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
  		selfSay('Hello ' .. creatureGetName(cid) .. '! I sell the first addon for 5k and the second addon for 10k.')
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'first addon') then
			selfSay('Do you want to buy the first addon for 5k?')
			talk_state = 1

		elseif msgcontains(msg, 'second addon') then
			selfSay('Do you want to buy the second addon for 10k?')
			talk_state = 2	
		
		elseif talk_state == 1 then
			if msgcontains(msg, 'yes') then
				if pay(cid,5000) then
					addon(cid, 1)
				else
					selfSay('Sorry, you don\'t have enough money.')
				end
 			end
			talk_state = 0

		elseif talk_state == 2 then
			if msgcontains(msg, 'yes') then
				if pay(cid,10000) then
					addon(cid, 2)
				else
					selfSay('Sorry, you don\'t have enough money.')
				end
 			end
			talk_state = 0
			
		elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
			selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
			focus = 0
			talk_start = 0
		end
	end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
	doNpcSetCreatureFocus(focus)
	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end

promotion.lua
Code:
local focus = 0
local talk_start = 0
local target = 0
local days = 0

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
 		selfSay('Hello ' .. creatureGetName(cid) .. '! I sell premiums and promotions.')
 		focus = cid
 		talk_start = os.clock()

	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.')

  	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, 'promotion') or msgcontains(msg, 'promote') then
 			if getPlayerVocation(cid) > 4 then
 				selfSay('Sorry, you are already promoted.')
 				talk_state = 0
 			elseif getPlayerLevel(cid) < 20 then
				selfSay('Sorry, you need level 20 to buy promotion.')
				talk_state = 0
			elseif not isPremium(cid) then
				selfSay('Sorry, you must be premium to buy promotion.')
				talk_state = 0
			else
				selfSay('Do you want to buy promotion for 20k?')
				talk_state = 1
			end

		elseif msgcontains(msg, 'premium') or msgcontains(msg, 'premmy') then
			selfSay('Do you want to buy 7 days of premium for 7k?')
			talk_state = 2

		elseif talk_state == 1 then
			if msgcontains(msg, 'yes') then
				if pay(cid,20000) then
					doPlayerSetVocation(cid, getPlayerVocation(cid)+4)
					selfSay('You are now promoted!')
				else
					selfSay('Sorry, you do not have enough money.')
				end
 			end
			talk_state = 0

		elseif talk_state == 2 then
			if msgcontains(msg, 'yes') then
				if pay(cid,7000) then
					selfSay('/premium '.. creatureGetName(cid) ..', 7')
					selfSay('You have 7 days of premium more!')
				else
					selfSay('Sorry, you do not have enough money.')
				end
			end
			talk_state = 0

  		elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then
  			selfSay('Good bye, ' .. creatureGetName(cid) .. '!')
  			focus = 0
  			talk_start = 0
  		end
  	end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
	doNpcSetCreatureFocus(focus)
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end

Napisz czy dzia?a.
 

sputerkarol

Advanced User
Joined
Oct 25, 2008
Messages
479
Reaction score
29
Odp: [TFS 0.3.5] Npc?

Teraz npc wgl nie reaguj? na "hi" .
Prosz? o dalsz? pomoc.
PS:
B??dy w konsoli wyskakuj? dopiero po napisaniu "yes".
 

Hulala

Senior User
Joined
May 2, 2008
Messages
539
Reaction score
37
Age
32
Odp: [TFS 0.3.5] Npc?

Prosz? usun?? tego posta co? z netem mam i wys?a?o mi 2 >.<


To mo?e NPC Ci dam.
Johnny.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Johnny" script="data/npc/scripts/promotion.lua" walkinterval="2000" floorchange="0">
	<mana now="800" max="800"/>
	<health now="200" max="200"/>
	<look type="133" head="114" body="119" legs="132" feet="114"/>

	<parameters>
		<parameter key="module_shop" value="3" />
	</parameters>
</npc>

Varkhal.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Varkhal" script="data/npc/scripts/addons.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="134" head="78" body="88" legs="0" feet="88" addons="3"/>
</npc>
 
Last edited:

Hulala

Senior User
Joined
May 2, 2008
Messages
539
Reaction score
37
Age
32
Odp: [TFS 0.3.5] Npc?

To mo?e NPC Ci dam.
Johnny.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Johnny" script="data/npc/scripts/promotion.lua" walkinterval="2000" floorchange="0">
	<mana now="800" max="800"/>
	<health now="200" max="200"/>
	<look type="133" head="114" body="119" legs="132" feet="114"/>

	<parameters>
		<parameter key="module_shop" value="3" />
	</parameters>
</npc>

Varkhal.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Varkhal" script="data/npc/scripts/addons.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="134" head="78" body="88" legs="0" feet="88" addons="3"/>
</npc>
 

sputerkarol

Advanced User
Joined
Oct 25, 2008
Messages
479
Reaction score
29
Odp: [TFS 0.3.5] Npc?

Podmieni?em te npc ( w sumie by?y prawie takie same ) i dalej nie odpisuj?. Pr?bowa?em te? wrzuci? stary skrypt to dalej s? takie b??dy jak by?y.
 

arabek3929

Advanced User
Joined
Sep 20, 2008
Messages
312
Reaction score
25
Odp: [TFS 0.3.5] Npc?

By? mo?e jest co? nie tak w folderze npc/lib
 

sputerkarol

Advanced User
Joined
Oct 25, 2008
Messages
479
Reaction score
29
Odp: [TFS 0.3.5] Npc?

@up
To nie mo?e by? to. Przecie? pisa?em, ?e nie dzia?aj? tylko dwa npc.
 
Top