QuiveringT 11 Posted September 20, 2017 I need to blow up some tanks with rockets from a helicopter but the rockets are not strong enough. What is the best way to achieve this? The helicopter I am using does not incorporate the new payload-changing system. Share this post Link to post Share on other sites
Tajin 349 Posted September 20, 2017 You could simple change weapons with the removeWeapon addWeapon addMagazine commands. Or if you want the same weapon to be shown, you can also exchange the rocket when it's beeing fired. (only good for dumbfire weapons) https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Fired You could also add HandleDamage eventhandlers to your tanks to make them generally easier to destroy. Or spawn your tanks with reduced health. It's up to you to decide which solution you like best, these are just some examples. Share this post Link to post Share on other sites
JohnKalo 657 Posted September 20, 2017 Or to be sure nameoftank setdamage 1; after a certain time period or when the helicopter is out of ammo or something like that Share this post Link to post Share on other sites
7erra 629 Posted September 20, 2017 this addEventHandler ["HandleDamage",{ if (_this select 4 == "classname_of_your_rocket") then {1}; }]; Put this in the init of the tank. Change the "classname_of_your_rocket" to the according classname. You can get it by first adding this EH to the tank: this addEventHandler ["HandleDamage",{ systemchat (_this select 4); }]; 1 Share this post Link to post Share on other sites
QuiveringT 11 Posted September 20, 2017 11 hours ago, Tajin said: Or if you want the same weapon to be shown, you can also exchange the rocket when it's beeing fired. (only good for dumbfire weapons) https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Fired I believe this solution would work best for my situation. How would I do this? Share this post Link to post Share on other sites
Tajin 349 Posted September 21, 2017 something like this: yourHeli addEventHandler["fired", { params["_unit","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_gunner"]; if !(_weapon isEqualTo "missiles_DAR") exitWith {}; private ["_pos","_projectile","_vecup","_vecdir","_dir","_vel"]; _pos = getpos _projectile; _vecup = vectorup _projectile; _vecdir = vectordir _projectile; _dir = direction _projectile; _vel = velocity _projectile; deleteVehicle _projectile; _new = "Rocket_04_HE_F" createVehicle _pos; _new setpos _pos; _new setvelocity _vel; _new setdir _dir; _new setvectorup _vecup; _new setvectordir [0,0,0]; }; Ull have to adjust the classnames of course. A lot of magic can be done with those fired eventhandlers. (even some very weird things that normally don't make sense but are fun to try) 1 Share this post Link to post Share on other sites
QuiveringT 11 Posted September 21, 2017 (edited) yourHeli addEventHandler["fired", { params["_unit","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_gunner"]; if (! _weapon isEqualTo "missiles_DAR") exitWith {}; private ["_pos","_projectile","_vecup","_vecdir","_dir","_vel"]; _pos = getpos _projectile; _vecup = vectorup _projectile; _vecdir = vectordir _projectile; _dir = direction _projectile; _vel = velocity _projectile; deleteVehicle _projectile; _new = "Rocket_04_HE_F" createVehicle _pos; _new setpos _pos; _new setvelocity _vel; _new setdir _dir; _new setvectorup _vecup; _new setvectordir [0,0,0]; }; Can you elaborate as far as how much of this I will need to replace for my specific situation? Also, where would be the best place to store this code in the scenario? Edited September 21, 2017 by QuiveringT Share this post Link to post Share on other sites
Tajin 349 Posted September 21, 2017 Replace yourHeli with whatever varname you've given your helicopter. Replace "missiles_DAR" with whatever weapon the helicopter is using originally (the example is for an AH9 Pawnee). Replace "Rocket_04_HE_F" with whatever rocket or projectile you want to use instead. Then just put the whole thing in the initServer.sqf Share this post Link to post Share on other sites
QuiveringT 11 Posted September 23, 2017 I tried the code using my chopper and the Pawnee and it doesn't work either way. The tanks still list the original ammo when they output the damage in system chat. I put the code in an init.sqf instead of an initServer.sqf, but that didn't make a difference either. Share this post Link to post Share on other sites
QuiveringT 11 Posted September 27, 2017 On 9/21/2017 at 5:01 AM, Tajin said: Replace yourHeli with whatever varname you've given your helicopter. Replace "missiles_DAR" with whatever weapon the helicopter is using originally (the example is for an AH9 Pawnee). Replace "Rocket_04_HE_F" with whatever rocket or projectile you want to use instead. Then just put the whole thing in the initServer.sqf Since this solution doesn't work, alternatively I would like to add damage incrementally to the tanks when they receive damage. On 9/20/2017 at 9:59 AM, 7erra said: this addEventHandler ["HandleDamage",{ if (_this select 4 == "classname_of_your_rocket") then {1}; }]; Something like this would work, except of course this code would simply blow up all the tanks if there was a rocket even remotely close to hitting. Share this post Link to post Share on other sites
Tajin 349 Posted September 27, 2017 Simply havent tested that code so it may contain some minor errors. So just enable script errors (which you should anyway), see what comes up and correct them. The basic idea is solid. Share this post Link to post Share on other sites
7erra 629 Posted September 27, 2017 To prevent the tanks from blowing up because of minor damage you can add a damage threshhold: this addEventHandler ["HandleDamage",{ if (_this select 4 == "classname_of_your_rocket" && _this select 2 > 0.5) then {1}; }]; 1 Share this post Link to post Share on other sites
QuiveringT 11 Posted September 29, 2017 On 9/27/2017 at 1:39 AM, Tajin said: Simply havent tested that code so it may contain some minor errors. So just enable script errors (which you should anyway), see what comes up and correct them. The basic idea is solid. I'm not experienced enough with scripting to really get that code working on my own. Can you come up with a working solution please? That is still my best option, but if not, I will have to explore the other options. Adding the damage threshold would help, is there a way to add damage incrementally instead of setting it to a value? Share this post Link to post Share on other sites
7erra 629 Posted September 29, 2017 Okay here are the basics: An eventhandler is a piece of code that is executed everytime the event happens. HandleDamage fires when a unit receives damage. Every EH has arguments passed to the script. They can be found here: Arma 3: Event Handlers. The parameters for HandleDamage can be found here. Furthermore, if you return a number at the end of the HandleDamage EH this number will be the new damage. damage >= 1 will kill the object. To increase the damage incrementally we can do some simple math: this addEventHandler ["HandleDamage",{ _rocketClassname = _this select 4; _damage = _this select 2; if (_rocketClassname == "classname_of_your_rocket") then { _damage * 2 }; }]; With this code in the init line of the tank, the tank will receive double the damage when hit by a rocket with your classname. You can adjust the "2" to lower or higher values. I usually test my code even when I'm sure it works. Multiplayer is a different story though. 1 Share this post Link to post Share on other sites
QuiveringT 11 Posted October 3, 2017 On 9/29/2017 at 6:27 AM, 7erra said: this addEventHandler ["HandleDamage",{ _rocketClassname = _this select 4; _damage = _this select 2; if (_rocketClassname == "classname_of_your_rocket") then { _damage * 2 }; }]; With this code in the init line of the tank, the tank will receive double the damage when hit by a rocket with your classname. You can adjust the "2" to lower or higher values. I usually test my code even when I'm sure it works. Multiplayer is a different story though. I've been toying with this and it seems to do what I want. I will probably belay my need to change the projectiles unless I need more control for whatever reason. Setting the damage tank side like this also preserves the missile sound effects and such, so that's nice. The damage value multiplied seems to be quite finicky, but I'm still finding the sweet spot for the damage. As for my original question, I believe a friend of mine has solved it to a degree and I will post the code if I can confirm it works. Share this post Link to post Share on other sites
QuiveringT 11 Posted October 4, 2017 To successfully swap projectiles on a vehicle's weapon, you can use this code in an init.sqf and most likely an initServer.sqf: weapon_name = "HMG_127_APC"; replacement_ammo = "Rocket_04_HE_F"; apc1 addEventHandler ["fired", { params["_unit","_weapon","_muzzle","_mode","_ammo","_maga zine","_projectile","_gunner"]; hint format ["Fired Weapon: %1 - %2", _weapon, _ammo]; if (_weapon == weapon_name) then { private ["_pos","_priv_projectile","_vecup","_vecdir","_dir ","_vel"]; _pos = getpos _projectile; _vecup = vectorup _projectile; _vecdir = vectordir _projectile; _dir = direction _projectile; _vel = velocity _projectile; deleteVehicle _projectile; _new = replacement_ammo createVehicle _pos; _new setpos _pos; _new setvelocity _vel; _new setdir _dir; _new setvectorup _vecup; _new setvectordir [0,0,0]; }; }]; To verify that the projectile is swapped, you can use 7erra's code for the init line of the vehicle you wish to fire at, which will display the projectile in systemchat. Of course if it works, your new projectile will be listed and if not, the old one will be: this addEventHandler ["HandleDamage",{ systemchat (_this select 4); }]; Simply change "weapon_name" and "replacement_ammo" to whatever the current weapon is and the new ammo you want it to fire, and change your vehicle variable name to "apc1" or some other name. The original example is for the NATO IFV-6 Panther, and you can immediately verify that it works because the Panther will take damage. In addition, I tested it using a UH-1H from the Air Car Vietnam workshop mod, and that worked as well. The UH-1H did not suffer any damage when firing, and this appears to be dependent on the types of weapons that are already mounted on the vehicle (which I believe you can change through a similar process). I exchanged a rocket for another rocket on the UH-1H, whereas for the Panther you are exchanging a much smaller round for a rocket. This would be something to play around with for you specific needs. The "hint format" line of code is just a super simple way to defeat having to go to the config menu to find the weapon you are currently using, so you can delete it. In addition, I discovered that changing the projectile will not change the firing sound. It seems like common sense to me now, but it's something to keep in mind if you are new to scripting like me. To recap: You can use this code to swap the projectile thus changing the strength of a heli's rocket, or you can use 7erra's code quoted in my last post that simply scales outgoing damage up or down. Share this post Link to post Share on other sites
pierremgi 4898 Posted October 5, 2017 Alternate solution: swap at the end (when projectile disappear). Lighter code. 1 Share this post Link to post Share on other sites
Jnr4817 215 Posted October 5, 2017 23 hours ago, pierremgi said: Alternate solution: swap at the end (when projectile disappear). Lighter code. This is absolutely the best thing I've seen all day. Great work. Did you use timetolive to define when the projectile despawns? Thanks, Reed Share this post Link to post Share on other sites
7erra 629 Posted October 5, 2017 What is the code you are using @pierremgi? Share this post Link to post Share on other sites
pierremgi 4898 Posted October 6, 2017 15 hours ago, 7erra said: What is the code you are using @pierremgi? PM Share this post Link to post Share on other sites
Jnr4817 215 Posted October 7, 2017 I'd love to see the code, as well. Share this post Link to post Share on other sites