Jump to content
Sign in to follow this  
creartan

add EH hit, will switchmove unit

Recommended Posts

i want to put this inside unit (unplayable ai) initialization

the code is bleow, but its not working, can someone point out wheres the error?

this addEventHandler ["hit",
"if (damage this >= 0.9) then
{ [east,-2] call BIS_fnc_respawnTickets; this SetUnitPos 'down';
this switchMove 'AinjPpneMrunSnonWnonDb_still';
this disableAI 'ANIM';
this setCaptive true;
this globalchat 'Ai Wounded -2';
sleep 30;
if (damage this >= 0.9) then
{this hideobject true;
this setposATL getposATL base;} else {false};}
else {false};"]

Share this post


Link to post
Share on other sites

"this" doesnt work inside an Eventhandler. Replace "this" with "_this select 0" and it should work, as _this select 0 references the unit that was hit. Also you've got a double else false statement in there. That won't work.

More info: https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Hit

Share this post


Link to post
Share on other sites

not working, already change _unit = _this select 0, the EH is not firing event giving it huge damage

 this addEventHandler ["hit","if (damage _this select 0 >= 0.8) then { _unit = _this select 0;[east,-2] call BIS_fnc_respawnTickets; _unit SetUnitPos 'down';  _unit switchMove 'AinjPpneMrunSnonWnonDb_still';  _unit disableAI 'ANIM'; _unit setCaptive true;  _unit globalchat 'Ai Wounded -2'; sleep 30; if (damage _unit >= 0.8) then {_unit hideobject true; _unit setposATL getposATL base;}} else {false};"]; 

---------- Post added at 17:59 ---------- Previous post was at 17:49 ----------

i make a tweak the "" is not needed after EH

this addEventHandler ["hit",{_unit = _this select 0; if (damage _unit >= 0.8) then {[east,-2] call BIS_fnc_respawnTickets; _unit SetUnitPos 'down';  _unit switchMove 'AinjPpneMrunSnonWnonDb_still';  _unit disableAI 'ANIM'; _unit setCaptive true;  _unit globalchat 'Ai Wounded -2'; sleep 30; if (damage _unit >= 0.8) then {_unit hideobject true; _unit setposATL getposATL base;}} else {false};}];

and now its working, but the sleep thing is not working

Share this post


Link to post
Share on other sites

unit init

this addEventHandler ["hit","(_this select 0) execVM 'hit.sqf'"]; 
/*
OR
this addEventHandler ["hit",{(_this select 0) execVM "hit.sqf"}]; 
*/

hit.sqf

private ["_side"];

_side = side _this;

if ((damage _this) >= 0.8) then { 

[_side,-2] call BIS_fnc_respawnTickets; 
_this SetUnitPos "down";  
_this switchMove "AinjPpneMrunSnonWnonDb_still";  
_this disableAI "ANIM"; 
_this setCaptive true;  
_this globalchat "Ai Wounded -2"; 
sleep 30; 
if ((damage _this) >= 0.8) then {
	_this hideobject true;
	_this setposATL (getposATL base);
}	
} else {
false
};

Edited by Iceman77
Took out redundant code

Share this post


Link to post
Share on other sites

wow, its working iceman..

the unit is now down when get hit.

but afterthe hit EH run, now the game says that my side is lose immediately

iceman would you explain about the,

private ["_side"];

_side = side _this;

what is that code do?

what is private?

why side?

what is _this?

sorry i get verry exited to know about the scripting now :)

Share this post


Link to post
Share on other sites

private is declaring the scope(s) inwhich the local variable can be used within the script. I always do it just in good practice and declare variables scopes in the scopes they are actually used in etc. _this is what was passed to the script. In your case the unit that was hit (_this select 0) was passed to the script. Google eventhandlers for arma and take a look at what arguments the EHs are passed to the script / code space of the EH. There are several eventhandlers too.

It says you're side is losing immediately because your tickets fell below 0.

Share this post


Link to post
Share on other sites

it just decrese by -2 than the losing screen pop up with ticket still 300

---------- Post added at 22:41 ---------- Previous post was at 22:38 ----------

if ((damage _this) >= 0.8) then 
{ 
   [east,-1] call BIS_fnc_respawnTickets; 
   _this SetUnitPos "down";  
   _this switchMove "AinjPpneMrunSnonWnonDb_still";  
   _this disableAI "ANIM"; 
   _this setCaptive true;
_this globalchat "Ai Wounded -1";
sleep 10;
   if ((damage _this) >= 0.8 and (side _this) == east) then 
   {
       _this hideobject true;
       _this setposATL (getposATL basepp);
   };    
} 
else 
{false};

hey if im going to put the side thing, where to put it?

i put

if ((damage _this) >= 0.8 and (side _this) == east) then

but seems not working

and the globalchat it stuttering, is there any alternative than globalchat to tell the wounded event?

Share this post


Link to post
Share on other sites

hey if im going to put the side thing, where to put it?

i put

if ((damage _this) >= 0.8 and (side _this) == east) then

but seems not working

and the globalchat it stuttering, is there any alternative than globalchat to tell the wounded event?

if ((damage _this >= 0.8) && (side _this == EAST)) then {};

Share this post


Link to post
Share on other sites

if ((damage _this >= 0.8) && (side _this == EAST)) then {};

still not working, any other alternative?

and is there any alternative for the globalchat so it will not stutter?

it repetedly send the global chat for 3 times even i just put one time

Share this post


Link to post
Share on other sites

If the unit is dead, his side defaults to civilian. Maybe that's causing some problems. It's a fine line between 0.8 and dead. You could be killing the unit when you're shooting him for testing? Not sure what you mean by "globalChat stuttering".

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
Sign in to follow this  

×