Jump to content
Sign in to follow this  
Shinotama

Need Help with Scripting, Please Help

Recommended Posts

Hey guys, I am a complete noob to .sqf scripting..

I would like to know if someone can point me in the correct direct as to a guide on how to initialize scripts in my mission at start as to be able to choose what weapons and ammo etc my characters have.

I have been playing about with the execVM etc but I have no success..

The other part would be that I have been told that I should put them in a folder called "Scripts" inside my mission folder, if this happens then can it also be explained as to how I start these scripts aswel..

Thanks.. Any help would be amazing!!

Edited by Shinotama

Share this post


Link to post
Share on other sites

If you want your players to select their gear from a weapon pool you don't need any scripts. Just add the weapons and magazines to your description.ext file (must be created if it doesn't exist already). Below is an example on how the lines must look like:

// Weapon Selection for BLUEFOR Side
// Adjust amount of Weapons/Magazines as needed
class Weapons
{
 class M16A2                   {count=12;};
 class M16A2GL                 {count=12;};
 class M16A4                   {count=12;};
 class M16A4_GL                {count=12;};
 class M16A4_ACG               {count=12;};
 class M16A4_ACG_GL            {count=12;};
};

class Magazines
{
 class 30Rnd_556x45_Stanag     {count=120;};
 class 30Rnd_556x45_StanagSD   {count=120;};
 class 20Rnd_556x45_Stanag     {count=120;};
};

You don't have to put the scripts inside a "scripts" folder. They work also if you place them just in the missions folder. It's totally up to you where you put the scripts into.

Executing the scripts depends on where they are called at.

Share this post


Link to post
Share on other sites

This is good progress guys =)

Ok, I have used the script

nul = [arguments] execVM "scripts\vampgear.sqf";
in the initialization box on the individual soldier (Which has the tag "SABRE" for other mission triggers later on)

I used the program "Arma Edit" to make my .sqf file

The code I have used in my "Vampgear.sqf" is as follows

removeAllWeapons this;

Exit

Yet when I try the mission in preview and multi-player, I select that soldier with the code, yet I still have the original weapons that he was given by default instead of having them removed.

This would be apparent that either..

  1. The code is not working
  2. I am doing something very simple, very wrong

Any ideas? I apologize as you can tell I am very new yet very eager, as soon as I sort this, my world of scripting opens up =)

Share this post


Link to post
Share on other sites

Yup, the script has no way of knowing that "this" is, so you need to pass it as an argument. You'd do this:

null = [sABRE] execVM "scripts\Vampgear.sqf";

Then your script would have:

_unit = _this select 0;

removeAllWeapons _unit;

Don't need the "exit", that does nothing in SQF.

The way this works is: The [sABRE] part sends the object of your unit to the script. The script then uses the "magic" value of _this select 0 to grab that value, assign it to an interal value of _unit and then runs the removeAllWeapons _unit; command.

So it's the same as if you'd typed removeAllWeapons SABRE; but allows you to reuse the script with others. So null = [bOB] execVM "scripts\vampgear.sqf" would remove all weapons from BOB.

Edited by kylania

Share this post


Link to post
Share on other sites

You sir..

Are a f*****g legend, I would kiss you but I am now busy finding scripts =p

I befriended you if thats all cool if I get stuck again =)

So you say the "Exit" does nothing then?

Weird as most people tend to put it in..

All this is for my "Black Hawk Down" mission I am working on, I am an avid fan of the Operation Flashpoint Series since day 1 =p, well my pre-order that I got a week early =D

Share this post


Link to post
Share on other sites

I think "Exit"is more commenly used in functions with a loop capabillity. Anyway hope you solvedd your problem ? One tip! please change the topic title to something usefull like: "how to set player weapons with a script?" Makes the forum more fun to read! :cool:

Share this post


Link to post
Share on other sites

Exit is a pure sqs command, ignored by sqf scripts, and used to exit the sqs script.

ExitWith on the other hand is used to break out of code blocks, used in the sqf syntax.

Share this post


Link to post
Share on other sites

exit literally does nothing in SQF. It's an SQS command.

To exit a loop in SQF you can use exitWith, and some people incorrectly use it at the end of a script to "exit" it or elsewhere, but what happens in that case isn't always what you want. :) SQF functions exit themselves, no need to declare an exit or anything.

Share this post


Link to post
Share on other sites

Done Done & Done, Check out my Spoiler for the code

//###################################################//

// MISSION LOADOUT SCRIPT CREATED BY SHINOTAMA

//

// INSERT THE BELOW LINE INTO THE INITIALIZATION OF THE SOLDIER IN QUESTION

//

// null = [unitname] execVM "filepath\filename.sqf";

//###################################################//

// SELECTS THE UNIT IN QUESTION //

_unit = _this select 0;

// REMOVES ALL YOUR WEAPONS //

removeAllWeapons _unit;

// ADD YOURSELF SOME EQUIPMENT & AMMO //

// AMMO //

_unit addMagazine "30Rnd_556x45_Stanag";

_unit addMagazine "30Rnd_556x45_Stanag";

_unit addMagazine "30Rnd_556x45_Stanag";

_unit addMagazine "30Rnd_556x45_Stanag";

_unit addMagazine "7rnd_45acp_1911";

_unit addMagazine "7rnd_45acp_1911";

_unit addMagazine "7rnd_45acp_1911";

_unit addMagazine "7rnd_45acp_1911";

_unit addMagazine "1Rnd_HE_M203";

_unit addMagazine "1Rnd_HE_M203";

_unit addMagazine "Handgrenade_west";

_unit addMagazine "Handgrenade_west";

// ADD YOURSELF SOME GUNS & EQUIPMENT //

// PRIMARY //

_unit addWeapon "SCAR_H_STD_EGLM_Spect";

// SECONDARY //

// SIDEARM //

_unit addweapon "Colt1911";

// VISUAL //

_unit addweapon "Binocular_Vector";

// SET YOUR DEFAULT WEAPON //

_unit selectweapon "SCAR_H_STD_EGLM_Spect";

Edited by Shinotama

Share this post


Link to post
Share on other sites

Nice work! :yay: For a challenge, next see if you can get it to use arrays to add multiple magazines with one line of code (hint, use forEach) instead of typing the same line multiple times.

Then see if you can make the script change the weapon based on a second argument like this:

nul = [unitName, "SCAR_H_STD_EGLM_Spect"] execVM "filepath\filename.sqf"

Hint: This will deal with accessing multiple elements within an array and probably also a case statement (to make sure you give the correct ammo for each weapon, start with just two weapons at first. Try using the SCAR_H_STD_EGLM_Spect rifle which uses 20rnd_762x51_B_SCAR magazines and the Sa58V_RCO_EP1 rifle which uses 30Rnd_762x39_SA58 magazines. Look up switch to see how to use the given weapon type to get the magazine type).

Share this post


Link to post
Share on other sites

I shall look into this tomorrow as it's 3am now and I am off to bed :glare: I hate it lol

But yes, I will defiantly look into it =)

Share this post


Link to post
Share on other sites

Ok.. So I managed to get the "forEach" script working but I tried putting the gun into the init line of the soldier and it just loads but without the gun "up" and no knowledge of it in the top right so I have returned it back to how it was.

This is coming along well.

So I don't understand this "Switch" statement? How will that help me?

//###################################################//

// MISSION LOADOUT SCRIPT CREATED BY SHINOTAMA

//

// INSERT THE BELOW LINE INTO THE INITIALIZATION OF THE SOLDIER IN QUESTION

//

// null = [unitname] execVM "filepath\filename.sqf";

//###################################################//

// SELECTS THE UNIT IN QUESTION //

_unit = _this select 0;

// REMOVES ALL YOUR WEAPONS //

removeAllWeapons _unit;

// AMMO //

{_unit addMagazine "30Rnd_556x45_Stanag"} forEach [1,2,3,4,5,6];

{_unit addMagazine "7rnd_45acp_1911"} forEach [1,2,3,4];

{_unit addMagazine "1Rnd_HE_M203"} forEach [1,2,3,4];

{_unit addMagazine "Handgrenade_west"} forEach [1,2,3,4];

// PRIMARY WEAPON //

_unit addWeapon "SCAR_L_STD_EGLM_RCO";

// SECONDARY WEAPON //

//PLACEHOLDER//

// SIDEARM WEAPON //

_unit addweapon "Colt1911";

// VISUAL EQUIPMENT //

_unit addweapon "Binocular_Vector";

// SET YOUR DEFAULT WEAPON //

_unit selectweapon "SCAR_L_STD_EGLM_RCO";

Share this post


Link to post
Share on other sites

Ok fair warning, this steps up the complexity a bit, but it should be good for learning. :)

Here's how to adapt your code so that if you put in a specific weapon class that you've preset in your Switch block, you'll give it the correct ammo automatically. This is pretty limited though, since the script now only knows about two weapons.

The other thing we did was put in an optional argument, for the weapon type. If you don't put in a weapon (or put in one doesn't know about) it will default to giving you the SCAR L Iron Sights.

nul = [this] execVM "fill.sqf"  // No optional argument, so gets Mk16
nul = [this, "SCAR_H_STD_EGLM_Spect"] execVM "fill.sqf" // Known optional weapon argument so gets the Mk17 RCO EGLM
nul = [this, "popsiclestick"] execVM "fill.sqf" // totally incorrect optional argument, so gets Mk16

We do this by using the switch (something) do { case "value": {}; }; control structure.

Here's an example to list the color of a fruit:

switch (fruit) do {
case "apple": {fruitColor = "RED"};
case "banana": {fruitColor = "YELLOW"};
};

It looks at what "fruit" is, then in the case that fruit = "apple", it will set fruitColor to "RED".

Here's the code for your script with the new optional argument. The parts I added are in blue.

//################################################## #//

// MISSION LOADOUT SCRIPT CREATED BY SHINOTAMA

//

// INSERT THE BELOW LINE INTO THE INITIALIZATION OF THE SOLDIER IN QUESTION

//

// null = [unitname, "WeaponClassName"] execVM "filepath\filename.sqf";

//################################################## #//

// SELECTS THE UNIT IN QUESTION //

_unit = _this select 0;

_unitPrimaryWeapon = if (count _this > 1) then {_this select 1} else {""};

_priWeaponMagName = "";

switch (_unitPrimaryWeapon) do {

case "SCAR_H_STD_EGLM_Spect": {_priWeaponMagName = "20rnd_762x51_B_SCAR"};

case "Sa58V_RCO_EP1": { _priWeaponMagName = "30Rnd_762x39_SA58" };

default {_unitPrimaryWeapon = "SCAR_L_CQC"; _priWeaponMagName = "30Rnd_556x45_Stanag"};

};

// REMOVES ALL YOUR WEAPONS //

removeAllWeapons _unit;

// AMMO //

{_unit addMagazine _priWeaponMagName} forEach [1,2,3,4,5,6];

{_unit addMagazine "7rnd_45acp_1911"} forEach [1,2,3,4];

{_unit addMagazine "1Rnd_HE_M203"} forEach [1,2,3,4];

{_unit addMagazine "Handgrenade_west"} forEach [1,2,3,4];

// PRIMARY WEAPON //

_unit addWeapon _unitPrimaryWeapon;

// SECONDARY WEAPON //

//PLACEHOLDER//

// SIDEARM WEAPON //

_unit addweapon "Colt1911";

// VISUAL EQUIPMENT //

_unit addweapon "Binocular_Vector";

// SET YOUR DEFAULT WEAPON //

_unit selectweapon _unitPrimaryWeapon;

Now, the next big trick would be to change from using set weapon + ammo to set loadouts! Like if you put in:

nul = [this, "RIFLE"] execVM "fill.sqf"; // give the unit a rifleman loadout
nul = [this, "TEAMLEAD"] execVM "fill.sqf"; // give the unit a Team Lead loadout

So instead of just setting the weapon and magazine types you'd set the whole loadout, so the RIFLE case would assign someone a Mk17 CCO (SCAR_H_CQC_CCO) and an M9 and some grenades while the TEAMLEAD would get the MK17 RCO EGLM and a Colt 1911. Hint, you'll end up moving the addWeapon and addMagazine commends inside the case: statements.

Give that a try. :)

Share this post


Link to post
Share on other sites

So you would set custom loadouts depending on what "loadout" you set the second part of the name too?

Thats quite good, how would you insert that into the code though? "If" we where to start again that is..

Share this post


Link to post
Share on other sites

Instead of:

case "SCAR_H_STD_EGLM_Spect":

You'd use:

case "TEAMLEAD":

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  

×