summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2011-03-14 20:53:49 +0100
committerPhilipp Sehmisch <mana@crushnet.org>2011-03-14 21:47:09 +0100
commit967caa8a91702510fc9b4a35292042802c27d14c (patch)
treeaa0961174ed5b180163ffb972adcf5007513722e
parentcc162d170bcaf7d5b3f47ffde346b1849f905662 (diff)
downloadmanaserv-967caa8a91702510fc9b4a35292042802c27d14c.tar.gz
manaserv-967caa8a91702510fc9b4a35292042802c27d14c.tar.xz
manaserv-967caa8a91702510fc9b4a35292042802c27d14c.zip
Script binding for the new screen shake effect.
The new lua function mana.chr_shake_screen can cause a screen shake for a single client with variable x-intensity, y-intensity, decay and duration. I also added an example script which causes tremors for nearby characters with intensity and direction relative to a specific point. The function is not referenced on the example map because it is quite distracting.
-rw-r--r--example/serverdata/scripts/npcs/shaker.lua48
-rw-r--r--src/manaserv_protocol.h1
-rw-r--r--src/scripting/lua.cpp45
3 files changed, 94 insertions, 0 deletions
diff --git a/example/serverdata/scripts/npcs/shaker.lua b/example/serverdata/scripts/npcs/shaker.lua
new file mode 100644
index 0000000..9d7bafb
--- /dev/null
+++ b/example/serverdata/scripts/npcs/shaker.lua
@@ -0,0 +1,48 @@
+----------------------------------------------------------------------------------
+-- Copyright 2009-2010 The Mana World Development Team --
+-- --
+-- This file is part of The Mana World. --
+-- --
+-- The Mana World 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. --
+----------------------------------------------------------------------------------
+
+shake_count = 0
+
+function shaker_update(npc)
+ shake_count = shake_count + 1
+ if shake_count > 20 then
+ shake_count = 0
+
+ center_x = mana.posX(npc)
+ center_y = mana.posY(npc)
+ tremor(center_x, center_y, 300)
+
+ end
+end
+
+-- function which causes a screen shake effect for all players near a
+-- certain point with an intensity and direction relative to said point
+function square(x)
+ return x * x
+end
+
+function tremor (center_x, center_y, intensity)
+ for dummy, object in ipairs(mana.get_beings_in_circle(center_x, center_y, intensity)) do
+ if mana.being_type(object) == TYPE_CHARACTER then
+ object_x = mana.posX(object)
+ object_y = mana.posY(object)
+ dist_x = object_x - center_x
+ dist_y = object_y - center_y
+ dist = math.sqrt(square(dist_x) + square(dist_y))
+ intensity_local = intensity - dist
+ intensity_x = (intensity - dist) * (dist_x / dist) / 5
+ intensity_y = (intensity - dist) * (dist_y / dist) / 5
+ mana.chr_shake_screen(object, intensity_x, intensity_y)
+ end
+ end
+end
+
+
+
diff --git a/src/manaserv_protocol.h b/src/manaserv_protocol.h
index 978187d..337f2e2 100644
--- a/src/manaserv_protocol.h
+++ b/src/manaserv_protocol.h
@@ -163,6 +163,7 @@ enum {
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
GPMSG_CREATE_EFFECT_POS = 0x0320, // W effect id, W*2 position
GPMSG_CREATE_EFFECT_BEING = 0x0321, // W effect id, W BeingID
+ GPMSG_SHAKE = 0x0330, // W intensityX, W intensityY, [W decay_times_10000, [W duration]]
// Guild
PCMSG_GUILD_CREATE = 0x0350, // S name
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 6f36bb9..11f42f5 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1395,6 +1395,50 @@ static int effect_create(lua_State *s)
return 0;
}
+
+
+/**
+ *
+ * mana.chr_shake_screen(
+ */
+static int chr_shake_screen(lua_State *s)
+{
+ Character *c = getCharacter(s, 1);
+ if (!c)
+ {
+ raiseScriptError(s, "lua chr_shake_screen called for nonexistent character.");
+ return 0;
+ }
+
+ MessageOut msg(GPMSG_SHAKE);
+ if(!lua_isnumber(s, 2) || !lua_isnumber(s, 3))
+ {
+ raiseScriptError(s, "lua chr_shake_screen called with illegal arguments.");
+ return 0;
+ }
+ else
+ {
+ int x = lua_tointeger(s, 2);
+ int y = lua_tointeger(s, 3);
+ msg.writeInt16(x);
+ msg.writeInt16(y);
+ }
+ if(lua_isnumber(s, 4))
+ {
+ msg.writeInt16((int)lua_tonumber(s, 4) * 10000);
+ }
+ if(lua_isnumber(s, 5))
+ {
+ msg.writeInt16(lua_tointeger(s, 5));
+ }
+ c->getClient()->send(msg);
+
+ return 0;
+}
+
+
+
+
/**
* Gets the exp total in a skill of a specific character
* mana.chr_get_exp (being, skill)
@@ -1840,6 +1884,7 @@ LuaScript::LuaScript():
{ "get_beings_in_circle", &get_beings_in_circle },
{ "being_register", &being_register },
{ "effect_create", &effect_create },
+ { "chr_shake_screen", &chr_shake_screen },
{ "test_tableget", &test_tableget },
{ "get_map_id", &get_map_id },
{ "item_drop", &item_drop },