redburn 20 Posted October 14, 2018 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
Harzach 2505 Posted October 14, 2018 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? 2 Share this post Link to post Share on other sites
pierremgi 4736 Posted October 14, 2018 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! 2 Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted October 14, 2018 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 2 Share this post Link to post Share on other sites
redburn 20 Posted October 14, 2018 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
redburn 20 Posted October 14, 2018 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
redburn 20 Posted October 14, 2018 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
Harzach 2505 Posted October 14, 2018 Well, which is it - damaged X number of times, or damaged X amount? Share this post Link to post Share on other sites
redburn 20 Posted October 14, 2018 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
Grumpy Old Man 3540 Posted October 14, 2018 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 Spoiler 1 Share this post Link to post Share on other sites
redburn 20 Posted October 14, 2018 3 minutes ago, Grumpy Old Man said: Reveal hidden contents 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
Grumpy Old Man 3540 Posted October 14, 2018 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
redburn 20 Posted October 14, 2018 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
Grumpy Old Man 3540 Posted October 14, 2018 Well for starters I recommend the guide from Mr Murray, should still hold true for A3. Depends on your native language there might be other options though. Cheers Share this post Link to post Share on other sites