Jump to content
WelshyYT

Arma 3 - Range Help!

Recommended Posts

Hey Everybody,

 

For the last week or so, I have been developing a Range for my unit. So far it is 50% Complete; the issue I have been getting/unable to figure out is, I want to have the target pop up and take 5 shots from the players weapon before falling. I have tried everything from disabling simulation to Hit Event handlers. But ye I have no idea on how to do it.

Share this post


Link to post
Share on other sites

I made this script to do that, not sure if it's the best approach but it works.

What the script does is that it deletes the target on hit and creates new one.

 

the code:

 

handleTargetHit = 
{
 _obj = _this select 0;
 _hitsLeft = (_obj getVariable "hitsLeft") - 1;
 
 player sideChat format["target hit %1", _hitsLeft];
 
 if(_hitsLeft <= 0) exitwith {};
 
 _type = typeof _obj;
 _pos = getpos _obj;
 _dir = getdir _obj;
 deleteVehicle _obj;
 _newObj = _type createVehicle _pos;
 _newObj setdir _dir;
 _newObj setpos _pos;
 
 [_newObj,_hitsLeft] call setupTarget;
};

setupTarget =
{
 params ["_target","_hitsLeft"];
 
_target addEventHandler ["hit", handleTargetHit];

_target setVariable ["hitsLeft", _hitsLeft];
};


[target1,5] call setupTarget; // Init target, target1 is name of the target placed in editor. The target takes 5 hits

 

put the code in init.sqf for example

Share this post


Link to post
Share on other sites

Okay m

On 1/7/2018 at 11:31 AM, gc8 said:

I made this script to do that, not sure if it's the best approach but it works.

What the script does is that it deletes the target on hit and creates new one.

 

the code:

 


handleTargetHit = 
{
 _obj = _this select 0;
 _hitsLeft = (_obj getVariable "hitsLeft") - 1;
 
 player sideChat format["target hit %1", _hitsLeft];
 
 if(_hitsLeft <= 0) exitwith {};
 
 _type = typeof _obj;
 _pos = getpos _obj;
 _dir = getdir _obj;
 deleteVehicle _obj;
 _newObj = _type createVehicle _pos;
 _newObj setdir _dir;
 _newObj setpos _pos;
 
 [_newObj,_hitsLeft] call setupTarget;
};

setupTarget =
{
 params ["_target","_hitsLeft"];
 
_target addEventHandler ["hit", handleTargetHit];

_target setVariable ["hitsLeft", _hitsLeft];
};


[target1,5] call setupTarget; // Init target, target1 is name of the target placed in editor. The target takes 5 hits

 

put the code in init.sqf for example

Thanks mate, I'll give it a try :)

Share this post


Link to post
Share on other sites

in init filed of an animated target:

 

0 = this spawn {
  params ["_tgt"];
  while {true} do {
    waitUntil {sleep 0.1; _tgt animationPhase "Terc" > 0};
    _tgt setVariable ["cnt", (_tgt getVariable ["cnt",0]) + 1, true];
    if ((_tgt getvariable "cnt") mod 5 != 0) then {
      _tgt animateSource ["terc",0,true]};
    waitUntil {sleep 0.1; _tgt animationPhase "Terc" == 0};
  }
};

 

There is no available EH for this kind of object (EPEContact, damage, hit, animationChanged... don't work,)

UPDATED : as GC8 says, hit is a working EH (see below).

I tried to write something with onEachFrame EH, but it's more complex than it appears.

So, keep it simple with a loop.

  • Like 1

Share this post


Link to post
Share on other sites

@pierremgi that looks like I good approach, but addEventHandler "hit" does work with the target object, check my code.

 

Share this post


Link to post
Share on other sites

@gc8 Yes! Good point. I don't know why I failed to "hit" this EH. (note: your approach is not repeatable due to the countdown)

So, code is simple as:

 

this addEventHandler ["hit", {
  params ["_tgt"];
  _tgt spawn {
    params ["_tgt"];
    _tgt setVariable ["cnt", (_tgt getVariable ["cnt",0]) + 1, true];
    sleep 0.1;
    if ((_tgt getvariable "cnt") mod 5 != 0) then {
      _tgt animateSource ["terc",0,true]
    };
  }
}];

in init field of the target.

 

@WelshyYT You have choice between loop or EH solutions.

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×