Jump to content
Sign in to follow this  
Mynock

Horrible script that doesn't work as intended (Edited)

Recommended Posts

Edited:

Yeah nevermind this script sucks pretty bad. Doesn't work on certain helicopter I'm told, so it's relatively useless afterall. Sorry for wasting your time if you downloaded it and it didn't work on the helicopter you wanted to use it for.

Share this post


Link to post
Share on other sites

Neat idea!  Here's a quick rewrite to use some optional parameter commands to save on typing.

// 0 = [this] execVM "heli_idle.sqf"; // true damage after delay
// 0 = [this, false] execVM "heli_idle.sqf"; // optional false damage remains.

params[["_helicopter", objNull], ["_damage", true]];
if (isNull _helicopter) exitWith {};

_helicopter allowdamage false;

getPosWorld _helicopter params ["_xpos", "_ypos"];
_helicopter setPosWorld [_xpos, _ypos, 0];
_helicopter flyInHeight 0;

sleep 5;
_helicopter allowdamage _damage;

Share this post


Link to post
Share on other sites

The big difference is in how you capture the input variables.

 

You were using:

_helicopter = _this select 0;
_damage = _this select 1;

Capturing the [this, true] from the _this input as normal.

 

There's a newish command called params which does that work for you, and more which is what i demonstrated.

 

This is identical to what you had:

params["_helicopter", "_damage"];

Both give us _helicopter and _damage variables we can use which match up with the input from _this. So the first "_var" we list will assume the value from _this select 0, the second "_val" will assume the value of _this select 1 and so on.

 

However we can take it a step further and set defaults!

params[["_helicopter", objNull], ["_damage", true]];

This now gives us the same variable names to play with however if _helicopter isn't a valid object, it will default to objNull.  The next line of the script checks if that happened and exits the script without doing anything.

 

The _damage default is more powerful though.  It defaults to true so you can leave it off entirely now when you call the script and it'll still return allowDamage to the unit.

 

You can even expand that out more with detailing what types of data each is allowed to be, but for this script simply defaulting to true to make it optional was enough.

 

So if you wanted to call your script with optional allowDamage False you'd do:

0 = [this, false] execVM "heli_idle.sqf";

While if you wanted to leave the default of allowing damage after a few seconds you leave off the boolean:

0 = [this] execVM "heli_idle.sqf";

Ideally you'd move your code into a function, either by using the function library or just putting this in your init.sqf:

 fn_startRunning = {
    params[["_helicopter", objNull], ["_damage", true]];
    if (isNull _helicopter) exitWith {};

    _helicopter allowdamage false;

    getPosWorld _helicopter params ["_xpos", "_ypos"];
    _helicopter setPosWorld [_xpos, _ypos, 0];
    _helicopter flyInHeight 0;

    sleep 5;
    _helicopter allowdamage _damage;
};

Then you'd call it from an init field as:

[this] call fn_startRunning;

That way you have a single copy of it in memory instead of compiling the script each time you use it.

 

Following all of that? :)

  • Like 4

Share this post


Link to post
Share on other sites

@Mynock:  Good useful idea dude.

@Kylania:  Thanks for breaking down the explanation.  I didn't now about the new params command, and default usage.  Your incremental explanation rocked.  There's some very bright scripter guys who just would have dropped in their slick code with no explanation (which feels a bit like showing off without going the extra mile to explain it).

  • Like 2

Share this post


Link to post
Share on other sites

That's odd.  I didn't test a whole lot, but I also started my helo about 200m up in the air.  However I didn't see the bouncing in the air thing you're talking about.  I am on Dev build though, and there has been some changes to flyInHeight and AI movement, so maybe that explains it?

 

For the function thing you can just declare it in the init.sqf or go the full route for functions library.  I have a demo showing that structure here.

 

Glad you learned a bit more. :)

Share this post


Link to post
Share on other sites

Sorry if i have misunderstood, have only read the first couple posts. But if u want a chopper (empty or with crew) to be spooled up at ground level cant u just use _this engineOn true?

  • Like 1

Share this post


Link to post
Share on other sites

Sorry if i have misunderstood, have only read the first couple posts. But if u want a chopper (empty or with crew) to be spooled up at ground level cant u just use _this engineOn true?

 

Well, sure... this will give exactly the result he wants without the bounce:

this engineOn true; this flyInHeight 0;

But.. then he wouldn't have learned about params!  :unsure:

Share this post


Link to post
Share on other sites

WIll this work with an emptied place helicopter? Meaning I place an empty helo down, add this script, and at start of mission the helo is started and I can hop in and go. It takes a while for some of the chinooks to spool up.

Share this post


Link to post
Share on other sites

It works with the Huron at least, but the wheels never come down so it just sits there on the ground.

Share this post


Link to post
Share on other sites

It doesn't work as intended, only worked with a couple vanilla helicopter. Disregard this thread from now on. I'm an idiot for thinking I could make something.

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  

×