Jump to content
Sign in to follow this  
frattonstation

Vehicle drop from C130

Recommended Posts

Try this. :cool:

code to activate (adjust parameters first):

nul=[position,"classname",dir] execVM "dropspawn.sqf";

Script file: dropspawn.sqf

_pos = _this select 0;
_spawntype = _this select 1;
_dir = _this select 2;
_airtype = "C130J";
_type = "GUE_Soldier_Pilot";
mygroup = creategroup side player;

_target = createVehicle  ["testsphere2",[_pos select 0,_pos select 1,-10], [], 0, "FLY"];
_target setpos [_pos select 0,_pos select 1,200];
_target setDir _dir;
_vdir = vectorDir _target;
_target setpos [(_pos select 0) + (_vdir select 0) * 26, (_pos select 1) + (_vdir select 1) * 26,200];
_apos = getposasl _target;


_npos = [(_pos select 0) + (_vdir select 0) * -1500, (_pos select 1) + (_vdir select 1) * -1500, 300];

_vehicle = createVehicle  [_airtype,_npos, [], 0, "FLY"];
_vehicle setpos _npos;
_vehicle setDir _dir;


_vehicle setvelocity [(_vdir select 0)*50,(_vdir select 1)*50, 5];

_type createUnit [_npos, mygroup,"pilot=this;"];
_pilot = pilot;
_pilot moveindriver _vehicle;
_pilot reveal _target;
_pilot doMove _npos;
_pilot dotarget _target;
_pilot dowatch _target;
_pilot FlyInHeight 400;
_vehicle FlyInHeight 400;


while {_vehicle distance _target > 40} do {
   sleep 0.5;
   if(_vehicle distance _target < 600) then {
       _pilot FlyInHeight 400;
       _pilot doMove _npos;
   };
};

   _bpos = _vehicle ModelToWorld [0,-12,-5.5];
   _bomb = _spawntype createVehicle _bpos;
   _bomb setpos _bpos;
   _bomb setDir direction _vehicle;
   _chute = "ParachuteMediumWest" createVehicle getpos _bomb;
   _chute setpos (_bomb ModelToWorld [0,0,3]);
   _bomb attachTo [_chute,[0,0,0]];
   deletevehicle _target;
   sleep 0.05;

_plane FlyInHeight 250;


sleep 1;
_plane FlyInHeight 450;
_pilot doMove [(_pos select 0) + (_vdir select 0) * 800, (_pos select 1) + (_vdir select 1) * 800, 500];

sleep 15;

deletevehicle _vehicle;
deletevehicle _pilot;

Share this post


Link to post
Share on other sites

Awesome script, just one problem, though its probably the wrong thing to use this for; I placed a US Special Weapons crate as the drop vehicle, but when it hits the ground it just sinks right through. Can this script work for Ammo Crates, or only vehicles?

Share this post


Link to post
Share on other sites

You'll need to adjust the z coordinate (third parameter) of the attachTo to be higher for crates. That's how I fixed it, anyway.

Share this post


Link to post
Share on other sites

Yep, thats the one.. just tweaking it now... 1 not high enough, 10 too much... Cheers for the response.

Edit: How would I go about spawning in the C-130 further away from the drop zone? I've doubled its spawn in distance:

_npos = [(_pos select 0) + (_vdir select 0) * -3000, (_pos select 1) + (_vdir select 1) * -3000, 300];

But it arcs upwards then turns away before it reaches the drop point. I couldn't see any other lines which would help this problem, but I've doubled up some random position numbers to see if I can get it with trial and error, however to no avail. Any further help would be greatly appreciated.

Edited by Uzii

Share this post


Link to post
Share on other sites

Changing the "-1500" to any other value should do for adjusting the distance. Maybe it's an AI-issue. *shrug*

Share this post


Link to post
Share on other sites

Right, I'll have to keep it at that then. I've tried changing a lot of the values but the only difference I can get out of it is how late it arcs up and turns away. But whatever I set it as it never manages to get close enough to the drop point to release the cargo...

Share this post


Link to post
Share on other sites

To activate this script would i place a trigger with the code posted above nul=[position,"classname",dir] execVM "dropspawn.sqf"; however what parameters should i use for the classname and dir (obviously for the position i can just use a marker or game logic location)?

Share this post


Link to post
Share on other sites
To activate this script would i place a trigger with the code posted above nul=[position,"classname",dir] execVM "dropspawn.sqf"; however what parameters should i use for the classname and dir (obviously for the position i can just use a marker or game logic location)?

using a trigger activated by anybody or the specific blufor side being present is fine depending on mission. classname would be the what the aircraft is called ingame. For example the MV-22 Osprey classname is "MV22". for dir you could just put a number from 0 to 360 is what it looks like.

Share this post


Link to post
Share on other sites

Just to clarify, the classname is the vehicle that is dropped from the c-130. Here is an example line I am using:

nul=[getpos drop1,"USOrdnanceBox",225] execVM "dropspawn.sqf";

drop1 is an invisible H object, and the USOrdnanceBox is the smaller one containing explosives.

Share this post


Link to post
Share on other sites

confirmed.

instead of manually setting the dir you can also use it like this:

nul=[getPos drop1,"USOrdnanceBox",getDir drop1] execVM "dropspawn.sqf";

So you just have to rotate that invisible H. If you want anything else than the c130 to make the drop, you would have to adjust the script. Not very hard to do though.

Share this post


Link to post
Share on other sites

I am planning on using this script to drop supplies to a smll village, since you are using it for the same thing Uzii could you please tell me what Z axis value you are using? Also if i wanted to adjust the script to drop multiple supply crates how would i go about doing this?

Share this post


Link to post
Share on other sites
    _bomb attachTo [_chute,[0,0,2.3]];

That seems to line the box up with the ground pretty well. Think it might change slightly with other size boxes. As for multiple drops, not sure, just above my level. Might be able to loop the spawn vehicle action for the drop, or copy it and put a little wait between each one so it drops 3 crates in a row. Not sure though, Tajin is the man for this one ;)

Share this post


Link to post
Share on other sites

Hmmm you would just have to duplicate the following lines and add a "sleep" between them:

	_bpos = _vehicle ModelToWorld [0,-12,-5.5];
_bomb = _spawntype createVehicle _bpos;
_bomb setpos _bpos;
_bomb setDir direction _vehicle;
_chute = "ParachuteMediumWest" createVehicle getpos _bomb;
_chute setpos (_bomb ModelToWorld [0,0,3]);
_bomb attachTo [_chute,[0,0,0]];

if you dont want the same crate 3 times you'll have to change _spawntype to the respective classnames or define additional variables for it _spawntype1, _spawntype2 and so on.

Share this post


Link to post
Share on other sites

Could you please have a quick look through this script and tell me if its all correct?

Code to activate:

nul=[position,"classname0","classname1","classname2",dir] execVM "dropspawn.sqf";

Script file: dropspawn.sqf

_pos = _this select 0;
_spawntype0 = _this select 1;
_spawntype1 = _this select 2;
_spawntype2 = _this select 3;
_dir = _this select 4;
_airtype = "C130J";
_type = "GUE_Soldier_Pilot";
mygroup = creategroup side player;

_target = createVehicle  ["testsphere2",[_pos select 0,_pos select 1,-10], [], 0, "FLY"];
_target setpos [_pos select 0,_pos select 1,200];
_target setDir _dir;
_vdir = vectorDir _target;
_target setpos [(_pos select 0) + (_vdir select 0) * 26, (_pos select 1) + (_vdir select 1) * 26,200];
_apos = getposasl _target;


_npos = [(_pos select 0) + (_vdir select 0) * -1500, (_pos select 1) + (_vdir select 1) * -1500, 300];

_vehicle = createVehicle  [_airtype,_npos, [], 0, "FLY"];
_vehicle setpos _npos;
_vehicle setDir _dir;


_vehicle setvelocity [(_vdir select 0)*50,(_vdir select 1)*50, 5];

_type createUnit [_npos, mygroup,"pilot=this;"];
_pilot = pilot;
_pilot moveindriver _vehicle;
_pilot reveal _target;
_pilot doMove _npos;
_pilot dotarget _target;
_pilot dowatch _target;
_pilot FlyInHeight 400;
_vehicle FlyInHeight 400;


while {_vehicle distance _target > 40} do {
   sleep 0.5;
   if(_vehicle distance _target < 600) then {
       _pilot FlyInHeight 400;
       _pilot doMove _npos;
   };
};

   _bpos = _vehicle ModelToWorld [0,-12,-5.5];
   _bomb = _spawntype0 createVehicle _bpos;
   _bomb setpos _bpos;
   _bomb setDir direction _vehicle;
   _chute = "ParachuteMediumWest" createVehicle getpos _bomb;
   _chute setpos (_bomb ModelToWorld [0,0,3]);
   _bomb attachTo [_chute,[0,0,2.3]];

   sleep 2;
   _bpos = _vehicle ModelToWorld [0,-12,-5.5];
   _bomb = _spawntype1 createVehicle _bpos;
   _bomb setpos _bpos;
   _bomb setDir direction _vehicle;
   _chute = "ParachuteMediumWest" createVehicle getpos _bomb;
   _chute setpos (_bomb ModelToWorld [0,0,3]);
   _bomb attachTo [_chute,[0,0,2.3]];

   sleep 2;
   _bpos = _vehicle ModelToWorld [0,-12,-5.5];
   _bomb = _spawntype2 createVehicle _bpos;
   _bomb setpos _bpos;
   _bomb setDir direction _vehicle;
   _chute = "ParachuteMediumWest" createVehicle getpos _bomb;
   _chute setpos (_bomb ModelToWorld [0,0,3]);
   _bomb attachTo [_chute,[0,0,2.3]];

   deletevehicle _target;
   sleep 0.05;

_plane FlyInHeight 250;


sleep 1;
_plane FlyInHeight 450;
_pilot doMove [(_pos select 0) + (_vdir select 0) * 800, (_pos select 1) + (_vdir select 1) * 800, 500];

sleep 15;

deletevehicle _vehicle;
deletevehicle _pilot;

Share this post


Link to post
Share on other sites

Looks fine to me. Have you tested it yet ?

Share this post


Link to post
Share on other sites
Looks fine to me. Have you tested it yet ?

Just about to, i will report back when i have :)

---------- Post added at 05:22 PM ---------- Previous post was at 05:05 PM ----------

It worked perfectly, thanks mate. If anyone needs to drop multiple things the script i posted above works perfectly :)

Edited by Brute

Share this post


Link to post
Share on other sites

Can i use this script in Multiplayer or have i change something ?

When i use it in MP...sometimes it dont work. There 2 C-130 that fall from the sky...strange.

Share this post


Link to post
Share on other sites
Can i use this script in Multiplayer or have i change something ?

When i use it in MP...sometimes it dont work. There 2 C-130 that fall from the sky...strange.

Depends on how you call it... if you use a trigger you'll have to change the script to run only on the server. Otherwise there will be 1 C130 for each player... and that will surely result in an aerial crash. :D

Share this post


Link to post
Share on other sites

Ah, how would I go about that? At the moment, I've got it activating when a trigger is err... triggered.

Edit: Found this little piece on the wiki, would this at the beginning of the script work?

?(!isServer): exit

Edited by Uzii

Share this post


Link to post
Share on other sites

Almost, the code you quoted is SQS code but my script is SQF.

You'll need this:

if (!isServer) exitWith {}

Share this post


Link to post
Share on other sites

Thank you, your continuing help on this thread is much appreciated.

Share this post


Link to post
Share on other sites

This comes at the start of the script ?

Like this:

if (!isServer) exitWith {}

(The rest of the script....)

Share this post


Link to post
Share on other sites

Yep, that's it. It means that if its not(!) the dedi server running the script(isServer), it exits without running the rest(exitwith{}). There will only be one server running it, so only one C-130 will spawn. The problem is that every player was each running the script so there would be a C-130 for every player. I think that's it.

Edited by Uzii

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
Sign in to follow this  

×