diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-03-04 16:52:41 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-03-05 20:25:48 +0100 |
commit | d4f9a3370ed27cdae23da6f8c94c68619431cd48 (patch) | |
tree | b36d4895c4c48a20c94cb34917e49719f56a294f /src/scripting | |
parent | 9f67ba0e68d0a85944268c55045c28d6d12983b5 (diff) | |
download | manaserv-d4f9a3370ed27cdae23da6f8c94c68619431cd48.tar.gz manaserv-d4f9a3370ed27cdae23da6f8c94c68619431cd48.tar.bz2 manaserv-d4f9a3370ed27cdae23da6f8c94c68619431cd48.tar.xz manaserv-d4f9a3370ed27cdae23da6f8c94c68619431cd48.zip |
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.
Diffstat (limited to 'src/scripting')
-rw-r--r-- | src/scripting/lua.cpp | 40 |
1 files changed, 33 insertions, 7 deletions
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; } |