OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: haroon1992 on 30 Jul 2009, 16:44:07

Title: How can i rearm a chopper via SCRIPTING?[Maybe SOLVED]
Post by: haroon1992 on 30 Jul 2009, 16:44:07
I have a large scale battle mission (check forum)
I have made an air strike but i don't know how to rearm the chopper via SCRIPTING method......

How can i rearm the chopper every three minutes so that it doesn't run out of ammo? ???

Haroon1992...............
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: Gruntage on 30 Jul 2009, 18:43:54
You need a script like this one here:

Code: [Select]
_chopper = _this select 0

#Status

?NOT (SomeAmmo _chopper): goto "Rearm"

goto "Status"

#Rearm


_chopper addmagazine "HellfireLauncherCobra"
_chopper addmagazine "ZuniLauncher38"


goto "status"

exit

This script is called from the init line of the chopper:

Code: [Select]
[this] exec "rearm.sqs"
However, i dont know a command that can restore a vehicle's ammo without adding the weapons manually. Which is quite difficult as i dont know the different types of weapons  :confused:

If only there was a command like 'setvehicleammo'  :(

(Ive tried SetAmmoCargo but nothing happens  :no: )

Hope this helps

Gruntage
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: haroon1992 on 31 Jul 2009, 14:29:01
At least this adds some ammo to my chopper....
Thanks...... ;)
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: Raptorsaurus on 31 Jul 2009, 22:50:44
Here is a more general script that will work on any vehicle with any ammo type. The script must be run before the unit runs out of ammo so that it "knows" the magazine types before they are expended.
Code: [Select]
;reload.sqs by Raptorsaurus

_craft = _this select 0
_mags = magazines _craft

#start
@ (! (someAmmo _craft) || ! alive _craft
? ! alive _craft : exit
{_craft removeMagazine _x} forEach _mags
{_craft addMagazine _x} forEach _mags

? alive _craft : goto "start"
exit

To run the script just use: [this] exec "reload.sqs" in the init field of the vehicle that you want to have perpetual ammo. This will work for soldiers also.
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: Walter_E_Kurtz on 01 Aug 2009, 02:58:39
I think using the someAmmo (http://www.ofpec.com/COMREF/index.php?action=details&id=354&game=All) command will prove more trouble than it's worth, because it only becomes not true when the vehicle is out of all possible magazines. In other words, your chopper may use up its rockets but, as long as it can fire its gun, it won't rearm.

Use the majority of Raptosaurus' script, but, as you originally wanted, have it looping every three minutes:
Code: (reload.sqs) [Select]
_craft = _this select 0
_mags = magazines _craft

#start
? ! alive _craft : exit
{_craft removeMagazine _x} forEach _mags
{_craft addMagazine _x} forEach _mags

~180
goto "start"
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: haroon1992 on 01 Aug 2009, 15:05:37
Thanks you very much for the help (both of you) :clap:

I have been confused that i can't find the ammo class for FFAR missiles.....
With this ,i think it will work ,thanks....everyone
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: Planck on 01 Aug 2009, 15:40:26
Here (http://www.ofpec.com/COMREF/index.php?action=read&id=67).


Planck
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: haroon1992 on 01 Aug 2009, 15:47:35
Can you tell me which one is the FFAR.....? ???
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: Walter_E_Kurtz on 01 Aug 2009, 16:07:13
ZuniLauncher38
Title: Re: How can i rearm a chopper via SCRIPTING?
Post by: haroon1992 on 01 Aug 2009, 16:13:20
Thanks Walter.................................................................. :D