Jump to content

Recommended Posts

Hi all,
I have a problem that does not allow me to live in peace, I try to make an event that when a vehicle receives an amount of damage a variable is TRUE and I mark a specific action, but every time I enter the map to try the script something It goes wrong and I do not know what it would be.

Someone help me? here the script that I have made.

 

//initDamageVeh.sqf

_granDamage = false;

dispo1 addEventHandler ["Hit", 
{
	params ["_unit", "_source", "_damage", "_instigator"];
	
	dispo1 setdamage 0.10;
	veh = getDammage dispo1;

	if (veh => 0.30) then {
		_granDamage = true;
	};

}];

 

Share this post


Link to post
Share on other sites
Quote

The hit EH will not necessarily fire if only minor damage occurred (e.g. firing a bullet at a tank), even though the damage increased.

 

The HandleDamage EH might be a better choice? 

 

Also, why are you using global variables inside your EH? 

  • Like 2

Share this post


Link to post
Share on other sites

Make your variable global (even public if MP).

replace everywhere _granDamage by something like:  RBN_granDamage

 

 

RBN_granDamage = false;

dispo1 addEventHandler ["HandleDamage", {

  RBN_granDamage = true;

0.1

}];

 

should work as is... depending on what you want exactly!

  • Like 2

Share this post


Link to post
Share on other sites
8 minutes ago, redburn said:

Hi all,
I have a problem that does not allow me to live in peace, I try to make an event that when a vehicle receives an amount of damage a variable is TRUE and I mark a specific action, but every time I enter the map to try the script something It goes wrong and I do not know what it would be.

Someone help me? here the script that I have made.

 


//initDamageVeh.sqf

_granDamage = false;

dispo1 addEventHandler ["Hit", 
{
	params ["_unit", "_source", "_damage", "_instigator"];
	
	dispo1 setdamage 0.10;
	veh = getDammage dispo1;

	if (veh => 0.30) then {
		_granDamage = true;
	};

}];

 

 

That entire snippet doesn't make sense.

At all.

 

At first you don't need global variables, when you could simply use the _unit parameter that's being passed inside the EHs code.

Then you manually set the damage of the vehicle to 0.1, yet check with an if statement if the damage is (what I presume) bigger than 0.3, which will only be true if the vehicle gets destroyed with one hit (big explosive charge or tank hit might do that).

The check of the damage isn't proper syntax, you're using =>, which might pass as a smily face, but not as bool comparison, you might want to use >= instead.

Then inside the if statement you set a local variable to true, which can't be accessed anywhere outside the scope where it has been defined, namely the if statement inside that EH.

 

To top it off the variable names are all over the place, you'd want them named in a way that makes it obvious what they contain and as best practice add a tag to them to prevent conflicts with other scripts/addOns.

The vehicle could be called RBN_obj_dispo1 (whith RBN being short for redburn), the global variable to handle the damage check could be called RBN_flag_dispo1Damaged or similar.

 

I suggest taking a look at some basic scripting guides first before attempting something like that, heh.

 

What exactly do you want to accomplish? In your post you state that you want to check for damage, but in the snippet you manually set the damage of the object.

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites
1 minute ago, Harzach said:

 

The HandleDamage EH might be a better choice? 

 

Also, why are you using global variables inside your EH? 

 

What I need is that: when a vehicle receives damage a number of times, then a mission passes as failed!

that's why he had calculated that if he received an amount X of damage then the following will be activated.

Share this post


Link to post
Share on other sites
1 minute ago, Grumpy Old Man said:

 

That entire snippet doesn't make sense.

At all.

 

At first you don't need global variables, when you could simply use the _unit parameter that's being passed inside the EHs code.

Then you manually set the damage of the vehicle to 0.1, yet check with an if statement if the damage is (what I presume) bigger than 0.3, which will only be true if the vehicle gets destroyed with one hit (big explosive charge or tank hit might do that).

The check of the damage isn't proper syntax, you're using =>, which might pass as a smily face, but not as bool comparison, you might want to use >= instead.

Then inside the if statement you set a local variable to true, which can't be accessed anywhere outside the scope where it has been defined, namely the if statement inside that EH.

 

To top it off the variable names are all over the place, you'd want them named in a way that makes it obvious what they contain and as best practice add a tag to them to prevent conflicts with other scripts/addOns.

The vehicle could be called RBN_obj_dispo1 (whith RBN being short for redburn), the global variable to handle the damage check could be called RBN_flag_dispo1Damaged or similar.

 

I suggest taking a look at some basic scripting guides first before attempting something like that, heh.

 

What exactly do you want to accomplish? In your post you state that you want to check for damage, but in the snippet you manually set the damage of the object.

 

Cheers

 

what happens is that I'm still a novice and I'm learning how to do event handlers, and I'm still a little ignorant of the situation

Share this post


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

Make your variable global (even public if MP).

replace everywhere _granDamage by something like:  RBN_granDamage

 

 

RBN_granDamage = false;

dispo1 addEventHandler ["Hit", {

  RBN_granDamage = true;

0.1

}];

 

should work as is... depending on what you want exactly!

As I had mentioned above, what I'm looking for is for you to do the following:

 

when a vehicle receives damage a number of times, then a mission passes as failed!

that's why he had calculated that if he received an amount X of damage then the following will be activated.

Share this post


Link to post
Share on other sites

Well, which is it - damaged X number of times, or damaged X amount?

Share this post


Link to post
Share on other sites
Just now, Harzach said:

Well, which is it - damaged X number of times, or damaged X amount?

 

0.30 or more amount

Share this post


Link to post
Share on other sites
5 minutes ago, redburn said:
6 minutes ago, Harzach said:

Well, which is it - damaged X number of times, or damaged X amount?

 

0.30 or more amount

 

wBVOrZv.jpg

 

 

Spoiler

:yay:

 

  • Haha 1

Share this post


Link to post
Share on other sites
3 minutes ago, Grumpy Old Man said:

 

wBVOrZv.jpg

 

 

  Reveal hidden contents

:yay:

 

 

that is, a random amount, not less than 0.3

 

I'm sorry not to explain myself correctly.

Share this post


Link to post
Share on other sites
2 minutes ago, redburn said:

 

that is, a random amount, not less than 0.3

 

I'm sorry not to explain myself correctly.

Kidding aside, you want a variable to turn true once a vehicle is damaged more than 0.3?

Why not just:
 

RBN_granDamage = false; 
waitUntil {damage dispo1 >= 0.3};
RBN_granDamage = true; 
//do stuff

Cheers

Share this post


Link to post
Share on other sites
Just now, Grumpy Old Man said:

Kidding aside, you want a variable to turn true once a vehicle is damaged more than 0.3?

Why not just:
 


RBN_granDamage = false; 
waitUntil {damage dispo1 >= 0.3};
RBN_granDamage = true; 
//do stuff

Cheers

 

Thanks, is that I still try to learn about the scope of everything, I wanted to learn about the events and that's why I was doing an EH, but you're also right if I simplify in that way, I still have a long way to go, but I do not I faint for things that I still do not understand at all, little by little I will understand it.

There is a book that I have that talks about the use of variables and other things, but does not speak for example of the white list and that I would also like to learn, if you have something that I can use to learn it more thoroughly I would thank you very much and thank you for aid.

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

×