Jump to content

Getting Started Scripting


Xzempt

Recommended Posts

Is there a tutorial anywhere to help newbies get started learning to script in Arma3? I keep trying to run the editor on Multiplayer but when I select my role and then click ok it just gets stuck at the map screen with the continue/cancel button. Nothing is clickable or anything. Obviously I would need whatever I make to work with multiplayer.

 

I have found this: https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3 I'm sure that will come in extremely handy.

Any other information would be greatly appreciated.

Can someone point me towards tutorials on getting started and any documentation for scripting or related documentation of functions and what not?

Edited by Xzempt
Link to comment
Share on other sites

Anyone care to give me a hint on this?

Error in expression <andom(count _crashPos));


_crashMarker = createMarker ["Warning",[_randomPos]];
_>
23:06:27   Error position: <createMarker ["Warning",[_randomPos]];
_>
23:06:27   Error 1 elements provided, 3 expected

script file:

//create crash position
_crashPos = ["5466.86,14993.9","9144.6,21475.8","26880.7,24573.7","6504.54,12306.3","8313.33,9570.95","10717,7612.08,20998.7","7300.87,24181.5,15575"];

//should return position from above array
_randomPos = floor(random(count _crashPos));
_crashMarker = createMarker ["Warning",[_randomPos]];
_crashMarker setMarkerShape "Ellipse";
_crashMarker setMarkerType "Empty";
_crashMarker setMarkerColor "ColorRed";
_crashMarker setMarkerSize [400,400];

 

Link to comment
Share on other sites

Follow the syntax: https://community.bistudio.com/wiki/createMarker

As error states - it requires 3 elements in an array of position, you only gave it one.

Secondly - do not use quotation marks on integers, that makes them string... like you know.. a text, not a float/number

_var = 0; //this is an integer
_var = 0.1; // scalar/float/decimal
_var = "yo"; //string
_var = {}; //code block or function
_var = []; //array


And lastly, positions are 3 elements in an array - like [0,0,0] (x,y,z)
You are telling script to count an array (amount of elements in a single integer) and passing this single integer inside faked array to a command that requires an array with 3 integers inside it, getting the idea?

Solution: Nested array (and don't use "", lol)
Nested array is an array [] inside another array - [[]]. This means you can take several position arrays and put them into a larger array like so:

[[0,0,0],[1,1,1],[2,2,2]]



Think of an array as a memory block in your RAM, like a "group" or a "folder" that can hold any type of variable inside of it, even other arrays.

You access elements inside array by using select command. Array counting starts from 0, so first element is 0, second is 1, third is 2 etc...
 

_location = [0,0,0];
_x = _location select 0;
_y = _location select 1;
_z = _location select 2;

The integer after select can be dynamic - a variable... something you can select randomly.

_crashPos = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]; //large nested array with 3-element position arrays
_random = _crashPos select floor random count _crashPos ; //reads in reverse - count our large array, so we know max number we can safely choose, then choose random float from this value (large decimal) and floor it so its a single value integer... then use this value to select an element.
_crashMarker = createMarker ["Warning",_random];

 

You might want to consider learning basics of variable manipulation, bro. Grab yourself a dev console and play around with variables and some math. The stuff you want is on very top in a wiki page you linked yourself in OP post.

Link to comment
Share on other sites

Time isn't a problem for me, haha. Just need someone/where to bounce things off of when I get stuck.

 

Edit: Which reminds me. Is it possible to add items to the inventory of a wreck like "Land_UWreck_Heli_Attack_02_F"

Edited by Xzempt
Link to comment
Share on other sites

you can't put vehicles in your inventory, if I understand your question correctly. Also lol.

However, mr IT07 is right, you can spawn weapon holder (invisible) container and put loot inside it. But you will be reinventing the wheel, because this has been already done and is part of vanilla mod. Just reuse Epoch's function that does this, you can find it in server side files I believe.

Link to comment
Share on other sites

you can't put vehicles in your inventory, if I understand your question correctly. Also lol.

However, mr IT07 is right, you can spawn weapon holder (invisible) container and put loot inside it. But you will be reinventing the wheel, because this has been already done and is part of vanilla mod. Just reuse Epoch's function that does this, you can find it in server side files I believe.

I was asking can you put items in the vehicles inventory. I know you can on a perfectly healthy vehicle. but In this case it's a wreck vehicle.

Link to comment
Share on other sites

I was asking can you put items in the vehicles inventory. I know you can on a perfectly healthy vehicle. but In this case it's a wreck vehicle.

Well, yes and no. Vehicles has what's called "named selections" that are defined when model is created. These selections are used to give objects certain properties, like - a cargo/container space. This ofc means if wreck does not have one, then answer is no. You can check if vehicle has cargo by just looking at it and trying to store items in it.
When making your own @mods, you can add cargo spaces yourself (as long as you have access to unbinarized p3d files).... in your case as server admin, answer is still a no.

However, nothing is stopping you from using cargo space as a separate (invisible object that was designed specifically for this task) vehicle/object spawned beneath or nearby this wreck that can hold your items, just like original script does it. (The stuff i was talking about)

Link to comment
Share on other sites

Well, yes and no. Vehicles has what's called "named selections" that are defined when model is created. These selections are used to give objects certain properties, like - a cargo/container space. This ofc means if wreck does not have one, then answer is no. You can check if vehicle has cargo by just looking at it and trying to store items in it.When making your own @mods, you can add cargo spaces yourself (as long as you have access to unbinarized p3d files).... in your case as server admin, answer is still a no.

However, nothing is stopping you from using cargo space as a separate (invisible object that was designed specifically for this task) vehicle/object spawned beneath or nearby this wreck that can hold your items, just like original script does it. (The stuff i was talking about)

Thanks for your answer. I will never learn if I use  already existing scripts though. I'm aware that re-inventing the wheel is mostly useless, however  it does have it's purposes. lol

This is my first attempt at arma3 scripting and I'm learning slowly using the link I linked in the first post and through input from others. Thank you very much for your time in replying and helping me out. It's greatly appreciated.

 

Oh, and one more thing. I don't guess scripts made in the  local editor (not mp one) will work on a server huh? Still don't know why I can't use the multiplayer editor...

Edited by Xzempt
Link to comment
Share on other sites

Oh, and one more thing. I don't guess scripts made in the  local editor (not mp one) will work on a server huh? Still don't know why I can't use the multiplayer editor...

There is no such thing as MP editor and there is no such thing as single player. You could watch first part of video from thread you can find in my sig, it explains how files and MP environment is loaded. Granted video is a bit dated and now I know a ton more about engine, but majority of it is still accurate even for Arma 3.

When it comes to scripting, anything you put in your mpmissions will be read by both client and server. Server is first to load everything, then joining clients does the same.
However you can prevent client or server from loading specific function or loop if you want to and there's several ways of doing it:
1) For server only scripts, simply put your scripts in server side @mod. You can ofc also use mpmissions pbo, like init.sqf, which is the very first file to be read after mission namespace is created. You can then use !hasInterface or isDedicated booleans inside IF statement to make sure only server reads your stuff. When client goes trough this file, it will ignore anything under the statement.
2) For client side as an admin (unless your clients are willing to download @mods) you are limited to init.sqf file (preferred by new coders) or cfgFunctions in description.ext to define functions or run code. This is not a bad thing, don't get me wrong, it gets the job done. Ofc there are ways of putting client code server side, essentially hiding it, but those are more advanced techniques that almost nobody around would be willing to share (i will at some point).
So anyway... to make sure only client loads your stuff, you simply use the opposite of previously mentioned commands - hasInterface or !isDedicated

There is third command for similar task, but personally I'd rather use it only if you want to launch something Editor specific. Command is isServer. This command will be true if you are in editor and false if in MP, true for dedicated server. Problem is, when you develop scripts in editor and port them to MP, this command will cause issues as the statements will be reversed, so try to avoid it and get into habit of using isDedicated command instead.

TIP: make local test server with full features of A3 epoch and shit, set verifySignatures to 0 and enable dev console in your description.ext (google this one). This will allow you to write scripts in live MP game, but in a shitty console... still better than nothing constantly restarting for small tests

Anyway, feel free to ask more questions if you got any.

Edited by raymix
Link to comment
Share on other sites

timer = 5; //seconds

//simple timer
[] spawn {
    //do stuff
    uiSleep timer;
};

//wait for timer
[] spawn {
    uiSleep 10; //sleep 10 seconds
    timerDone = true;
};

[] spawn {
    waitUntil {timerDone};
    hint "10 seconds passed";
};

//wait for timer while loop method
[] spawn {
    _count = 0;
    while {_count < 10} do {
        _count = _count + 1;
        uiSleep 1;
    };
    hint "10 seconds passed";
};

//count to 10
[] spawn {
    for "_i" from 1 to 10 do {
        _count = _i;
        hint str _count; //outputs current count
        uiSleep 1; //wait 1 sec
    };
    hint format ["I counted to %1",_count];
};


I could go on like this for a while (lol), but hope you get the drift....plenty of ways to do it. As you can see code suspension is done by simply using sleep or uiSleep commands.
By now you probably noticed I've used spawn command a lot, this is because there are 2 code environments - scheduled and unscheduled.
Normally game runs in unscheduled env, this means you cannot suspend code using sleep or waitUntil, even loops are reduced to 10000 iterations, but if you wrap your code around spawn tag, it will work just fine without limits.
Think of it as running a code block on a separate thread, but this also means that rest of script will not be waiting on it. This means you will have to get creative with it if your unscheduled environment depends on variables gathered from scheduled env.

Makes sense?

Link to comment
Share on other sites

You can use sleep with execVM, yup. And it's still perfectly safe to run spawn inside executed scripts, too.

ExecVM is actually very similar to spawn, both runs in scheduled env, difference is - execVM is used to run script file from hard drive and spawn is used to run functions or code blocks from RAM. Spawn also always require parameters, hence [] in front.

another command would be call, just like spawn, it runs functions and code from RAM, but you can only use sleep with call in scheduled evironment (ie. call is part of spawned code).

Link to comment
Share on other sites

Can someone point me to what I'm looking for here. I have 2 variables. both numbers, I need to choose a random number between the 2 variables. What command am I looking for. I don't think random will do that will it?

 

I mean I could do:

 

 

_minimumValue = 5;
_maximumValue = 10;
_number = random(_maximumValue);
if (_number < _minimumValue) then {
_number = _minimumValue;
};

But wouldn't that make _minimumValue the more oftenly chosen number?

Edited by Xzempt
Link to comment
Share on other sites

hmm, won't that some times give me a number below the _min value?

say for instance, if

(random floor _min) returned 1 and 
(random floor _max)returned 3

1 + 3 / 2 = 2. ya?

 

I ended up doing it like this

    _number = floor(random _maxCrashProtectors);
    
    if (_number < _minCrashProtectors) then {
        _number = _minCrashProtectors;
    }
    else {
        _number = _maxCrashProtectors - _number;
    };
    while {_number < _maxCrashProtectors} do {
        _soldierCrash = _soldiers select floor random count _soldiers;
        _soldierCrash createUnit [_randomPos,_crashGroup ,"this allowFleeing 0", 0.5, "Private"];
        _number = _number + 1;
    
    };

Is this bad? I read somewhere using while is bad?

Edited by Xzempt
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...