Jump to content
breeze

First Script a Lil Help

Recommended Posts

Just finished a few tutorials and wanted to automate the animations of the hatch going up and down on some test mission I was doing, I thought that it was a perfect little script to begin on.

 

So in the init box on the Chopper at this time, I had the following.

 

this animate ["ramp_top" 1];

this animate ["ramp_bottom" 1];

this keeps it open at spawn 

 

In a trigger set with a heli-pad I have this and when the chopper lands it opens

this animate ["ramp_top" 0];

this animate ["ramp_bottom" 0];

 

These work But for learning purposes I wanted to make a small script and initiate it in the Init.sqf file

 

 

 //Animate Door Scripting

 

 

_myChopper = Chopper1
_animateClose = _myChopper animate ["ramp_top",0]["ramp_bottom",0];   ///I don't think this is joined right but not sure how to
_animateOpen = _mychopper animate ["ramp_top",1] ["ramp_bottom",1];
 
_myChopper getPosAsl;
 
if getPosAsl > 3 _animateClose;
if getPosAsl < 3 _animateOpen;
 
I think the if statement is right but not sure either.
 
Any help??
 
 
 
Also I loved the tutorials by devPaxton on you tube if you guys know any others like his please drop a link.

Share this post


Link to post
Share on other sites

Think of sqf files as the same code you put in triggers/init of unit etc.

You had it correct for syntax in the trigger but changed it for the sqf.

What I think you want us a function.

Brz_fnc_animateOpen = { params ["_heli"]
_heli animate ["ramp_top" 0];
_heli animate ["ramp_bottom" 0];
}
Now call this with

[mychopper] call Brz_fnc_animateOpen
In have not tested as on my phone waiting for kids to finish sports practice. I'd there a syntax error or autocomplete error I will fix later.

I'll leave you to set up the close function.

Share this post


Link to post
Share on other sites

And what about the If Statement in other words, When the heli lands the door should open as it lifts off the door should close. is the if statement correct?

 

Also I shouldn't have to call it if the script should continually run right?

 

I should initialize it in the init.sqf??

Share this post


Link to post
Share on other sites

The whole thing could be wrapped in a while do loop

You have not put the vehicle in the getposasl check. Also positionserves beyond an array you need the third parameter-select 2

(GetPosASL _heli select 2) >3

Params ["_heli"]

while {alive _heli} do {
    If ((getposasl _heli select 2)>3) then {.....}
};

Share this post


Link to post
Share on other sites

So Like this?

 

I named it animate_ramp.sqf and tried to execute it with execVm in the init.sqf not working.

 

//Animate Door script 
 
 
_myChopper = Chopper1
_animateClose = _myChopper animate ["ramp_top",0];
                _myChopper animate ["ramp_bottom",0];
 _animateOpen = _mychopper animate ["ramp_top",1];
                _myChopper animate ["ramp_bottom",1];
 
Params ["_myChopper"]
 
while {alive _myChopper} do {
    If (( getPosAsl _myChopper select 0) >3)then _animateClose};
    If (( getPosAsl _myChopper select 0) <3)then _animateOpen);

Share this post


Link to post
Share on other sites

save as something.sqf and call it by _nul = [chopperName] execVM "something.sqf"

_myChopper = _this select 0;
while {alive _myChopper} do {
     if (( getPos _myChopper select 2) > 3) then {_myChopper animate ["ramp_top",0]; _myChopper animate ["ramp_bottom",0];};
     if (( getPos _myChopper select 2) < 3) then {_myChopper animate ["ramp_top",1]; _myChopper animate ["ramp_bottom",1];};
}

Share this post


Link to post
Share on other sites

OK I have a couple of questions.??

 

First I need to define the Variables with the first paragraph correct?

 

_myChopper = Chopper1
_animateClose = _myChopper animate ["ramp_top",0]; _myChopper animate ["ramp_bottom",0] ;
 _animateOpen = _mychopper animate ["ramp_top",1]; _myChopper animate ["ramp_bottom",1];
 
 
Then once the _animateOpen and _animateClose are defined
 
_myChopper = _this select 0;  ///Where you have _this select 0; What index is this referring to? 

while {alive _myChopper} do {
if (( getPos _myChopper select 2) > 3) then {_myChopper animate ["ramp_top",0]; _myChopper animate ["ramp_bottom",0];};
if (( getPos _myChopper select 2) < 3) then {_myChopper animate ["ramp_top",1]; _myChopper animate ["ramp_bottom",1];};
}

 
 while {alive _myChopper} do {

if (( getPos _myChopper select 2) > 3) then {_myChopper  _animateClose};
if (( getPos _myChopper select 2) < 3) then {_myChopper  _animateOpen};
}

 

I mean I am new I am trying to follow something that I can make sence of.. When you used the index I was thrown because I saw nothing defined to be using it? Then once each parameter is defined? I can just call it by name without the quotes because its no longer a string?

 
 
When  _nul = _myChopper execVM "animate_ramp.sqf" This is in the units init line..
Is the nul acting like a switch here I read that nil and nul shut off a script after it runs??

Share this post


Link to post
Share on other sites

No, the script that I wrote is all you need. _this is the argument that you pass to the script when calling it by [argument array] execVM "scriptname.sqf", so _this select 0 is the first, and in our case only argument that we passed to the script. The way you do it (_myChopper = Chopper1) means that the script will work only for Chopper1, while my way will work for any chopper you call the script for. You can define the _animateOpen/Close as functions (but it would need to be called with call) but it's just a waste of time here and it'll even make the script slower.

 

Also, donelsarjo is right, there should be a sleep somewhere in the loop to lessen the burden on the system.

Share this post


Link to post
Share on other sites

if you 'sleep' in the init of an object you need to spawn or execVM the code on the object just to confuse things more..... or you will get an error...theend3r has it pretty much as i would do it.

 

breeze, just remember in your examples you are using anipmateopen and animateclose but you are not wrapping the code in { } so you will likely get things run out of sequence.

 

_animateClose = _myChopper animate ["ramp_top",0]; _myChopper animate ["ramp_bottom",0] ;

_animateOpen = _mychopper animate ["ramp_top",1]; _myChopper animate ["ramp_bottom",1];

should be 

_animateClose = { (_this select 0) animate ["ramp_top",0]; (_this select 0) animate ["ramp_bottom",0] ;
_animateOpen ={(_this select 0)animate ["ramp_top",1]; (_this select 0) animate ["ramp_bottom",1]};

then as you have created a variable containing code, you need to 'call' or 'spawn' this code on the object.

[chopper1] call _animateOpen

completed code:

fnc_ramps ={
params ["_myChopper"]; //_myChopper = _this select 0; //better  to use params as it also sets the variable as private....
while {alive _myChopper} do {
     if (( getPos _myChopper select 2) > 3) then {_myChopper animate ["ramp_top",0]; _myChopper animate ["ramp_bottom",0];};
     if (( getPos _myChopper select 2) < 3) then {_myChopper animate ["ramp_top",1]; _myChopper animate ["ramp_bottom",1];};
    sleep 0.5;
}};

Use by spawning on object in init

[this] spawn fnc_ramps;

Share this post


Link to post
Share on other sites

OK well I appreciate all of the feedback I really do, But sometimes I am not understanding and I want to. 

 

So anyway I got an undefined variable when I used this

 

 

_myChopper = Chopper1;
while {alive _myChopper} do {
     if (( getPos _myChopper select 2) > 3) then {_myChopper animate ["ramp_top",0]; _myChopper animate ["ramp_bottom",0];};
     if (( getPos _myChopper select 2) < 3) then {_myChopper animate ["ramp_top",1]; _myChopper animate ["ramp_bottom",1];};
}
 
I like being able to call it from any vehichle with a ramp like the osprey or a C130 for jumps but this didnt work.
 
I used the 
 
_nul = [chopperName] execVM "ramp.sqf";
 
in the choppers init line...
 
And just one more question because you used setpos you needed to index with select, 2
 
But if we use the setPosAsl thats just one value of height right so it would not require a select index number???
 
Lastly where should I put the sleep thing for efficiency??

Share this post


Link to post
Share on other sites

getPosASL is still an array with [x,y,z] values, it just uses seas level (ASL = above sea level) Select 2 is still the third parameter which is height.

 

I updated post above your last...

 

edit: linked correct command now!! Doh, must be late.

Share this post


Link to post
Share on other sites

The chopperName was supposed to be the name of your chopper, so use _nul = [Chopper1] execVM "ramp.sqf"; if the chopper is named Chopper1 (is it?), or _nul = [this] execVM "ramp.sqf"; if calling it from the init line.

As for the sleep, it doesn't matter where:

_myChopper = _this select 0;
while {alive _myChopper} do {
     if (( getPos _myChopper select 2) > 3) then {_myChopper animate ["ramp_top",0]; _myChopper animate ["ramp_bottom",0];};
     if (( getPos _myChopper select 2) < 3) then {_myChopper animate ["ramp_top",1]; _myChopper animate ["ramp_bottom",1];};
     sleep 0.5;
}

The undefined var is strange if you named the chopper correctly.

 

Edit: ninja'd

Share this post


Link to post
Share on other sites

 

_myChopper = _this select 0;  ///Where you have _this select 0; What index is this referring to? 

_this select 0; is the unit you want it to activate on, eg. I would put a script in a unit's init and in the script at the top you would have:

_myunit = _this select 0;

_unit_who_activates_it = _this select 1; (this only applies normally with an AddAction script)

_id = _this select 2; (This is normally also applied only in AddAction scripts, it is the AddAction, Action. Eg. "Activate me" then scrolling on that and activating it, the addAction would activate but wouldn't disappear. So I would do this to make the addAction after you select it:

_myunit removeAction _id;

That is all the their is.

Share this post


Link to post
Share on other sites

OK I think I follow all that you have said its just this is zipping right past variables into arrays. These are multidimensional arrays right??

 

And the one part I am not following Is the spot where your writing  

 

[chopper1] call _animateOpen 

 

 

Also where theend3r defined

 

_chopper1 = this select 0; /// This is so it can be used on any aircraft as he said so 

 

[this] spawn fnc_ramps; ////in any aircrafts init line would work if the _chopper1 is defined as _chopper1 this select 0; in the array? 

 

and you are naming the script fnc_ramps.sqf ??

Share this post


Link to post
Share on other sites

 

[chopper1] call _animateOpen

 

[this] spawn fnc_ramps; ////in any aircrafts init line would work if the _chopper1 is defined as _chopper1 this select 0; in the array? 

 

and you are naming the script fnc_ramps.sqf ??

1) That's how functions are called: [argument1, argument2,...] call nameOfTheFunction;

2) It would work for any vehicles of the same type, yes (different vehicles have different animation names)

3) It doesn't matter how you name it, just use it with _nul = [blah] execVM "name.sqf" (so in this case ramp.sqf) when saving the script to a file

 

Compiling it as a function is better when it's something that's called a lot in the mission but it's not needed here.

Kev's code is a bit more complicated as he creates a function. You need to put it in the init.sqf and there is no other file.

 

Basically: Either use my code, save it to a file and call it with execVM or use Kev's, create a file called init.sqf and put his code in there. Then call it with [this] spawn fnc_ramps;.

Share this post


Link to post
Share on other sites

Well I will keep reading this and try applying this a few ways just for my learning experience. I want to thank you guys for the patience.

I had done the tutorials by DevPaxton on youtube thought they were great the way he explains things.

So you guys took me right past the variables into complex arrays. Its this syntax stuff drives me nuts,

 

But thanks again I will keep at it.

Share this post


Link to post
Share on other sites

Np. Also get some good software to write it in. I use Notepad++ with a SQF addon (autocompletition, colors, shows paired brackets...). It makes things significantly easier.

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

×