Jump to content
Sign in to follow this  
mia389

Script not running (loadout script)

Recommended Posts

First, I do not know anything about scripting. I made this script from other scripts that I have found. I have this script in all of my team leaders init line. When I host my mission my load out will work. But my other team leaders will have default loadouts. How can I fix this? Here is my script.

removeAllWeapons _this;
//Mags
{_this addMagazine "20Rnd_762x51_SB_SCAR";} count [1,2,3,4,5,6,7,8,9];
{_this addMagazine "smokeShellRed";} count [10,11];
_this addMagazine "HandGrenade_West";
{_this addMagazine "ACE_33Rnd_9x19_G18";} count [1,2];
{_this addMagazine "ACE_Morphine";} count [3,4];
{_this addMagazine "ACE_Bandage";} count [5,6];
{_this addMagazine "ACE_Epinephrine";} count [7,8];
//Weapons
_this addWeapon "SCAR_H_CQC_CCO_SD";
_this selectWeapon "SCAR_H_CQC_CCO_SD";
_this addWeapon "ACE_Glock18";
_this addWeapon "BINOCULAR"; 
_this addWeapon "ACE_Map_Tools";
_this addWeapon "ACE_EARPLUGS"; 
_this addWeapon "ACE_DAGR";
_this addWeapon "ACE_MX2A"; 
//Backpack
_this addWeapon "ACE_VTAC_Rush72";
[_this, "SmokeShellBlue", 6] call ACE_fnc_PackMagazine;
[_this, "20Rnd_762x51_SB_SCAR", 6] call ACE_fnc_PackMagazine;
[_this, "ACE_Morphine", 6] call ACE_fnc_PackMagazine;
[_this, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;
[_this, "ACE_Epinephrine", 6] call ACE_fnc_PackMagazine;
[_this, "NVGOGGLES", 1] call ACE_fnc_PackMagazine;

I call it using this

null = this execVM "loadout\tl.sqf";

Share this post


Link to post
Share on other sites

Problem is caused by locality.

Try adding this as the very first line:

waituntil {time>0};

That way everyone will be in game and have control of their unit before loadout changing is tried. Also, you might want to add selectweapon in there.

Share this post


Link to post
Share on other sites

Another option is to do "call compile preprocessfile" instead of execvm.

Share this post


Link to post
Share on other sites

Just a couple of words on practice. Although fully legal to use player execVM and in the script use _this, a better practice is to use [player] execVM and in the script use _unit = _this select 0; then applying everything to _unit instead of _this.

The benefit isn't easy to grasp, but you get consistent looking code everywhere, and it makes it easier to expand what you send to your script. I don't know if there are any memory and speed repercussions of significance from sending one element as an array or sending one element as an element though.

I believe you will come to the same conclusions once you gather experience. But nice to start early.

Share this post


Link to post
Share on other sites

I'm surprised that a script with lines like...

{_this addMagazine "20Rnd_762x51_SB_SCAR";} count [1,2,3,4,5,6,7,8,9];

... works at all. This should just cause an error. You want to use forEach, not count.

Share this post


Link to post
Share on other sites

Ouch! I failed to see that :) Yeah I think using count like that would throw an error :p

Add "-showScriptErrors" (but without the "s) to your startup shortcut line to easier spot errors.

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

I get no error at all with the above script. How else would I add the 9 magazines? What ST_Dux says makes no sense to me as I know nothing of what hes talking about lol

@SHK

I tried the waituntil {time>0}; I have not tested it though. Im not sure what you mean by "call compile preprocessfile". That is over my head. I will need an example if the waituntil {time>0} doesn't work for me.

Share this post


Link to post
Share on other sites

Lol, just tested. And indeed it works.

But only from a script. From a init field I get the expected error message.

If I replace in script (init.sqf) to:

{ww addMagazine "20Rnd_762x51_SB_SCAR";} 9;

it also gives the error message.

But count [1,2,3,4,5,6,7,8,9] is the same as 9, so it's damn funny one works but not the other :D

So even if it happens to work, it actually shouldn't. Better off changing count to forEach. This would truly qualify as them "Happy little bugs" as Bob Ross would put it :D

Btw, as you say yourself, "I do not know anything about scripting", scripting for ACE is probably not the first thing you want to do. It's like learning to drive using a semi. There is just going to be so many concepts that will confuse you. Second, scripting for MP is most definitely not where you want to start. This is learning to drive with a space shuttle. There is so much to learn before you jump that wagon. The learning curve is already hard, you're just going to get extremely frustrated.

Do the tutorials, do the small stuff. Experiment. Check out what others have done (the simple missions, don't even go into campaigns yet). Learn to use the biki - always have the commands up, and keep an eye up for those EG/AL type images at the top of each command - they are very important for MP scripting. Do read the stickied topics, they're there for a reason.

About your script, I never use init fields, but instead spawn a script that equips players. Here is the typical style I use:

[] spawn {
waitUntil {player == player};
if (!local player) exitWith {};
removeAllWeapons player;
removeAllItems player; //If you need detailed control over what items your player gets, like GPS, watch, map etc.
_ply = player;
_str = format ["%1", player];
switch (true) do {
	case (_str in ["alpha_1","alpha_2"]) : {
		{_ply addMagazine "20Rnd_762x51_B_SCAR";} forEach [1,2,3,4,5,6,7,8,9];
		_ply addWeapon "SCAR_H_CQC_CCO";
//			... etc etc ...
	};
	case (_str in ["alpha_3","alpha_4"]) : {
		{_ply addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4];
		_ply addWeapon "SCAR_L_CQC_Holo";
//			... etc etc ...
	};
};
_primw = primaryWeapon _ply;
if (_primw != "") then {
	_ply selectWeapon _primw;
	_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
	_ply selectWeapon (_muzzles select 0);
};
};

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites
But count [1,2,3,4,5,6,7,8,9] is the same as 9

Except when count is preceded by a code block.

This optional code block is run for every element. That's why it works in the OP's example. Note that the array elements itself are meaningless here. It's their amount that counts (literally). He could also have used ["Frog", nil] instead of [1, 2].

Share this post


Link to post
Share on other sites

There's a real command for it as well:

for "_i" from 1 to 9 do {};

Share this post


Link to post
Share on other sites

That's actually quite funny. It's interesting that count will assume true if the code block doesn't return any boolean value.

Share this post


Link to post
Share on other sites
That's actually quite funny. It's interesting that count will assume true if the code block doesn't return any boolean value.

Did you actually test that? It will iterate through the whole array, no matter if they return false/true/nothing.

Share this post


Link to post
Share on other sites

From CarlGustaffa

[] spawn {
waitUntil {player == player};
if (!local player) exitWith {};
removeAllWeapons player;
removeAllItems player; //If you need detailed control over what items your player gets, like GPS, watch, map etc.
_ply = player;
_str = format ["%1", player];
switch (true) do {
	case (_str in ["alpha_1","alpha_2"]) : {
		{_ply addMagazine "20Rnd_762x51_B_SCAR";} forEach [1,2,3,4,5,6,7,8,9];
		_ply addWeapon "SCAR_H_CQC_CCO";
//			... etc etc ...
	};
	case (_str in ["alpha_3","alpha_4"]) : {
		{_ply addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4];
		_ply addWeapon "SCAR_L_CQC_Holo";
//			... etc etc ...
	};
};
_primw = primaryWeapon _ply;
if (_primw != "") then {
	_ply selectWeapon _primw;
	_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
	_ply selectWeapon (_muzzles select 0);
};
};

Instead me trying to reinvent the wheel I should have asked! This is what I needed from the start. Now does that go into the init.sqf?

---------- Post added at 03:25 PM ---------- Previous post was at 02:04 PM ----------

It worked great in the init. This is a MP mission. Will the above work for JIP players?

Share this post


Link to post
Share on other sites

I do it a little differently myself in MP, by having a JIP script being started from a trigger, that does all of the player setups (incl actions, weapon loadouts, ammo crates, variables etc) but only because that method is already there for me :)

And it's better to spawn a secondary script than messing up your init.sqf. Here I only waitUntil {player == player} (which is same as waitUntil{time>0}), but you should also wait until any precompiled functions etc are done compiling, so that these can be used during player setup. For complicated setup scripts (like Domination), make the player watch a small intro while it is running.

Share this post


Link to post
Share on other sites

so make a JIP.sqf and in that sqf I would have something like this?

if (isDedicated) exitWith{};

waitUntil{!isNull player};
waitUntil{local player};

call {[player] execVM jipinit.sqf

I got the above from a different mission I had.

Then I put my loadout in the jipinit.sqf? like this

[] spawn {
waitUntil {player == player};
if (!local player) exitWith {};
removeAllWeapons player;
_ply = player;
_str = format ["%1", player];
switch (true) do {
	case (_str in ["sl","red1","yellow1","blue1"]) : {
		{_ply addMagazine "20Rnd_762x51_SB_SCAR";} forEach [1,2,3,4,5,6,7,8,9];
		_ply addWeapon "SCAR_H_CQC_CCO_SD";
		{_ply addMagazine "smokeShellRed";} forEach [10,11];
		_ply addMagazine "LASERBATTERIES";
		{_ply addMagazine "ACE_33Rnd_9x19_G18";} forEach [1,2];
		{_ply addMagazine "ACE_Morphine";} forEach [5,6];
		{_ply addMagazine "ACE_Epinephrine";} forEach [9,10];
		_ply addWeapon "ACE_Glock18";
		_ply addWeapon "BINOCULAR"; 
		_ply addWeapon "ACE_Map_Tools";
		_ply addWeapon "ACE_EARPLUGS"; 
		_ply addWeapon "ACE_DAGR";
		_ply addWeapon "LASERDESIGNATOR"; 
		_ply addWeapon "ACE_VTAC_Rush72";
		[_ply, "SmokeShellBlue", 6] call ACE_fnc_PackMagazine;
		[_ply, "20Rnd_762x51_SB_SCAR", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Morphine", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Epinephrine", 6] call ACE_fnc_PackMagazine;
		[_ply, "NVGOGGLES", 1] call ACE_fnc_PackMagazine;
	};
	case (_str in ["YellowAT","RedAT","BlueAT"]) : {
		{_ply addMagazine "20Rnd_762x51_SB_SCAR";} forEach [1,2,3,4];
		_ply addWeapon "SCAR_H_CQC_CCO_SD";
		{_ply addMagazine "smokeShellRed";} forEach [10,11];
		{_ply addMagazine "MAAWS_HEAT";} forEach [4,5];
		{_ply addMagazine "ACE_33Rnd_9x19_G18";} forEach [1,2];
		{_ply addMagazine "ACE_Morphine";} forEach [3,4];
		{_ply addMagazine "ACE_Bandage";} forEach [5,6];
		{_ply addMagazine "ACE_Epinephrine";} forEach [7,8];
		_ply addWeapon "ACE_Glock18";
		_ply addWeapon "BINOCULAR"; 
		_ply addWeapon "ACE_Map_Tools";
		_ply addWeapon "ACE_EARPLUGS"; 
		_ply addWeapon "ACE_DAGR";
		_ply addWeapon "MAAWS";
		_ply addWeapon "NVGOGGLES"; 
	};
	case (_str in ["ar1","ar2"]) : {
		{_ply addMagazine "100RND_762X51_M240";} forEach [1,2,3,4,5,6];
		{_ply addMagazine "smokeShellRed";} forEach [10,11,12,7,8,9];
		{_ply addMagazine "ACE_33Rnd_9x19_G18";} forEach [1,2];
		{_ply addMagazine "ACE_Morphine";} forEach [3,4];
		{_ply addMagazine "ACE_Bandage";} forEach [5,6];
		{_ply addMagazine "ACE_Epinephrine";} forEach [7,8];
		_ply addWeapon "MK_48";
		_ply addWeapon "ACE_Glock18";
		_ply addWeapon "BINOCULAR"; 
		_ply addWeapon "ACE_Map_Tools";
		_ply addWeapon "ACE_EARPLUGS"; 
		_ply addWeapon "ACE_DAGR";
		_ply addWeapon "ACE_MX2A"; 
		_ply addWeapon "ACE_VTAC_Rush72";
		[_ply, "ACE_Morphine", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Epinephrine", 6] call ACE_fnc_PackMagazine;
		[_ply, "NVGOGGLES", 1] call ACE_fnc_PackMagazine;
	};
	case (_str in ["m1","m2","m3"]) : {
		{_ply addMagazine "20Rnd_762x51_SB_SCAR";} forEach [1,2,3,4,5,6,7,8,9];
		{_ply addMagazine "smokeShellRed";} forEach [10,11];
		_ply addMagazine "HandGrenade_West";
		{_ply addMagazine "ACE_33Rnd_9x19_G18";} forEach [1,2];
		{_ply addMagazine "ACE_Morphine";} forEach [3,4];
		{_ply addMagazine "ACE_Bandage";} forEach [5,6];
		{_ply addMagazine "ACE_Epinephrine";} forEach [7,8];
		_ply addWeapon "SCAR_H_CQC_CCO_SD";
		_ply addWeapon "ACE_Glock18";
		_ply addWeapon "BINOCULAR"; 
		_ply addWeapon "ACE_Map_Tools";
		_ply addWeapon "ACE_EARPLUGS"; 
		_ply addWeapon "ACE_DAGR";
		_ply addWeapon "ACE_MX2A"; 
		_ply addWeapon "ACE_Wirecutter";
		_ply addWeapon "ACE_Rucksack_MOLLE_ACU_Medic";
		[_ply, "SmokeShellBlue", 6] call ACE_fnc_PackMagazine;
		[_ply, "20Rnd_762x51_SB_SCAR", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Morphine", 50] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Bandage", 50] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Epinephrine", 50] call ACE_fnc_PackMagazine;
		[_ply, "NVGOGGLES", 1] call ACE_fnc_PackMagazine;
	};
	case (_str in ["tws"]) : {
		{_ply addMagazine "20Rnd_762x51_SB_SCAR";} forEach [1,2,3,4,5,6,7,8,9];
		{_ply addMagazine "smokeShellRed";} forEach [10,11];
		_ply addMagazine "HandGrenade_West";
		{_ply addMagazine "ACE_33Rnd_9x19_G18";} forEach [1,2];
		{_ply addMagazine "ACE_Morphine";} forEach [3,4];
		{_ply addMagazine "ACE_Bandage";} forEach [5,6];
		{_ply addMagazine "ACE_Epinephrine";} forEach [7,8];
		_ply addWeapon "SCAR_H_STD_TWS_SD";
		_ply addWeapon "ACE_Glock18";
		_ply addWeapon "BINOCULAR"; 
		_ply addWeapon "ACE_Map_Tools";
		_ply addWeapon "ACE_EARPLUGS"; 
		_ply addWeapon "ACE_DAGR";
		_ply addWeapon "ACE_MX2A"; 
		_ply addWeapon "ACE_VTAC_Rush72";
		[_ply, "SmokeShellBlue", 6] call ACE_fnc_PackMagazine;
		[_ply, "20Rnd_762x51_SB_SCAR", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Morphine", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;
		[_ply, "ACE_Epinephrine", 6] call ACE_fnc_PackMagazine;
		[_ply, "NVGOGGLES", 1] call ACE_fnc_PackMagazine;
	};
};
_primw = primaryWeapon _ply;
if (_primw != "") then {
	_ply selectWeapon _primw;
	_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
	_ply selectWeapon (_muzzles select 0);
};
};

What would be the correct way to call the jip.sqf from a trigger?

Share this post


Link to post
Share on other sites

In Domination it's:

Condition: local player

On activation: _xhandle = [] execVM "x_client\x_jip.sqf"

which in turn starts the intro and setupplayer script.

But, you could have looked ;)

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

I did, but I didnt know what _xhandle meant. I will give it a try. Thanks

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  

×