diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-05-29 22:11:12 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-05-30 17:50:55 +0200 |
commit | 3e669831a05c36a38519b6f22cb1ed3c11837f2f (patch) | |
tree | 21a2763b425480c909d43efe0856cfbab48e3573 /scripts/lua/npclib.lua | |
parent | 8a95ed77fec7c2ef3c0fac81258f70db25009b48 (diff) | |
download | manaserv-3e669831a05c36a38519b6f22cb1ed3c11837f2f.tar.gz manaserv-3e669831a05c36a38519b6f22cb1ed3c11837f2f.tar.xz manaserv-3e669831a05c36a38519b6f22cb1ed3c11837f2f.zip |
Copied basic Lua libs back from tmwserv-data and added dummy data
The dummy data is currently mostly empty data though, so still nothing
to see as far as the example content is concerned.
Reviewed-by: Bertram
Diffstat (limited to 'scripts/lua/npclib.lua')
-rw-r--r-- | scripts/lua/npclib.lua | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/scripts/lua/npclib.lua b/scripts/lua/npclib.lua new file mode 100644 index 0000000..9edfcbd --- /dev/null +++ b/scripts/lua/npclib.lua @@ -0,0 +1,103 @@ +---------------------------------------------------------- +-- 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. -- +-- -- +---------------------------------------------------------------------------------- +-- Copyright 2008 The Mana World Development Team -- +-- -- +-- This file is part of The Mana Server. -- +-- -- +-- The Mana Server is free software; you can redistribute it and/or modify it -- +-- under the terms of the GNU General Public License as published by the Free -- +-- Software Foundation; either version 2 of the License, or any later version. -- +---------------------------------------------------------------------------------- + +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] = mana.posX(npc) + wasmall_starty[npc] = mana.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] + mana.being_walk(npc, x, y, 2) + 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] = mana.posX(npc) + wawide_starty[npc] = mana.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] + mana.being_walk(npc, x, y, 2) + 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) + mana.posX(npc) + local y = math.random(-128, 128) + mana.posY(npc) + mana.being_walk(npc, x, y, 2) + end +end + +-- Allows passage of more information to an NPC's talk function +function talk(f, ...) + local a = {...} + return function(npc, ch) + f(npc, ch, a) + end +end |