Jump to content
Ranwer135

Scripting Introduction for New Scripters

Recommended Posts

G'day guys,

 

There has been a lot of new threads by newcomers that ask the same/similar questions, found in many other threads.

 

 

If you are new to ArmA or want to get into scripting, welcome to the forums!  :) 


As you know, there is a search box at the top of the page, it can be used to search throughout every thread what you are after. Bear in mind that it may sometimes not provide you with the proper answer. This, however, doesn't mean that another thread should be opened. In fact, there is a huge library of scripts you probably never heard of.

Check it out, there is an abundant of examples provided in each script command: https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

It is constantly being updated with new facts, info and scripts by many of our users such as KK. (Killzone Kid)
 

 

Lastly, here are some basic info and tips on scripting.

 

  •  To create your own scripts, navigate to "My Documents\Arma 3\missions\your_saved_mission". Then, create a text document and rename the extension ".txt" to ".sqf". Once done, open it with Notepad or Notepad++.

 

  •  To run your script in the game, navigate to your mission folder and create a "init.sqf". Open it and put this in:
[] execVM "myscript.sqf";
  •  If you want to get a specific unit to do some action (e.g. setDamage or setFuel), give your unit a name but without spaces. Then in a trigger, put this in:
myguy setDamage 1;
  • The symbol ";" used after each command, is to separate the command from another. (Think of it as a period symbol)

Also, if you are thinking that Steam Workshop is the only place for mods, addons, scripts, etc. Armaholic is the official site for releasing such. You can find it here, they also have a FAQ as well: http://www.armaholic.com

  • If you want to convert a string to code, you can use call compile STRING. This is very handy (and sometimes a smart trick) when passing code around such as lbData. ;)

 

 

This wraps up the introduction for those new to scripting. If you have any questions, concerns or ideas that may improve this thread, feel free to post here.  ^_^

 

 

Happy Scripting, ;)

 

 

Rawner135

 

 

 

ArmA 3 Tutorial Links:

 

Arma 3 Scripting Tutorial For Noobs - forums.bistudio.com

[Tutorial] Server Side Scripting - forums.bistudio.com

Camera Scripting - www.armaholic.com

KK's blog - ArmA Scripting

 

Videos:

 

 

 

Modding Tutorials by GameDev Byrne:

https://www.youtube.com/playlist?list=PLqRU_EL4pwOHOJ6L2P5XlpfmNoWqulZqf

 

 

Other Tutorial Links:

 

http://www.kylania.com/ex/
Conversation System
Mission Editor 
ArmA 2 Mission Editor
Triggers
OFPEC
ArmA 2 Scripting Commands
ArmA2 COMREF
Forums Post - Classnames
ArmA2 Library
ArmAholic
ArmA2 Moves
ArmA2 Modules
Description.ext
Scripting Topics (Check All Links)
Startup Parameters
Crash Files
Tasks
ARMA 2 Functions
PostProcess Effects

  • Like 12
  • Thanks 1

Share this post


Link to post
Share on other sites

First of all using execVM or spawn is bad practice, it clogs up the scheduler and can be avoided in 100% of cases.

Putting your scripts / functions in init.sqf is also very bad practice since it runs on all machines.

If you want to run a script / function use preprocessFileLineNumbers or cfgFunctions and make sure it's not executed globally unless it's needed.

  • Like 1

Share this post


Link to post
Share on other sites

First of all using execVM or spawn is bad practice, it clogs up the scheduler and can be avoided in 100% of cases.

Putting your scripts / functions in init.sqf is also very bad practice since it runs on all machines.

If you want to run a script / function use preprocessFileLineNumbers or cfgFunctions and make sure it's not executed globally unless it's needed.

 

This is not the first time I see a member of ACE3 team talking utter nonsense. If I was Nou I'd ban everyone from showing any ACE3 association in signatures, gives the whole ACE3 team a bad rep when they start saying stupid things like this in public. 

  • Like 17

Share this post


Link to post
Share on other sites

This is not the first time I see a member of ACE3 team talking utter nonsense. If I was Nou I'd ban everyone from showing any ACE3 association in signatures, gives the whole ACE3 team a bad rep when they start saying stupid things like this in public. 

 

what was wrong with it?

Share this post


Link to post
Share on other sites

First of all using execVM or spawn is bad practice, it clogs up the scheduler and can be avoided in 100% of cases.

Putting your scripts / functions in init.sqf is also very bad practice since it runs on all machines.

If you want to run a script / function use preprocessFileLineNumbers or cfgFunctions and make sure it's not executed globally unless it's needed.

 

Um...this thread is a basic introduction for new scripters to get them started. New scripters need to know the very basics and fundamentals of coding, before they start getting into advanced coding. (Same thing for me, I had to read, learn and study the docs found on the BIKI, before getting more deeper into coding)

 

 

First of all, there is nothing wrong with execVM or Spawn. However, using execVM constantly may and WILL clog up the CPU memory (only if used at a majority of times with heavy-weight code such as while). Says it all here on the call function (which I assume you didn't read), found in the BIKI:

 

 

"Executes the function string. The argument(s) (if any) are passed as _this. (argument(s) are passed in an array). To execute a sleep function in the called code, execute it with spawn instead."

 

 

Another words, any form of script suspension (e.g. waitUntil, sleep, etc.) has to be executed with spawn.

 

 

 

Placing them in an init.sqf (During MP) will likely mess up the functions since it is server-based, yes. But it is perfectly alright if you were to have the mission/mod SP-based. Also, defining multiple functions in an .sqf file for CfgFunctions is one of the ways where you can easily get frustrated, as CfgFunctions will only turn your .sqf file into a function (without the need for inserting brackets). If I were you, I would have an .sqf file (call it compiles.sqf) that lists and compiles all the available functions you want stored as memory. And lastly, if you want to protect your functions against hackers, I would suggest using compileFinal.

 

 

More info on code optimization as well: https://community.bistudio.com/wiki/Code_Optimisation

 

 

 

Also, I don't quite understand why you should avoid scheduled events. In fact, if I recall, thousands of code posted on Armaholic is represented as in a Scheduled environment. If there was no scheduled environment, how the hell would BI and BIS be still here after all this?

  • Like 8

Share this post


Link to post
Share on other sites

Theres nothing wrong with while loops, scheduled code, execvm, spawn, etc.

 

Lots of soldiers out there now on the servers enjoying fun content which is packed to the gills with 'bad practice'. Only the misinformed, the nit-pickers and the OCD choose to poorly optimize their time by thinking about these things.

 

From my experience, the code which produces the lowest CPU / FPS burden, is the code with the fewest evaluations per time period. Which baffles me when people claim functions like onEachFrame is more performance friendly than a while loop with a sleep. The only negative to a while loop is that it evaluates a condition on each iteration. Caring about that, IMO, is nitpicking.

 

If there's one constant in A3 modding community, its that the perfectionists never finish anything.

  • Like 8

Share this post


Link to post
Share on other sites

Hello everyone,

 

Just wanted to share my experience, as Antistasi I think is probably one of the heaviest missions around the scene, I can say a few things.

 

First: It is not ultra code performance made. Indeed me, as coder, compared with, let's say Killzone, it's like comparing God with a worm.

 

But worried about performance I made several tests because there can be thousands of iterations, waituntils etc.. running in an Antistasi server on the same time.

 

Well, just I'll say: spawning a group eats more CPU than one thousand scripts running at a time.

 

So, as someone said before: there is a lot of fun things to enjoy prior to have the perfect code running. Better check how many units you spawn in map than think about it's better an EH than a while than a waitUntil....

 

As this post is made for beguinners, let's don't mess them up with code optimisation as their first worry is to copy paste some code and make it work :)

  • Like 7

Share this post


Link to post
Share on other sites

A piece of advice to existing programers considering SQF:

_a = 1; { _a = 2; } forEach [1]; hint str _a;  // 2
_a = 1; { _a = 2; }; hint str _a;  // 1
And a lot more of things like this. Think twice.
  • Like 2

Share this post


Link to post
Share on other sites

A piece of advice to existing programers considering SQF:

_a = 1; { _a = 2; } forEach [1]; hint str _a;  // 2
_a = 1; { _a = 2; }; hint str _a;  // 1
And a lot more of things like this. Think twice.

 

 

Oh yes, another extremely useful advice for scripting beginers.

 

My next post will be a relation between quantic states of electrons inside the CPU and AI behaviour when they are behind a rock :)

  • Like 5
  • Haha 1

Share this post


Link to post
Share on other sites

I used to mess around with Operation Flashpoint scripts, after a while I could usually open up the .sqs files and figure out what was going on... 

 

?!(alive _man): goto "dead"

#dead

 

it was pretty easy to follow where loops were going

 

Coming back to arma 3 and opening some .sqf files, lol I am lost

Share this post


Link to post
Share on other sites

I used to mess around with Operation Flashpoint scripts, after a while I could usually open up the .sqs files and figure out what was going on...

?!(alive _man): goto "dead"

#dead

it was pretty easy to follow where loops were going

Coming back to arma 3 and opening some .sqf files, lol I am lost

If you see something you dont understand, go to biki and search for it, chances are 95% of the time the answer will be there. biki is also not as it used to be (in a good way)
  • Like 1

Share this post


Link to post
Share on other sites

If you see something you dont understand, go to biki and search for it, chances are 95% of the time the answer will be there. biki is also not as it used to be (in a good way)

Oh I know, I am constantly referencing the biki... seems things are just a lot more complicated now. For the better I'm sure

Share this post


Link to post
Share on other sites

Ok I'm not sure how relevant this question is to the post but as a new member to the forum I am forbidden to create a new thread.

 

I am not totally new to mission editing and what-not but I'm seriously struggling with my mission.

 

I am hosting via Nitrado and I have made a CTI-style mission with respawn tickets. I have it set so that when you deplete the enemy tickets or take their base you win the round. This is working totally fine. Everything is working fine but when the mission is completed nothing happens. The only way I can get the mission to restart is by restarting the server manually which, as you can imagine is super annoying and I am positive that there MUST be something I am missing out. 

 

I get the popup telling me that the mission has been completed, it drops me into the end mission screen which displays stats and that kind of stuff but then you go back into the server in its current state.

 

​Can anyone advise how to cause the mission to restart?

Share this post


Link to post
Share on other sites

Can someone help me?

Im trying to make an gungame mission but I don't know how to make an gungame script, if anyone know how to make an gungame script please help me :D

Share this post


Link to post
Share on other sites

Ok .... so I'm the FNG to scritping and was unable to find a topic pertaining to my issue. I have/am using Igiload script for the C-130J, it works as advertised, but only once. I have to restart the mission editor so that it will work again. My unit is wanting to test this out in a mp mission, so the question is how do I or what line of script do I add to  make this function work all the time?

Any help would be greatly appreciated.

  • Like 1

Share this post


Link to post
Share on other sites

Scheduled code bad? or unscheduled? No neither are "bad" or "good" it's purely down to a use case basis.
The scheduler only gets bogged down if a script fails to complete it's full execution, but the scheduler can be unbogged simply by using sleeps inside of the code.

Also if the code originated from a scheduled environment e.g the initServer.sqf It is pretty much required. As killzone_kid brought up a while back and I made a comment about it you can go from

unscheduled script to scheduled but not the reverse unless you use a "hack" like call.fsm which forces it back into the unscheduled environment. The only problem with scheduled code is

time-pacing it sometimes will not complete when you expect it to complete. 

Share this post


Link to post
Share on other sites

Hey Guys,

 

Im looking for some help in setting up a Rush Game mode in Arma for Mulitplayer. Yes I know it was already recreated, but the original creator took it down and never revealed the script and mission details and all the servers shut down. Ive currently got the basics set up and the map set up, but could use help in setting up the objectives, displaying tickets, setting combat zones and punishments for leaving the combat zone, also for succeeding and failing for attackers and defenders, moving on to the next set of MCOM's, setting up briefing in deployment, draining tickets, and you know such and such. I know basic scripting, but I haven't made many single and multiplayer missions in Arma, always been more of player not creator, but would like to create this mission and game mode and publish it to the steam workshop and let everyone set up Rush Servers so I can play a competitive game mode in Arma against other players. Any assistance or pointing me to forums or videos that could help me, would be much appreciated.

Share this post


Link to post
Share on other sites

mostly u will not get an answer for those bunch of help requests. my advise is to start ur project with reading as much as u can about scripting and editing. do some usefull posts at other topics in the forum to raise your post count between 5 and 10 until u r able to do own topics. then if u get a problem while scripting or u get stuck somewhere ask for a specific thing in ur own topic and if someone sees it and is able to help u u will get that help.

i think this is not ur expected answer but it is the answer one could expect in this topic.

  • Like 2

Share this post


Link to post
Share on other sites

mostly u will not get an answer for those bunch of help requests. my advise is to start ur project with reading as much as u can about scripting and editing. do some usefull posts at other topics in the forum to raise your post count between 5 and 10 until u r able to do own topics. then if u get a problem while scripting or u get stuck somewhere ask for a specific thing in ur own topic and if someone sees it and is able to help u u will get that help.

i think this is not ur expected answer but it is the answer one could expect in this topic.

This, plus this thread is intended to teach on and summarize basic scripting subjects, not provide project help, those types of requests can be put here: https://forums.bistudio.com/forum/200-arma-3-find-or-offer-editing/

 

That is if you really want an extra hand, but if you want to actually learn, saroghtyp covered it.

Share this post


Link to post
Share on other sites

This, plus this thread is intended to teach on and summarize basic scripting subjects, not provide project help, those types of requests can be put here: https://forums.bistudio.com/forum/200-arma-3-find-or-offer-editing/

 

That is if you really want an extra hand, but if you want to actually learn, saroghtyp covered it.

Sorry it was my mistake.

Share this post


Link to post
Share on other sites

Posts: 1 

Rank: 

Level: Member

Country: 

Location:

Occupation:

Age:

In-game name:

 

#1 Posted at 2016-04-10 16:25        

     

Hi i need help to create a task. 

i remember that was a script to complete one task with waypoints you had make and assign a new one but i cant found it

Share this post


Link to post
Share on other sites

Neat tip:

To easily make mutexes / semaphores in a scheduled (can sleep) environment, use the pushBackUnique command, which is an easy alternative to the more common compare-and-exchange instruction you'd find in many CPUs or interpreters.

The key here is that pushBackUnique is a single scripting command (seems to be an atomic unit for the engine) and returns -1 if the element is already there or its new index if not.

So given an empty array as a starting lock, if you try to add a single member (ie. a digit 1), you can get 0 (index, you got the lock) or -1 (somebody else was faster).

_acquire_lock = {
    waitUntil { (_this pushBackUnique 123) == 0 };
};
_release_lock = {
    _this deleteAt 0;
};

_lock = [];

...

_lock call _acquire_lock;
... do work ...
_lock call _release_lock;
The code above could be easily enhanced with canSuspend to work in unscheduled environment (cannot sleep) as well, returning ie. 'false' if the lock couldn't be acquired.

This could in theory work reliably with publicVariables, but I haven't really stress-tested it to see how the uniqueness check works across network.

Note that while the engine doesn't currently execute more than one script at a time, it can cut off a script in a scheduled environment at any single scripting command, raising the need for proper mutexes if multiple scripts perform conflicting actions.

  • Like 3

Share this post


Link to post
Share on other sites

I need help with scripting ai to make them land at a airport and rearm/repair at a specific point. I have searched the forms to no avail if their is such a post about this i would gladly like to get to it. I am new to coding and could use so help. Thank you

Share this post


Link to post
Share on other sites

Thanks for the warm welcome. I just now need ability to make threads so I could ask an actual question.

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

×