Forum Jump :

Author Message


Posts: 75
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2009-10-06 05:38        
     
I'm kinda tired to typing every time I want a special loadout. So how would I write a script for a custom loadout that I can pull up anytime I need it.

Just guessing:

this addmagazine "magazine"; this addweapon "weapon"

and save this as an SQF file?

Also what would I put in the init line of the soldier with the custom loadout?

Thanks


Author Message

Tom_48_97  

Master lord of the head in the cloud!


Posts: 504
Rank:


Level: Server Admin

Country: 00
Location:
Occupation: Bohemia Interactive Developer
Age:
In-game name: Tom_48_97

 
#2 Posted at 2009-10-06 07:31        
     
well, yes and no :)

script:
removeAllWeapons _this;
_this addMagazine "magName";
_this addWeapon "WeapName";
_this selectWeapon "WeapName";
exit;
And you call it as follow when you want:
Null = unitName exec "scriptName.sqf";

This post was edited by Big (2009-10-06 07:32, ago)

@Tom_48_97 - Bohemia Interactive

Advertisement


Author Message


Posts: 75
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2009-10-08 05:10        
     
tom_48_97 : well, yes and no :)

script:
removeAllWeapons _this;
_this addMagazine "magName";
_this addWeapon "WeapName";
_this selectWeapon "WeapName";
exit;
And you call it as follow when you want:
Null = unitName exec "scriptName.sqf";

Thank you for yout reply. My first question is: Why is "_this" used instead of "this"? Why do you use "selectWeapon"? Why is there need for an "exit" at the end? And lastly why is "Null =" used for the unit? I know these are pesky question, but they may help me understand.

This post was edited by pepsifx357 (2009-10-08 05:44, ago)


Author Message

tcp  



Posts: 52
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#4 Posted at 2009-10-08 06:20        
     
First, if you are going to use exec which calls a script in SQS syntax, please name the script file with a .sqs extension.
SQF syntax (.sqf, called with execVM) should be kept mutually exclusive. Also, SQS is old, so you should start using SQF when possible.

Also, the semi-colon (;) a the end of each line in your sqs script is not required. A new line is considered the end of the last command. Semi-colons are only used when you choose to put two commands on one line. SQF is the syntax that requires semi-colons at the end of each line.

*Note* I only enclose syntax with < > clarification, not to be used as part of a script.

When calling a script from an init line of a unit or trigger, a variable to store the reference to the script (script handle) is sometimes required (namely the editor).
It's actually not required for the exec command, you can simply use <this exec "script.sqs";>
It is required for execVM, so use <Nul = this execVM "script.sqf";> or <_scriptname = this execVM "script.sqf";>
Most of the time you don't need to reference the script, so you use Nul or Null.
Nul is a safe variable to use, because everyone knows not to use it. It's considered a dummy variable.
*note* the reference varible only refers to the scriptname, it doesn't hold a return value as I previously thought.

An underscore (_) preceding a variable, such as <_this>, creates or refers to a local variable. It will not be shared outside the current scope, so, usually, when the script exits, the variable is forgotten. If you wanted to store the value, you would either use a global variable such as <money> (you can't define <this> because it's already used by the game) or you would pass it to another script <[_this, _money] execVM "nextscript.sqf";>

<exit> is considered exiting cleanly out of a SQS script, however, it is not required. If you left it out, the script would still exit. It can also be used anywhere in the script to terminate the script prematurely (e.g. if a certain condition is met). However, another method people use it <goto "end"> with #end place as the last line in the script.

A lot of times, you will see <if(true) exitWith{};> at the end of SQF scripts. This is considered exiting cleanly in SQF syntax.

There's a lot of confusion between SQF and SQS and what is required. What is considered good syntax is debatable.

The SQF version would look called with <Nul = this execVM "arm.sqf";>

arm.sqf
removeAllWeapons _this;

_this addMagazine "magName";
_this addWeapon "WeapName";
_this selectWeapon "WeapName";

if(true) exitWith{}; //not required

Check out my script: Respawning with Saved Loadouts w/ preconfigurable Custom Loadouts

This post was edited by tcp (2009-10-13 22:14, ago)


Author Message


Posts: 75
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#5 Posted at 2009-10-13 12:15        
     
It took a little bit but here's what I did to make it work.

removeAllWeapons _this; 
removeAllItems _this;
_this addWeapon "ItemMap";
_this addWeapon "itemcompass";
_this addWeapon "itemwatch";
_this addMagazine "30Rnd_556x45_Stanag";
_this addWeapon "M4A1_HWS_GL_camo";
_this addMagazine "30Rnd_556x45_Stanag";
_this addMagazine "30Rnd_556x45_Stanag";
_this addMagazine "30Rnd_556x45_Stanag";
_this addMagazine "7Rnd_45ACP_1911";
_This addWeapon "Colt1911";
_this addMagazine "7Rnd_45ACP_1911";
_this addMagazine "7Rnd_45ACP_1911";
_this addMagazine "7Rnd_45ACP_1911";
_this addMagazine "FlareWhite_M203";
_this addMagazine "SmokeShell";
if(true) exitWith{}; //not required

I saved the file Ben_Load_Out.sqf

In the init line of my soldier, who's name was Ben, I put:
Ben exec "Ben_Load_Out.sqf";

this exec "Ben_Load_Out.sqf";
Did not work.
this execVM "Ben_Load_Out.sqf";
Did not work.
Ben execVM "Ben_Load_Out.sqf";
Did not work.
Thanks for all your help guys.


Author Message

tcp  



Posts: 52
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#6 Posted at 2009-10-13 20:36        
     
Good idea on the removeAllItems command, didn't know about that and was getting duplicate items error in my RPT file.

I know it's a lot of reading but I tried to spell this out in my previous post.
Nul = this execVM "Ben_Load_Out.sqf";
You need to put some kind of variable to catch the return value of a SQF script called from the an init line (not required when called within a script). Nul is a reusable dummy variable, could be any unused value. Also < this > can be interchanged with < Ben >.

It's really bad form to try to exec an SQF file, not sure if it still works in some cases, but it only meant for SQS files. You can take out the //not required part.

This post was edited by tcp (2009-10-13 22:15, ago)


Author Message


Posts: 429
Rank:


Level: Member

Country: us
Location:
Occupation: Retired
Age: 54
In-game name:

 
#7 Posted at 2009-10-14 15:28        
     
tcp : ...
It's really bad form to try to exec an SQF file, not sure if it still works in some cases, but it only meant for SQS files. You can take out the //not required part.

Beyond bad form. Put sqf in .sqs can cause all kinds of wierd errors. Exec is for .sqs only - use execVM for sqf.

If you are new and learning, best to learn the sqf format. It's more powerful and allows for better code optimization.

I am fear.

Author Message


Posts: 75
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#8 Posted at 2009-10-15 10:29        
     
I have noticed that when the game starts, my weapon is unusable and I have to switch to my side arm and back to be able to aim or fire. The EOTECH red dot doesn't even show up when my weapon is down, up until I do that. Maybe that is the error you guys are talking about. However, it will not work if I use the command "execVM." I'm still using the format that I posted above for the script. Is there anything I need to be putting in the script for the "execVM" command to work? Also the game is throwing up an error over "SmokeShell." It can't seem to find the .bin file but when I'm in the game, the smoke grande is in my inventory and usable. The error doesn't seem to effect gameplay.


Author Message

tcp  



Posts: 52
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#9 Posted at 2009-10-16 01:08        
     
Nul = this execVM "Ben_Load_Out.sqf";
_loadout = this execVM "Ben_Load_Out.sqf";

The reason for the error is because exec is running the script as SQS which doesn't understand the if statement ("SmokeShell" must be affected because its the preceding line".

Needed after using removeAllWeapons to restore primary weapon selection automatically:
			if (primaryWeapon player != "") then {
				player selectWeapon (primaryWeapon player);
				_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles"); // Fix for weapons with grenade launcher
				player selectWeapon (_muzzles select 0);


Author Message


Posts: 15
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name: islesfan186

 
#10 Posted at 2010-02-06 18:06        
     
ok im pretty new at this. i cant get this scripting to work for the life of me. on the gamestop forums i just copy and pasted an M9 one and it worked fine, but when i changed m9 to M4A1_AIM_SD_CAMO and magainze to 30Rnd_556x45_StanagSD it kept telling me Missing ;

the script looked like:

removeallweapons this; this addmagazine "30Rnd_556x45_StanagSD"; this addmagazine "30Rnd_556x45_StanagSD"; this addmagazine "30Rnd_556x45_StanagSD"; this addweapon "M4A1_AIM_SD_CAMO"

is there something i have to add?


Author Message


Posts: 33
Rank:


Level: Member

Country: us
Location:
Occupation:
Age:
In-game name:

 
#11 Posted at 2010-02-28 05:20        
     
did you try addind a semi colon at the end of this> removeallweapons this; this addmagazine "30Rnd_556x45_StanagSD"; this addmagazine "30Rnd_556x45_StanagSD"; this addmagazine "30Rnd_556x45_StanagSD"; this addweapon "M4A1_AIM_SD_CAMO";<<<<here

im just taking stab at it


Author Message

palyarmerc  

I live inside the editor


Posts: 752
Rank:


Level: Member PFS

Country: 00
Location:
Occupation: *Retired*
Age:
In-game name: *Retired*

 
#12 Posted at 2010-08-15 12:47        
     
Can't remember where I got this - (many thanks to the author anyway) - this does exactly what I'd always wanted
(NOTE: this example requires ACE2 and RH_HK416)

place in your soldiers init line - add more 'cases' to your own design

save the following as your "kitout.sqf"

/*
null = [this, "RH417SD"] call compile preprocessFile "kitout.sqf"
*/

_unit = _this select 0;
_strLoadout = _this select 1;

if (!isServer) exitWith {};

removeAllWeapons _unit;
removeAllitems _unit;

switch (_strLoadout) do
{   
	case "RH417SD":
	{
	      	{_unit addMagazine "RH_20Rnd_762x51_SD_hk417";} forEach [1,2,3,4,5,6,7,8];
	      	{_unit addMagazine "ACE_Morphine";} forEach [1,2,3];
	      	{_unit addMagazine "ACE_Bandage";} forEach [1,2,3];
	      	{_unit addMagazine "ACE_Epinephrine";} forEach [1,2];
	      	_unit addWeapon "RH_hk417sdsp";
		{_unit addMagazine "HandGrenade_West";} forEach [1,2];
		_unit addweapon "Binocular";
		_unit addweapon "NVGoggles";
		_unit addweapon "ItemMap";
		_unit addweapon "ItemGPS";
		_unit addweapon "ItemCompass";
		_unit addweapon "ItemWatch";
		_unit addweapon "ItemRadio";
		_unit addweapon "ACE_Earplugs";
		_unit addWeapon "ACE_PRC119";
		[_unit, "ACE_Bandage",14] call ACE_fnc_PackMagazine;
		[_unit, "ACE_Morphine",14] call ACE_fnc_PackMagazine;
		[_unit, "ACE_Epinephrine",14] call ACE_fnc_PackMagazine;
		[_unit, "ACE_Knicklicht_B",2] call ACE_fnc_PackMagazine;
		[_unit, "SmokeShell",4] call ACE_fnc_PackMagazine;
		[_unit, "ACE_12Rnd_45ACP_USPSD",8] call ACE_fnc_PackMagazine;
		[_unit, "RH_20Rnd_762x51_SD_hk417",4] call ACE_fnc_PackMagazine;
	};
   
};


_primaryWeapon = primaryWeapon _unit;
_unit selectweapon _primaryWeapon;
// Fix for weapons with grenade launcher
_muzzles = getArray(configFile>>"cfgWeapons" >> _primaryWeapon >> "muzzles");
_unit selectWeapon (_muzzles select 0);

....that's all folks....!

Author Message


Posts: 26
Rank:


Level: Member

Country: us
Location: Dallas, Tx
Occupation:
Age: 43
In-game name:

 
#13 Posted at 2012-03-16 11:09        
     
Here is the method I use...

Once you've created these files, you'll need to create a
trigger on the map, set it to Repeatedly. Condition is

alive Player2

...code to execute if condition is met.

Player2 exec "P2Rearm01.sqs";

P2Rearm01.sqs

if (!local Server) exitWith {};
~5
W2Heal = Player2 AddAction ["Heal","P2Heal.sqs"];
RID201 = Player2 AddAction ["Switch weapon to m16a4_acg_gl","P2weap01.sqs"];
RID202 = Player2 AddAction ["Switch weapon to M24 Sniper","P2weap02.sqs"];

exit;

You can add more weapons to the P2Rearm01.sqs file to suit your needs.

P2Heal.sqs

~10

Player2 setdammage 0;

hint "You are healed!";

exit

P2weap01.sqs

removeAllWeapons Player2;

Player2 addMagazine "1Rnd_HE_M203";
Player2 addMagazine "1Rnd_HE_M203";
Player2 addMagazine "1Rnd_HE_M203";
Player2 addMagazine "1Rnd_HE_M203";
Player2 addMagazine "30Rnd_556x45_Stanag";
Player2 addMagazine "30Rnd_556x45_Stanag";
Player2 addMagazine "30Rnd_556x45_Stanag";
Player2 addMagazine "30Rnd_556x45_Stanag";
Player2 addMagazine "30Rnd_556x45_Stanag";

Player2 addWeapon "m16a4_acg_gl";
Player2 addweapon "Throw";
Player2 addweapon "Put";

Player2 selectWeapon "m16a4_acg_gl";
Player2 selectWeapon "M16MUZZLE";

exit

P2weap02.sqs

removeAllWeapons Player2;

Player2 addMagazine "5Rnd_762x51_M24";
Player2 addMagazine "5Rnd_762x51_M24";
Player2 addMagazine "5Rnd_762x51_M24";
Player2 addMagazine "5Rnd_762x51_M24";
Player2 addMagazine "5Rnd_762x51_M24";

Player2 addWeapon "M24";
Player2 addweapon "Throw";
Player2 addweapon "Put";

Player2 selectWeapon "M24";

exit

As many of us do, I as well, come from a Flashpoint, Resistance and Arma background. I was a member of the original DSF clan for about two months, back when Hatcher was in charge, along with Deaddog, Joker, Thatcher, two german dudes, and my callsign was, and still is FullMetal.