Słownik:NPC

Z Open Tibia Wiki
(Przekierowano z NPC)
Skocz do: nawigacji, wyszukiwania


Definicja

NPC - (non playable character) określenie postaci, w którą nie wciela się żaden z uczestników RPG podczas sesji. Postać sterowana przez skrypty Lua.

Przykładowy NPC (przewoźnik Fargum, protokół 7.6)

Plik XML:

<?xml version="1.0"?>
<npc name="Fargum" script="data/npc/scripts/boat.lua" access="6">
 	<look type="129" head="114" body="119" legs="114" feet="114"/>
</npc>

Plik Lua - odpowiadający za akcję, które wykonuje NPC:

focus = 0
talk_start = 0
target = 0
following = false
attacking = false
 
function onThink()
	if focus ~= 0 then
		if getDistanceToCreature(focus) > 3 then
			selfSay('Good bye then.')
			focus = 0
		end
	end
 end
 
 
 
function onThingMove(creature, thing, oldpos, oldstackpos)
 
end
 
 
function onCreatureAppear(creature)
 
end
 
 
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('I don`t have time.')
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
		if isPremmium(cid) then
			selfSay('Hello ' .. creatureGetName(cid) .. '! I can take you to the Politechlandia (20gp), Edronium (20gp),
 Spiders Land(50gp),Dragon Land (50gp), Belfegors Land(500gp), Lost Town(20gp), Thais(20gp), 
Xavia(200gp), Serpentia(200gp), Soraya(5k) ?')
 
			focus = cid
			talk_start = os.clock()
		else
			selfSay('Sorry, only premium players can travel by boat.')
			focus = 0
			talk_start = 0
		end
 
  	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, 'dragon land') then
			if pay(cid,50) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 121 119 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
		elseif msgcontains(msg, 'spiders land') then
			if pay(cid,50) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 140 163 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
		elseif msgcontains(msg, 'politechlandia') then
			if pay(cid,20) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 167 60 6')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
 
		elseif msgcontains(msg, 'edronium') then
			if pay(cid,20) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 260 260 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
		elseif msgcontains(msg, 'belfegors land') then
			if pay(cid,500) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 163 237 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
 
		elseif msgcontains(msg, 'lost town') then
			if pay(cid,20) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 280 96 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
		elseif msgcontains(msg, 'thais') then
			if pay(cid,20) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 109 295 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
			elseif msgcontains(msg, 'xavia') then
			if pay(cid,200) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 248 410 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
			elseif msgcontains(msg, 'serpentia') then
			if pay(cid,200) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 426 356 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
			elseif msgcontains(msg, 'soraya') then
			if pay(cid,5000) then
				selfSay('Lets go!')
				selfSay('/send ' .. creatureGetName(cid) .. ', 553 182 7')
				focus = 0
				talk_start = 0
			else
				selfSay('Sorry, you don't have enough money.')
			end
 
 
		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
Osobiste
Przestrzenie nazw
Warianty
Działania
Nawigacja
Narzędzia