summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-03-25 21:37:38 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-03-25 21:37:38 +0000
commit5b1c1c9a4f3d165942b26a39a292a8c71d869df1 (patch)
tree57cb730d3af398a9fa40168da78f5aaaa16f0919 /data
parent855d0b99b1240b2eeb73843137dd58e096f12180 (diff)
downloadmanaserv-5b1c1c9a4f3d165942b26a39a292a8c71d869df1.tar.gz
manaserv-5b1c1c9a4f3d165942b26a39a292a8c71d869df1.tar.bz2
manaserv-5b1c1c9a4f3d165942b26a39a292a8c71d869df1.tar.xz
manaserv-5b1c1c9a4f3d165942b26a39a292a8c71d869df1.zip
Added a Lua library with walk around functions for NPCs.
Diffstat (limited to 'data')
-rw-r--r--data/scripts/npclib.lua84
-rw-r--r--data/test.lua22
2 files changed, 90 insertions, 16 deletions
diff --git a/data/scripts/npclib.lua b/data/scripts/npclib.lua
new file mode 100644
index 00000000..c438d144
--- /dev/null
+++ b/data/scripts/npclib.lua
@@ -0,0 +1,84 @@
+------------------------------------------------------------------------------
+-- Library for commonly used NPC scripts --
+-- --
+-- Any NPC update function or talk function which could be used for NPCs on --
+-- more than one map should be placed here. --
+------------------------------------------------------------------------------
+
+module("npclib", package.seeall);
+
+
+-- Update function walkaround_small
+-- makes the NPC walk around in a 64x64 pixel square around its start location.
+-- Useful for NPCs which are supposed to stay on a specific spot but
+-- move a bit from time to time.
+
+local wasmall_timer = {}
+local wasmall_startx = {}
+local wasmall_starty = {}
+
+function walkaround_small(npc)
+ if not wasmall_timer[npc] then
+ wasmall_timer[npc] = 1
+ wasmall_startx[npc] = tmw.posX(npc)
+ wasmall_starty[npc] = tmw.posY(npc)
+ end
+
+ wasmall_timer[npc] = wasmall_timer[npc] + 1
+
+ if wasmall_timer[npc] == 100 then
+ wasmall_timer[npc] = math.random(1, 10)
+ local x = math.random(-32, 32) + wasmall_startx[npc]
+ local y = math.random(-32, 32) + wasmall_starty[npc]
+ tmw.being_walk(npc, x, y, 500)
+ end
+end
+
+
+-- Update function walkaround_wide
+-- makes the NPC walk around in a 256x256 pixel square around its start
+-- location. Useful for NPCs which are supposed to be found near a specific
+-- location but not nailed to the floor.
+
+local wawide_timer = {}
+local wawide_startx = {}
+local wawide_starty = {}
+
+function walkaround_wide(npc)
+ if not wawide_timer[npc] then
+ wawide_timer[npc] = 1
+ wawide_startx[npc] = tmw.posX(npc)
+ wawide_starty[npc] = tmw.posY(npc)
+ end
+
+ wawide_timer[npc] = wawide_timer[npc] + 1
+
+ if wawide_timer[npc] == 50 then
+ wawide_timer[npc] = math.random(1, 10)
+ local x = math.random(-128, 128) + wawide_startx[npc]
+ local y = math.random(-128, 128) + wawide_starty[npc]
+ tmw.being_walk(npc, x, y, 500)
+ end
+end
+
+
+-- Update function walkaround_map
+-- makes the NPC wander around the whole map. Useful when the players are
+-- supposed to search a bit for the NPC.
+
+local wam_timer = {}
+
+function walkaround_map(npc)
+ if not wam_timer[npc] then
+ wam_timer[npc] = 1
+ end
+
+ wam_timer[npc] = wam_timer[npc] + 1
+
+ if wam_timer[npc] == 50 then
+ wam_timer[npc] = math.random(1, 10)
+ local x = math.random(-128, 128) + tmw.posX(npc)
+ local y = math.random(-128, 128) + tmw.posY(npc)
+ tmw.being_walk(npc, x, y, 500)
+ end
+end \ No newline at end of file
diff --git a/data/test.lua b/data/test.lua
index 3bc630fb..70c0b66f 100644
--- a/data/test.lua
+++ b/data/test.lua
@@ -2,10 +2,12 @@
-- Map code --
--------------
+require "data/scripts/npclib"
+
atinit(function()
- create_npc(110, 50 * 32 + 16, 19 * 32 + 16, npc1_talk, nil)
- create_npc(108, 51 * 32 + 16, 25 * 32 + 16, npc4_talk, nil)
- create_npc(126, 45 * 32 + 16, 25 * 32 + 16, npc5_talk, npc5_update)
+ create_npc(110, 50 * 32 + 16, 19 * 32 + 16, npc1_talk, npclib.walkaround_small)
+ create_npc(108, 51 * 32 + 16, 25 * 32 + 16, npc4_talk, npclib.walkaround_wide)
+ create_npc(126, 45 * 32 + 16, 25 * 32 + 16, npc5_talk, npclib.walkaround_map)
create_npc(122, 58 * 32 + 16, 15 * 32 + 16, npc6_talk, nil)
end)
@@ -72,24 +74,12 @@ function npc5_talk(npc, ch)
local x = tmw.posX(npc)
local y = tmw.posY(npc)
tmw.monster_create(1012, x + 32, y + 32)
- tmw.monster_create(1012, x - 32, y + 32)
+ tmw.monster_create(112, x - 32, y + 32)
tmw.monster_create(1012, x + 32, y - 32)
tmw.monster_create(1012, x - 32, y - 32)
end
end
-local spidertamer_timer = 0
-
-function npc5_update(npc)
- spidertamer_timer = spidertamer_timer + 1
- if spidertamer_timer == 50 then
- spidertamer_timer = 0
- local x = math.random(-64, 64) + tmw.posX(npc)
- local y = math.random(-64, 64) + tmw.posY(npc)
- tmw.being_walk(npc, x, y, 500)
- end
-end
-
local guard_position = 1
function npc6_talk(npc, ch)