• logo_cipsoft
    Nowe serwery zostały otwarte 19 Lut 2025:
    Noctalia (Open PvP) Ignitera (Open PvP) us_logo Xybra (Open PvP)

NPC NPC item za item

Status
Zamknięty.

darekkielek

New User
Dołączył
Czerwiec 19, 2010
Posty
1
Liczba reakcji
0
Witam, ostatnio mi pare koleg?w dupe tru?o ?eby im zrobi? skrypt na NPC kt?ry daje przedmiot za przedmiot :) Zrobi?em i chc? podzieli? si? owym dzie?em.


Zaczynamy :)

W data/npc robimy pilk o nazwie Moras.xml i wklejamy do niego to:
PHP:
<?xml version="1.0"?>
<npc name="Moras" script="data/npc/scripts/moras.lua" access="3">
 	<look type="100" head="20" body="30" legs="40" feet="50"/>
</npc>
Teraz w data/npc/scripts robimy plik o nazwie moras.lua i wklejamy do niego to:
PHP:
focus = 0
talk_start = 0
target = 0
following = false
attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
      if focus == cid then
          selfSay('Dowidzenia.')
          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 ((string.find(msg, '(%a*)hi(%a*)')
or string.find(msg, '(%a*)siema(%a*)')
or string.find(msg, '(%a*)czesc(%a*)')
or string.find(msg, '(%a*)cze(%a*)')
or string.find(msg, '(%a*)yo(%a*)')
or string.find(msg, '(%a*)elo(%a*)'))
and (focus == 0)) and getDistanceToCreature(cid) < 4 then

rsay = math.random(1,4)
if rsay == 1 then says = 'Waazzuup'
elseif rsay == 2 then says = 'Siema'
elseif rsay == 3 then says = 'Czesc'
elseif rsay == 4 then says = 'Witam'
end



  		selfSay('Czesc ' .. creatureGetName(cid) .. 'moge ci wymienic "przedmiot 1" na "przedmiot 2" czy     chcesz dokonac tej zamiany (jesli tak napisz "Tak").')
  		focus = cid
  		talk_start = os.clock()

  	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Spadaj ' .. creatureGetName(cid) .. ' do kolejki!')

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

		if msgcontains(msg, 'tak') then
			
                itemstatus = doPlayerRemoveItem(cid,1111) <-- wpisz id przedmiotu 1
                if itemstatus == -1 then
                selfSay('Nie masz tego przedmiotu... ;/ :D')
                else
                buy(cid,1111,1,0)   <--- wpisz id przedmiotu 2
                selfSay('Dokonano zamiany miszczu :D.')
                end

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


function onCreatureChangeOutfit(creature)

end


function onThink()
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('Ktos nastepny?')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Zapraszam ponownie.')
focus = 0
end
end
if focus == 0 then
cx, cy, cz = selfGetPosition()
randmove = math.random(1,20)
if randmove == 1 then
nx = cx + 1
end
if randmove == 2 then
nx = cx - 1
end
if randmove == 3 then
ny = cy + 1
end
if randmove == 4 then
ny = cy - 1
end
if randmove >= 5 then
nx = cx
ny = cy
end
moveToPosition(nx, ny, cz)
--summons = 30
--summons2 = 30
end
end

Koniec :D mam nadzieje, ?e przyda sie to komu? :)
 
Status
Zamknięty.
Do góry