From d4f9a3370ed27cdae23da6f8c94c68619431cd48 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sun, 4 Mar 2012 16:52:41 +0100 Subject: Added possibility to make a being attack an other being This allows the script to let the character perform a scripted attack but the character still gets xp and killed monsters give drops. You can now call: mana.being_damage(target, dmg, dmg_delta, accurancy, type, element, source, skill) While on it I also added checks to the being_damage function. Reviewed-by: bjorn, Bertram. --- src/scripting/lua.cpp | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'src/scripting/lua.cpp') diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index f98fa849..bdbb3110 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1001,22 +1001,48 @@ static int being_say(lua_State *s) /** * mana.being_damage(Being* victim, int value, int delta, int cth, int type, - * int element): void + * int element [, Being* source [, int skill]]): void * Applies combat damage to a being. */ static int being_damage(lua_State *s) { Being *being = checkBeing(s, 1); + if (!being) + { + raiseScriptError(s, "being_damage called with invalid victim"); + return 0; + } if (!being->canFight()) + { + raiseScriptError(s, "being_damage called with " + "victim that cannot fight"); return 0; + } - Damage dmg((unsigned short) lua_tointeger(s, 2), /* base */ - (unsigned short) lua_tointeger(s, 3), /* delta */ - (unsigned short) lua_tointeger(s, 4), /* cth */ - (unsigned char) lua_tointeger(s, 6), /* element */ - DAMAGE_PHYSICAL); /* type */ - being->damage(NULL, dmg); + Damage dmg; + dmg.base = luaL_checkint(s, 2); + dmg.delta = luaL_checkint(s, 3); + dmg.cth = luaL_checkint(s, 4); + dmg.type = (DamageType)luaL_checkint(s, 5); + dmg.element = luaL_checkint(s, 6); + Being *source = 0; + if (lua_gettop(s) >= 7) + { + source = checkBeing(s, 7); + if (!source) + { + raiseScriptError(s, "being_damage called withd invalid source"); + } + if (!source->canFight()) + { + raiseScriptError(s, "being_damage called with " + "source that cannot fight"); + return 0; + } + } + dmg.skill = luaL_optint(s, 8, 0); + being->damage(source, dmg); return 0; } -- cgit v1.2.3-70-g09d2