Jump to content
Sign in to follow this  
NGagedFX

C130 Cargo Script

Recommended Posts

Hey there,

After +200 hours of ArmA2-editing, I finally made my very first script. Nothing special though, but it's a start. And now I'm rolling I want to get deeper into it. I know there are tons of C130 Cargo/Transport scripts, but I get headaches by just looking at it. That's why I want to build my own script in which you can load and unload vehicles, from scratch, and learn in the proces. Right now I am able to open and close the ramp of a C130. :) Here's my setup:

C130 - name = c130_transport

Init: this exec "c130_cargo\initRamp.sqf"

initRamp.sqf

openRamp = c130_transport addAction ["Open Ramp", "c130_cargo\openRamp.sqf"]

openRamp.sqf

c130_transport animate ["ramp_top",1];

c130_transport animate ["ramp_bottom",1];

c130_transport removeAction openRamp;

closeRamp = c130_transport addAction ["Close Ramp", "c130_cargo\closeRamp.sqf"];

closeRamp.sqf

c130_transport animate ["ramp_top",0];

c130_transport animate ["ramp_bottom",0];

c130_transport removeAction closeRamp;

openRamp = c130_transport addAction ["Open Ramp", "c130_cargo\openRamp.sqf"];

Right now I got 3 problems:

-It only works for this single C130, whereas I rather have it work for every C130.

-I has to be multiplayer compatible, and I have no idea what people are talking about when saying stuff like localVariable and what not.

-To get to the next part, I want a script to check if the ramp is open. Like "if c130_transport ramp_bottom = 1, then..." but that obviously doesn't work and I can't find anything on teh intarwebzorxz.

So if you experts are willing to guide me through it, I would be really thankfull and it would be great for my scripting skills. But please remember that I'm a total noob at scripting. :)

Share this post


Link to post
Share on other sites
C130 - name = c130_transport

Init: this exec "c130_cargo\initRamp.sqf"

Should be:

nul = [this] "c130_cargo\initRamp.sqf"

Just add it to all C130 you want.

Then

initRamp.sqf

_plane = _this select 0;

openRamp = _plane addAction ["Open Ramp", "c130_cargo\openRamp.sqf"];

openRamp.sqf

_plane = _this select 0;

My_plane_ramp_open = true;

_plane animate ["ramp_top",1];

_plane animate ["ramp_bottom",1];

_plane removeAction openRamp;

closeRamp = _plane addAction ["Close Ramp", "c130_cargo\closeRamp.sqf"];

closeRamp.sqf

_plane = _this select 0;

My_plane_ramp_open = false;

_plane animate ["ramp_top",0];

_plane animate ["ramp_bottom",0];

_plane removeAction closeRamp;

openRamp = _plane addAction ["Open Ramp", "c130_cargo\openRamp.sqf"];

To get to the next part, I want a script to check if the ramp is open. Like "if c130_transport ramp_bottom = 1, then..." but that obviously doesn't work and I can't find anything on teh intarwebzorxz.

if (My_plane_ramp_open) then { Ramp is open } else { Ramp is closed };

_neo_

Edited by neokika

Share this post


Link to post
Share on other sites

Thanks for the quick reply! :)

But could you maybe explain what that does? :o I understand that it is to make it work with multiple C130s, but I mean like, what does nul = [this] do in scripting language?

Share this post


Link to post
Share on other sites
Thanks for the quick reply! :)

But could you maybe explain what that does? :o I understand that it is to make it work with multiple C130s, but I mean like, what does nul = [this] do in scripting language?

No problem.

=D

this exec "script";

Is for sqs sytax.

nul = [this] exec "script";

Is for sqf sytax.

_neo_

Share this post


Link to post
Share on other sites

nul = [this] [color="Red"]execVM[/color] "c130_cargo\initRamp.sqf";

The nul = part is required by the execVM, in some cases the script will return a value, that value would be assigned to the variable "nul". Many people use "nul" for values they won't reference, it's just a way of kicking off a script.

The [this] part is passed to the script. The [ ] means it's an array. The this is the unit who's init field it's being called from. So since you're calling this from a C-130, lets say it's named "c1", this will be equal to the object c1.

Anything in the [ ] part will be accessible within the script as _this. Since it's an array you can get the value of the first argument (what's in the [ ]) as _this select 0. So in your script you'd have:

_plane = _this select 0;

and if you called this from the init of your c1 plane, inside your script _plane would be the c1 object. Meaning you can reuse the same script in multiple planes just by adding it to the init field. _plane will be equal to whatever plane you add the init to. You can see that in neo's examples above, the values in brown are the same inside and outside the scripts.

Edited by kylania

Share this post


Link to post
Share on other sites
-It only works for this single C130, whereas I rather have it work for every C130.

-I has to be multiplayer compatible, and I have no idea what people are talking about when saying stuff like localVariable and what not.

-To get to the next part, I want a script to check if the ramp is open. Like "if c130_transport ramp_bottom = 1, then..." but that obviously doesn't work and I can't find anything on teh intarwebzorxz.

you could make a script that will be loaded by the init.sqf, and that every 5 sec checks all vehicles. If vehicle = C130 and action not added, add action.

Variablelocality in this case means, if all other clients/server are able to know the value of YOUR clients variable. If you write scripts which don't need variables with values that other clients have, it is regularly easy.

Lets say, you want to increase a variable and post it per "hint format ...":

You call a script, and there is "for loop", in it it shows the loopvariables value. This Value may be local to your client.

Lets say, all computers have to display the same number at the same time:

This means, there has to be one Client, that does the Job for counting and sharing. Normally it's the servers job, because he is always available in a session.

So in our example, the server starts a script with a "for loop". This time he has to share the value of the loopvariable with all (or a part) clients. The clients will only display the new values, while the server writes em.

maybe a better explanation:

What happens, if you want to make a random weather change? If the script loads on every client its own random values for the weatherOption, every player gets a different weather. For such situations you need variables that aren't local to your client.

for the last point: You could make an Array for every C130 and its state (opened, closed), so after that you'd be able to check it easily and do actions depending off the state.

Sorry for my bad english - I hope I gave you some good hints :)

bye

Share this post


Link to post
Share on other sites
does this script not work for arma 2 free?

Why don`t you test it by yourself?

Share this post


Link to post
Share on other sites
would this script allow people/vehicles to be loaded inside the c130?

What's posted only adds an action to the plane and allows you to open & close the cargo door.

Share this post


Link to post
Share on other sites

Can't this script also be slightly modified to work with the MV-22 wing folding animation, so that you can fold and un-fold the craft on an LHD or so? Leaving the updated format the way it is and simply replacing names and animations?

Share this post


Link to post
Share on other sites

I know I'm a lil late to the party, but this is all flying over my head, can anyone simplify this down to what i put where and how to please?

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  

×