Jump to content
vallfield

Need Help! How to make damage x useful in If type.

Recommended Posts

Hi,

I wanted to use in my code something like this:

if (damage x > 0) then {//code };

But seems like it doesn't work like that, someone could explain?

Share this post


Link to post
Share on other sites

This work if you call the code in due time. In other word, a if.. then.. check once, not repeatedly like in a loop.

You can use a loop like while {something true} do { waitUntil {damage..};  or if (damage ...] then {...} ... };

 

or better, use an event handler ("hit" or "handleDamage"...)

 

NB: x is not an accurate variable like in math. use _x in a foreach loop or something defined before: player, myUnit...

Share this post


Link to post
Share on other sites

If you are referring to the magic variable _x then you'd have to use _x instead of x.

Also only the damage of objects that can be damaged can be returned. I'd need some more information on what you are doing.

Try to use brackets ():

if ((damage x) > 0) then {/*CODE*/};

Example from the wiki:

if ((damage player) > 0.1) then { 
    player groupChat "I'm hurt! Medic!"; 
};

 

Share this post


Link to post
Share on other sites
56 minutes ago, pierremgi said:

This work if you call the code in due time. In other word, a if.. then.. check once, not repeatedly like in a loop.

You can use a loop like while {something true} do { waitUntil {damage..};  or if (damage ...] then {...} ... };

 

or better, use an event handler ("hit" or "handleDamage"...)

 

NB: x is not an accurate variable like in math. use _x in a foreach loop or something defined before: player, myUnit...

 

52 minutes ago, 7erra said:

If you are referring to the magic variable _x then you'd have to use _x instead of x.

Also only the damage of objects that can be damaged can be returned. I'd need some more information on what you are doing.

Try to use brackets ():


if ((damage x) > 0) then {/*CODE*/};

Example from the wiki:


if ((damage player) > 0.1) then { 
    player groupChat "I'm hurt! Medic!"; 
};

 

 

I wanted to use it on a transmitter tower, to get to blow it up with just one normal charge, the brackets didn't work.

Also tried with a while loop but same result. It seems like  it doesn't read it if you use damage x.

I don't really understand how the event handler work.  :/

Share this post


Link to post
Share on other sites
tower addEventHandler ["Explosion", {if (_this select 1 > 0.7) then {(_this select 0) setDamage 1;}}];

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Explosion

 

The arguments used are:

_this select 0: The tower itself

_this select 1: Damage done to the tower by an explosion (for Explosive Charge and Explosive Satchel roughly 0.8)

 

If the tower is a map object you have to do the following:

// Transmitter tower
_tower = nearestObject [position, "Land_TTowerBig_1_F"];
_tower addEventHandler ["Explosion", {if (_this select 1 > 0.7) then {(_this select 0) setDamage 1;}}];

// Transmitter tower (tall)
_tower = nearestObject [position, "Land_TTowerBig_2_F"];
_tower addEventHandler ["Explosion", {if (_this select 1 > 0.7) then {(_this select 0) setDamage 1;}}];

https://community.bistudio.com/wiki/nearestObject

 

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, 7erra said:

tower addEventHandler ["Explosion", {if (_this select 1 > 0.7) then {(_this select 0) setDamage 1;}}];

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Explosion

 

The arguments used are:

_this select 0: The tower itself

_this select 1: Damage done to the tower by an explosion (for Explosive Charge and Explosive Satchel roughly 0.8)

 

If the tower is a map object you have to do the following:


// Transmitter tower
_tower = nearestObject [position, "Land_TTowerBig_1_F"];
_tower addEventHandler ["Explosion", {if (_this select 1 > 0.7) then {(_this select 0) setDamage 1;}}];

// Transmitter tower (tall)
_tower = nearestObject [position, "Land_TTowerBig_2_F"];
_tower addEventHandler ["Explosion", {if (_this select 1 > 0.7) then {(_this select 0) setDamage 1;}}];

https://community.bistudio.com/wiki/nearestObject

 

 

It works! Thanks! And now I know how the EH arrays works! Thank you very much!

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

×