Home   Help Search Login Register  

Author Topic: Fire flare from chopper  (Read 1509 times)

0 Members and 1 Guest are viewing this topic.

Offline Binary

  • Members
  • *
Fire flare from chopper
« on: 24 Sep 2008, 10:48:48 »
Hello all :)

I've searched the forums thin for 3 days now - trying to get my script to work.

The script is supposed to be applied to a "support chopper" and is simply a learn-as-you-go-sqf-project for myself :)
So far, the script works beautifully - I simply use
Code: [Select]
this addAction ["Drop ammo crate", "support_ammo_chopper_this.sqf"]to add a action to the chopper.

The script itself:
Code: [Select]
_height = getpos this select 2;

if (_height > 40)
exitWith { hint "Altitude to high"; };

if (speed this > 75)
exitWith { hint "Speed to high"; };

hint "Ammo crate dropped!";
"AmmoBoxWest" createVehicleLocal (getpos this);
"SmokeShellGreen" createVehicleLocal (getpos this);
"FlareWhite_GP25" createVehicleLocal (getpos this);

this sideChat "Ammo crate dropped!";
this removeAction 0;

The problem - is the flare part.
Code: [Select]
"FlareWhite_GP25" createVehicleLocal (getpos this);Ideally the flare should spawn in the air, directly above the ammo crate when dropped. I've tried my best to use getpos, setpos and so on, but it never works. At this stage the crate drops, the smoke is created but the flare doesn't spawn.

What am i doing wrong?
"Ah.. Home sweet hell !" - Al Bundy

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Fire flare from chopper
« Reply #1 on: 24 Sep 2008, 12:23:01 »
"FlareWhite_GP25" is the magazine classname, you really need the ammo classname, in this case "F_40mm_White".

I got this to work using:

brightthing = "F_40mm_White" createVehicleLocal [getpos player select 0,getpos player select 1,250];

This was in the players init field btw.

Incidentally is the use of 'this' correct in a script?
I was under the impression that '_this' was to be used in scripts as representing the passed object to the script.


Planck
« Last Edit: 24 Sep 2008, 12:28:30 by Planck »
I know a little about a lot, and a lot about a little.

Offline Binary

  • Members
  • *
Re: Fire flare from chopper
« Reply #2 on: 24 Sep 2008, 13:22:03 »
Thanks for the reply Planck :)

I've edited the code a bit

Code: [Select]
_height = getpos this select 2;
_launchflare = "F_40mm_White" createVehicleLocal [getpos this select 0,getpos this select 1,250];
_launchsmoke = "SmokeShellGreen" createVehicleLocal (getpos this);
_launchammo = "AmmoBoxWest" createVehicleLocal (getpos this);

if (_height > 40)
exitWith { hint "Altitude to high"; };

if (speed this > 75)
exitWith { hint "Speed to high"; };

hint "Ammo crate dropped!";
_launchammo;
_launchsmoke;
_launchflare;

this sideChat "Ammo crate dropped!";
this removeAction 0;

It now works like a charm.

Initially i named the chopper "support_chopper_1" and used that name in the script. However when i found out "this" worked as well, i switched to that, as the script can then be applied to any chopper by simply executing the script from the init field of the unit.

But as this is a learning experience for me - is there any reason why i shouldn't use this?
Eventually i would also like the script to be compatible in multiplayer.
"Ah.. Home sweet hell !" - Al Bundy

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Fire flare from chopper
« Reply #3 on: 24 Sep 2008, 13:43:59 »
* Inside scripts, use _this, not this. this just happens to work in your test, since this will be the last object created by the game and just happens to be the helocopter in this case (fine in your test mission, but not in a real mission).
* You are actually creating the crate on the ground. It doesn't fall because it isn't a "physics" object, so you have to manually setPos it under an object that can fall, like a parachute.
* The smoke and flare fall separately, so they need to be kept at a constant position.
* NEVER use "removeAction 0". Use the _index to delete the action, or your script will end up deleting other actions by mistake (fine in your test mission, but not in a real mission).
* Don't use createVehicleLocal unless you know you want to do it! Always use createVehicle unless you really do want a local-only object. They are equivalent in SP, but in MP they are very different!

* When you do:
Code: [Select]
_launchammo = "AmmoBoxWest" createVehicleLocal (getpos this);

_launchammo;
You are not creating and running functions (the code is run in the first line, the second line does nothing). I think you mean to do:
Code: [Select]
// Define function.
_launchammo = { "AmmoBoxWest" createVehicleLocal (getpos this) };

// Run function.
call _launchammo;

Anyway, here is a fixed version (only thing that isn't MP is that in MP only the player dropping the crate gets the sideChat message):
Code: [Select]
_helo = _this select 0; // Object that the action was on.
_actor = _this select 1; // The soldier that activated the action.
_index = _this select 2; // Action index, so you can delete it.
_parameters = _this select 3; // Any parameters passed into the action.

if (((getpos _helo) select 2) > 40)
exitWith { hint "Altitude too high"; };

if ((speed _helo) > 75)
exitWith { hint "Speed too high"; };

// Create the box just below the helo, else the helo will crash into it!
_dropPos = _helo modelToWorld [0, 0, -5];
_chute = "ParachuteWest" createVehicle _dropPos;
_chute setPos _dropPos;
_chute setVectorDirAndUp [vectorDir _helo, vectorUp _helo];

// Although we are creating them all at the same position, we will move them
// before they get a chance to collide.
_smoke = "SmokeShellGreen" createVehicle _dropPos;
_crate = "AmmoBoxWest" createVehicle _dropPos; // Will be placed on ground.
_crate setPos _dropPos;
_flare = "F_40mm_Green" createVehicle _dropPos;

_actor sideChat "Ammo crate dropped!";
_helo removeAction _index;

// Keep everything in line until the crate lands.
waitUntil
{
if (((getPos _flare) select 2) < 1) then
{
true; // Exit.
}
else
{
// Put them in a line so they don't collide with each other or the chute.
_crate setPos (_chute modelToWorld [0, 0, -1.5]);
_crate setVectorDirAndUp [vectorDir _chute, vectorUp _chute];

_smoke setPos (_chute modelToWorld [0, 0, -1]);

_flare setPos (_chute modelToWorld [0, 0, -0.5]);

false; // Don't exit.
};
};

// Put crate squarely on the ground.
_pos = getPos _crate;
_pos set [2, 0];
_crate setPos _pos;
_crate setVectorUp [0, 0, 1];
« Last Edit: 24 Sep 2008, 13:47:56 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Binary

  • Members
  • *
Re: Fire flare from chopper
« Reply #4 on: 24 Sep 2008, 14:01:10 »
Wow - amazing Spooner  :clap:

I'm gonna chew on this a day or two and then post my results here :)

Thanks a lot for help so far.
"Ah.. Home sweet hell !" - Al Bundy