From b538813c2488c2dd4177b84e81837a8a4908ae90 Mon Sep 17 00:00:00 2001 From: Andrey Voitishin Date: Tue, 16 Dec 2014 02:31:12 -0500 Subject: [PATCH] + Actor hit script callback --- res/gamedata/scripts/bind_stalker.script | 23 +++++++++++++++++++++ src/xrGame/Actor.cpp | 26 +++++++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/res/gamedata/scripts/bind_stalker.script b/res/gamedata/scripts/bind_stalker.script index a74523d44fb..50e5f0149d1 100644 --- a/res/gamedata/scripts/bind_stalker.script +++ b/res/gamedata/scripts/bind_stalker.script @@ -85,6 +85,11 @@ function actor_binder:net_destroy() self.object:set_callback(callback.take_item_from_box, nil) self.object:set_callback(callback.use_object, nil) + ----| aVo |-------------------------------------------------------------------- + self.object:set_callback(callback.hit, nil) + --self.object:set_callback(123, nil) + ----| end:aVo |---------------------------------------------------------------- + log("--------->"..tostring(_G.amb_vol)) log("--------->"..tostring(_G.mus_vol)) if(_G.amb_vol~=0) then @@ -118,7 +123,25 @@ function actor_binder:reinit() self.object:set_callback(callback.task_state, self.task_callback, self) self.object:set_callback(callback.take_item_from_box, self.take_item_from_box, self) self.object:set_callback(callback.use_object, self.use_inventory_item, self) + + ----| aVo |-------------------------------------------------------------------- + self.object:set_callback(callback.hit, self.actor_hit, self) + -- self.object:set_callback(123, self.key_press, self) + ----| end:aVo |---------------------------------------------------------------- +end +--------------------------------------------------------------------------------------------------------------------- + + +----| aVo |-------------------------------------------------------------------- +-- Actor hit callback +function actor_binder:actor_hit(obj, amount, local_direction, who, bone_index) + -- local msg = string.format("actor_hit %f, %i", amount, bone_index) + -- get_console():execute("load ~:"..msg) end +-- x-ray extensions key press callback +--function actor_binder:key_press(key) + --sm:call("key_press", key) +--end ---------------------------------------------------------------------------------------------------------------------- function actor_binder:take_item_from_box(box, item) local box_name = box:name() diff --git a/src/xrGame/Actor.cpp b/src/xrGame/Actor.cpp index ebbc800efff..f1f7997cebe 100644 --- a/src/xrGame/Actor.cpp +++ b/src/xrGame/Actor.cpp @@ -560,20 +560,27 @@ void CActor::Hit(SHit* pHDS) if (IsGameTypeSingle()) { - float hit_power = HitArtefactsOnBelt(HDS.damage(), HDS.hit_type); - if (GodMode()) { HDS.power = 0.0f; inherited::Hit(&HDS); - return; } - else + + float hit_power = HitArtefactsOnBelt(HDS.damage(), HDS.hit_type); + HDS.power = hit_power; + HDS.add_wound = true; + if (g_Alive()) { - HDS.power = hit_power; - HDS.add_wound = true; - inherited::Hit(&HDS); + /* AVO: send script callback*/ + callback(GameObject::eHit)( + this->lua_game_object(), + HDS.damage(), + HDS.direction(), + smart_cast(HDS.who)->lua_game_object(), + HDS.boneID + ); } + inherited::Hit(&HDS); } else { @@ -686,6 +693,11 @@ void CActor::HitSignal(float perc, Fvector& vLocalDir, IGameObject* who, s16 ele { if (g_Alive()) { + /* AVO: to get bone names from IDs*/ + /*Log("hit info"); + Log("bone ID = %s", element); + Log("bone Name = %s", smart_cast(this->Visual())->LL_BoneName_dbg(element)); + Log("hit info END");*/ // check damage bone Fvector D; XFORM().transform_dir(D, vLocalDir);