summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-10-27 16:53:13 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-10-27 16:53:13 +0000
commitfb2b268a2616617800b92330e09278042e50e7d7 (patch)
tree326f730314249c159adce0971d26e51a26acb358
parentbbb9a98aeefaa1609dbd2455c102750c5005e05f (diff)
downloadmanaserv-fb2b268a2616617800b92330e09278042e50e7d7.tar.gz
manaserv-fb2b268a2616617800b92330e09278042e50e7d7.tar.bz2
manaserv-fb2b268a2616617800b92330e09278042e50e7d7.tar.xz
manaserv-fb2b268a2616617800b92330e09278042e50e7d7.zip
Script binding for spawning effets from scripts.
-rw-r--r--ChangeLog7
-rw-r--r--data/scripts/test.lua15
-rw-r--r--src/scripting/lua.cpp30
3 files changed, 52 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 47431a91..4832c365 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-10-27 Philipp Sehmisch <tmw@crushnet.org>
+
+ * src/scripting/lua.cpp: Added script binding for spawning effets from
+ scripts.
+ * data/scripts/test.lua: Created example NPC for spawning effetcs from
+ scripts.
+
2008-10-27 Chuck Miller <shadowmil@gmail.com>
* src/defines.h, src/game-server/thing.hpp, src/game-server/state.cpp,
diff --git a/data/scripts/test.lua b/data/scripts/test.lua
index 344ca105..7f96a61e 100644
--- a/data/scripts/test.lua
+++ b/data/scripts/test.lua
@@ -24,6 +24,7 @@ atinit(function()
create_npc("Guard", 122, 58 * TILESIZE + 16, 15 * TILESIZE + 16, npc6_talk, npc6_update)
create_npc("Fire Demon", 202, 58 * TILESIZE + 16, 35 * TILESIZE + 16, firedemon_talk, firedemon_update)
create_npc("Post Box", 158, 45 * TILESIZE + 16, 22 * TILESIZE + 16, post_talk)
+ create_npc("Fireworker", 158, 43 * TILESIZE, 23 * TILESIZE, fireworker_talk, npclib.walkaround_small)
tmw.trigger_create(56 * TILESIZE, 32 * TILESIZE, 64, 64, "patrol_waypoint", 1, true)
tmw.trigger_create(63 * TILESIZE, 32 * TILESIZE, 64, 64, "patrol_waypoint", 2, true)
@@ -198,3 +199,17 @@ function post_talk(npc, ch)
end
end
end
+
+function fireworker_talk(npc, ch)
+ do_message(npc, ch, "Do you want some fireworks?")
+ local answer = do_choice(npc, ch, "Wheee! Fireworks", "Nah, thanks.")
+ if answer == 1 then
+ local x = tmw.posX(npc)
+ local y = tmw.posY(npc)
+ for c = 0, 25 do
+ schedule_in (c, function()
+ tmw.effect_create(c, x + math.random(-200, 200), y + math.random(-200, 200))
+ end)
+ end
+ end
+end
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 7f421c67..c0c7a95c 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -33,6 +33,7 @@ extern "C" {
#include "game-server/buysell.hpp"
#include "game-server/character.hpp"
#include "game-server/collisiondetection.hpp"
+#include "game-server/effect.hpp"
#include "game-server/gamehandler.hpp"
#include "game-server/inventory.hpp"
#include "game-server/item.hpp"
@@ -874,6 +875,34 @@ static int LuaNoteOnDeath(lua_State *s)
return 0;
}
+/**
+ * Triggers a special effect from the clients effects.xml
+ * tmw.effect_create (id, x, y)
+ */
+static int LuaEffect_Create(lua_State *s)
+{
+ if (!lua_isnumber(s, 1) ||
+ !lua_isnumber(s, 2) ||
+ !lua_isnumber(s, 3))
+ {
+ raiseScriptError(s, "effect_create called with incorrect parameters.");
+ return 0;
+ }
+ lua_pushlightuserdata(s, (void *)&registryKey);
+ lua_gettable(s, LUA_REGISTRYINDEX);
+ Script *t = static_cast<Script *>(lua_touserdata(s, -1));
+
+ MapComposite *m = t->getMap();
+ int id = lua_tointeger(s, 1);
+ int x = lua_tointeger(s, 2);
+ int y = lua_tointeger(s, 3);
+
+ Effects::show(id, m, Point(x, y));
+
+ return 0;
+}
+
+
LuaScript::LuaScript():
nbArgs(-1)
{
@@ -906,6 +935,7 @@ LuaScript::LuaScript():
{ "chatmessage", &LuaChatmessage },
{ "get_beings_in_circle", &LuaGetBeingsInCircle },
{ "note_on_death", &LuaNoteOnDeath },
+ { "effect_create", &LuaEffect_Create },
{ NULL, NULL }
};
luaL_register(mState, "tmw", callbacks);