Administrator |
Wysłany: Sob 16:29, 18 Mar 2006 Temat postu: [NPC] Dzownek (Donger) |
|
Witam. To mój pierwszy skrypt. Zrobiłem npc dzwonek. Na moim otsie bywało tak, że jedna osoba otworzyła w swoim domku sklep. Ale nie zawsze mogła być w sklepie wtedy gdy był klient. A powiadamianie ręcznie na priv było niezbyt ciekawe. Dlatego zrobiłem npc dzownka, który po wpisaniu "dong" przywołuje do siebie daną osobę. Do tego można sobie dorobić samemu ewentualnie lever który sam za playera mówi słowo które wywołuje sprzedawce A więc tak:
data/npc
Tworzymy Donger.xml i wpisujemy w nim:
Kod: | <?xml version="1.0"?>
<npc name="Donger" script="data/npc/scripts/donger.lua" access="3">
<look type="131" head="79" body="79" legs="79" feet="79"/>
</npc> |
Nazwę donger można zmienić na swoją nazwę npc
data/npc/scripts
Tworzymy donger.lua i wpisujemy w nim:
Kod: | -- Npc Donger by Kubofon --
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('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, 'dong') and focus == 0) and getDistanceToCreature(cid) < 4 then
selfSay('Witam ' .. creatureGetName(cid) .. '! Zaraz zawolam sprzedawce.')
selfSay('/c Nick Osoby')
selfSay('Sprzedawca juz jest')
focus = cid
talk_start = os.clock()
elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Przepraszam, aby zadzwonic po sprzedawce wpisz dong')
elseif focus == cid then
talk_start = os.clock()
end
end
function onCreatureChangeOutfit(creature)
end
function onThink()
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 |
Pochylone wartości można zmienić.
if (msgcontains(msg, 'dong') and focus == 0) and - W tej linijce zamiast dong, można wpisać inne słowo na które ma zaareagować npc
selfSay('Witam ' .. creatureGetName(cid) .. '! Zaraz zawolam sprzedawce.') - Powitanie po prośbie o wywołanie sprzedawcy
selfSay('/c Nick Osoby)' - Przeteleportowanie do siebie sprzedawcy
selfSay('Sprzedawca juz jest') - Informacja o przybyciu sprzedawcy
data/world/npc.xml
Kod: | <npc name="Donger" x="pozycjax" y="pozycjay" z="pozycjaz"/> |
Jeśli modyfikowałeś nazwę npc to w npc name=" wpisz swoją nazwę.
I to na tyle, powinno działać, jest to mój pierwszy skrypt więc wrazie błędów proszę o wyrozumiałość |
|