Jump to content
Sign in to follow this  
galzohar

loadout script doesn't run - why?

Recommended Posts

Mission is supposed to be running with AI disabled and base respawn with JIP-compatibility, and the script is supposed to give gear to the playable units and then save their loadouts.

Each unit has in its init line: hNil = [this, "FTL"] execVM "assigngear.sqf"; where "FTL" is of course for fire team leaders, while other strings are for other roles' loadouts.

Only the start of the script is probably the problem, as when the script isn't working it seems like it doesn't even run at all (the removeAllWeapons line is never executed for the player unit), meaning it either exists even for the player unit because it doesn't equal the player (why?!) or gets stuck on one of the waitUntils (again, why?!).

private ["_strLoadout"];

if (isDedicated) exitWith {};

waitUntil {!isNil "ace_sys_ruck"};
waitUntil {ace_sys_ruck};

sleep 0.1;

waitUntil {!isNull player};

if (player != _this select 0) exitWith {};

_strLoadout = _this select 1;

removeAllWeapons player;
player setVariable ["ACE_WeaponOnBack", ""];

switch (_strLoadout) do
{   
case "medic":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
     		player addWeapon "ACE_HK416_D14_COMPM3";
	{player addMagazine "SmokeShellGreen";} forEach [1,2,3];
};


// fireteams/squad

case "FTL":
{
      	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
     		player addWeapon "ACE_HK416_D14_COMPM3";
	player addMagazine "HandGrenade_West";
	player addMagazine "SmokeShell";
	player addMagazine "SmokeShellGreen";
	player addMagazine "ACE_C4_M";
	player addMagazine "PipeBomb";
};

case "M136":
{
     		{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
	player addWeapon "ACE_HK416_D14_COMPM3";
	player addMagazine "HandGrenade_West";
	player addMagazine "SmokeShell";
	player addWeapon "M136";
	player addMagazine "PipeBomb";
};

case "M203":
{
     		{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
	{player addMagazine "1Rnd_HE_M203"} forEach [1,2,3,4,5,6,7,8];
	player addWeapon "ACE_M4A1_GL";
	player addMagazine "HandGrenade_West";
	player addMagazine "SmokeShell";
	player addMagazine "PipeBomb";
};


case "LMG":
{
	{player addMagazine "200Rnd_556x45_M249";} forEach [1,2,3,4];
	player addWeapon "M249";
	player addMagazine "HandGrenade_West";
};


// FN MAG (M240) team

case "762ammo":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
     		player addWeapon "ACE_SOC_M4A1_Aim";
	player addMagazine "HandGrenade_West";
	{player addMagazine "100Rnd_762x51_M240";} forEach [1,2];
};

case "MMG":
{
     		{player addMagazine "100Rnd_762x51_M240";} forEach [1,2,3,4];
	player addWeapon "M240";
	player addMagazine "HandGrenade_West";
};


// SMAW AT team

case "SMAWHEAA":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
	player addWeapon "ACE_SOC_M4A1_Aim";
	player addWeapon "SMAW";
	{player addMagazine "SMAW_HEAA";} forEach [1,2];
};

case "HEAAammo":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6];
	player addWeapon "ACE_SOC_M4A1_Aim";
	{player addMagazine "SMAW_HEAA";} forEach [1,2,3];
};


// SF

case "TL":
{
      	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
     		player addWeapon "ACE_M4A1_ACOG_SD";
	player addMagazine "HandGrenade_West";
	player addMagazine "SmokeShell";
	player addMagazine "SmokeShellGreen";
	{player addMagazine "ACE_C4_M";} forEach [1,2];
	player addWeapon "ACE_GlassesBalaklava";
};

case "demo":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
     		player addWeapon "ACE_SOC_M4A1_AIM_SD";
	{player addMagazine "PipeBomb";} forEach [1,2];
	{player addMagazine "ACE_C4_M";} forEach [1,2];
	player addWeapon "ACE_GlassesBalaklava";
};

case "SPRSD":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
     		player addWeapon "ACE_M4SPR_SD";
	player addMagazine "HandGrenade_West";
	player addMagazine "SmokeShell";
	player addWeapon "ACE_GlassesBalaklava";
};

case "SFmedic":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
     		player addWeapon "ACE_SOC_M4A1_AIM_SD";
	{player addMagazine "SmokeShellGreen";} forEach [1,2,3];
	player addWeapon "ACE_GlassesBalaklava";
};

case "SFM136":
{
     		{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
	player addWeapon "ACE_SOC_M4A1_AIM_SD";
	player addMagazine "HandGrenade_West";
	player addMagazine "SmokeShell";
	player addWeapon "M136";
	player addWeapon "ACE_GlassesBalaklava";
};

case "SFlaser":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
	player addWeapon "ACE_SOC_M4A1_AIM_SD";
	player addMagazine "HandGrenade_West";
	player addMagazine "SmokeShell";
	player addMagazine "LaserBatteries";
	player addWeapon "LaserDesignator";
	player addWeapon "ACE_GlassesBalaklava";
};


// Snipers

case "M24":
{
     		{player addMagazine "5Rnd_762x51_M24";} forEach [1,2,3,4,5,6,7,8,9,10];
	player addWeapon "M24";
	{player addMagazine "SmokeShell";} forEach [1,2];
	player addWeapon "M9";
	{player addMagazine "15Rnd_9x19_M9";} forEach [1,2];
};

case "spotter":
{
     		{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
	player addWeapon "ACE_M4A1_ACOG";
	player addMagazine "HandGrenade_West";
	{player addMagazine "SmokeShell";} forEach [1,2];
	player addMagazine "LaserBatteries";
	player addWeapon "LaserDesignator";
	player addWeapon "ACE_Spottingscope";
	player addWeapon "ACE_Kestrel4500";
};

case "pilotM9":
{
	{player addMagazine "15Rnd_9x19_M9";} forEach [1,2];
	player addWeapon "M9";
	player addMagazine "SmokeShell";
	player addMagazine "SmokeShellGreen";
};

case "pilotMP5":
{
	{player addMagazine "30Rnd_9x19_MP5";} forEach [1,2,3,4,5];
	player addWeapon "MP5A5";
	player addMagazine "SmokeShell";
	player addMagazine "SmokeShellGreen";
};

case "crew":
{
	{player addMagazine "30Rnd_556x45_Stanag";} forEach [1,2,3,4,5,6,7];
	player addWeapon "M4A1";
	player addMagazine "SmokeShell";
};
};

if (!(player hasWeapon "itemGPS")) then
{
player addWeapon "itemGPS";
};
if (!(player hasWeapon "LaserDesignator")) then
{
player addWeapon "binocular";
};
player addWeapon "NVGoggles";
player addWeapon "ACE_GlassesLHD_glasses";
if (!(player hasWeapon "ACE_Earplugs")) then
{
player addWeapon "ACE_Earplugs";
};

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

execVM "saveloadout.sqf";

Since it's in the init line, it should run for all connecting players for all units, and since I check if the unit is actually the player (after the player is defined) it should then only run for the player unit.

I can't figure out why on an odd occasion (most of the time it works fine) the player will not get any weapons, as if the script didn't run at all (that is, he will have default weapons). I could not reproduce this in any way and in fact it never even happened to me (maybe by chance?), only to other players on the dedicated server.

Any help would be much appreciated.

Edited by galzohar

Share this post


Link to post
Share on other sites

Add a trigger in the editor, condition:

local player

don't change anything else (except maybe trigger size, 0,0) and run the script from the On Act. field without all the checks done at the beginning of the script.

The trigger will fire only once for a player as soon as he is ingame (and only for the player because of local player).

I never use unit init fields to change player gear in MP and do most of the JIP procedure via a local player trigger (though that's a relict of early ArmA 2 versions where init.sqf sometimes didn't run properly for JIP players).

Xeno

Share this post


Link to post
Share on other sites

The problem with the trigger is that I then have to use unit names to check which slot he JIPed into, which is exactly what I was trying to avoid with this script.

Are you suggesting that a player can be defined (not null) and still not be local? If so, I should just add a waitUntil {local player};?

Share this post


Link to post
Share on other sites

Wouldn't that local player check pretty much be the same as a player==player check? Or have I missed something with the creation of objects and the player-variable?

Share this post


Link to post
Share on other sites

AFAIK player == player is basically checking if the player is not null, as any non-null object would equal itself, so if !isNull player returns true, so will player == player. Whether the player is always local or not, though, I don't know. I thought it is, but if it isn't, even if for a very short time, then that would explain why the script on rare occasions doesn't run. In fact, if it's not local for a very short time it would be even more logical as the script seems to work 99% of the time and only fails on very rare occasions.

Of course, due to how rare it is, it would be nice to actually have someone confirm if it is actually the problem or not, as I'd rather not create a new version of the mission just to find out a week later that it failed again for someone.

Share this post


Link to post
Share on other sites

Still not working. Perhaps init lines for units simply doesn't run for some people in certain situations (in missions with respawn and AI disabled)? If this happens, this would totally suck for both this script (requiring a complete rewrite) and other scripts...

Share this post


Link to post
Share on other sites

I'm still having problems with this. While I can make pretty damn ugly solutions that don't rely on units' init lines, I'd much rather have a decent way to run a script for every unit (such as a setGropuID script which seems to fail if everyone in your group die and then you JIP back in the game or something if you just do the setGroupID in the units' init lines, and yes, I placed the command in all group memebers' init lines).

Can anyone explain how init lines work in respawn+AI disabled missions and how to run something for every unit/group reliably?

I could just run everything from init.sqf and spawn a waitUntil {!isNil "unitName";}; waitUntil {alive unitName}; // do whatever script but that's pretty ugly, especially for missions with a large number of slots that rarely get filled.

Share this post


Link to post
Share on other sites

Hmm... How about doing a setVariable on the unit itself in its init line, and the script waiting for said setVariable to become defined/a certain value? Does that take a long enough time to happen to get the desired results?

Share this post


Link to post
Share on other sites

Kinda funny that I desired to use this script as well, and came up with the same solution to get the ruck functions to work (get rid of the call compile preprocessfile)

At first test in MP this worked for me... hope it helps.

EDIT: dunno why the text is all left justified, its not like that in the script.

//hNil = [this, "cmd_US"] execVM "assigngear.sqf";

waitUntil {!isNil "ace_sys_ruck"};

waitUntil {ace_sys_ruck};

_unit = _this select 0;

_strLoadout = _this select 1;

removeAllWeapons _unit;

switch (_strLoadout) do

{

case "LDR":

{

if (local _unit) then

{

{_unit addMagazine "RH_20Rnd_762x51_hk417";} count [1,2,3,4,5,6];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

_unit addMagazine "SmokeShellGreen";

_unit addMagazine "SmokeShellRed";

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2];

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

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sglacog";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_hk417", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "1Rnd_HE_M203", 20] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShellGreen", 2] call ACE_fnc_PackMagazine;

[_unit, "SmokeShellRed", 2] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Morphine", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Epinephrine", 2] call ACE_fnc_PackMagazine;

};

};

case "AR":

{

if (local _unit) then

{_unit addMagazine "200Rnd_556x45_M249";} count [1,2,3,4];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_M249Para";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "200Rnd_556x45_M249", 2] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

case "GRN":

{

if (local _unit) then

{_unit addMagazine "RH_20Rnd_762x51_hk417";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "1Rnd_HE_M203";} count [1,2,3,4,5,6];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sgleotech";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_hk417", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Rucksack_MOLLE_Green"] call ACE_fnc_PutWeaponOnBack;

_unit addWeapon "M136";

};

case "MRK":

{

if (local _unit) then

{_unit addMagazine "RH_20Rnd_762x51_SD_hk417";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sdsp";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_SD_hk417", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 8] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

case "ENG":

{

if (local _unit) then

{_unit addMagazine "ACE_8Rnd_12Ga_Slug";} count [1,2,3,4];

{_unit addMagazine "ACE_8Rnd_12Ga_Buck00";} count [1,2,3,4];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "ACE_C4_M";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4,5,6];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_SPAS12";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "ACE_8Rnd_12Ga_Slug", 12] call ACE_fnc_PackMagazine;

[_unit, "ACE_8Rnd_12Ga_Buck00", 12] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_C4_M", 6] call ACE_fnc_PackMagazine;

[_unit, "PipeBomb", 2] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Rucksack_MOLLE_Green"] call ACE_fnc_PutWeaponOnBack;

_unit addWeapon "M136";

};

case "MED":

{

if (local _unit) then

{_unit addMagazine "RH_20Rnd_762x51_SD_hk417";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2];

{_unit addMagazine "ACE_Bandage"} count [1,2];

{_unit addMagazine "ACE_Morphine"} count [1,2];

{_unit addMagazine "ACE_Epinephrine"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sdaim";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_SD_hk417", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 8] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 20] call ACE_fnc_PackMagazine;

[_unit, "ACE_Morphine", 20] call ACE_fnc_PackMagazine;

[_unit, "ACE_Epinephrine", 20] call ACE_fnc_PackMagazine;

};

case "MG":

{

if (local _unit) then

{_unit addMagazine "100Rnd_762x51_M240";} count [1,2,3,4,5,6];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_M60";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "100Rnd_762x51_M240", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

case "SPR":

{

if (local _unit) then

{_unit addMagazine "ACE_5Rnd_127x99_S_TAC50";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4,5,6];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_TAC50_SD";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "ACE_5Rnd_127x99_S_TAC50", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 8] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

};

if (!(_unit hasWeapon "itemGPS")) then

{

_unit addWeapon "itemGPS";

};

_primaryWeapon = primaryWeapon _unit;

_unit selectweapon _primaryWeapon;

// Fix for weapons with grenade launcher

_muzzles = getArray(configFile>>"cfgWeapons" >> _primaryWeapon >> "muzzles");

_unit selectWeapon (_muzzles select 0);

Edited by franklin

Share this post


Link to post
Share on other sites

I don't know, I'm a total newb to scripting lol.

The part "if (local _unit) then" was put in under the first instance, under case "cmd_US" in the orginal script, where i have replaced with case "LDR." None of the other case instances had that line of code in the orginal script.

I tested the script with 2 squads, each of the squad leaders having the same loadout. I hosted the map and had a friend connect to help me test a totally separate issue. I noticed that I had default weaponry, and my friend had the custom loadout I had intended to be used. I also noticed that none of the AI for either squad had the custom loadouts I had intended them to have.

I noticed that piece of script... "if (local _unit) then" was only in the first case, so i simply copy and pasted it to each case, and everything worked as I needed it to, since the mission will be played on a dedicated server.

that piece of code seems much more intelligent, and surely makes sence now that I've seen it.

Share this post


Link to post
Share on other sites

The problem with that is that the unit could be local to the server when the script runs on the client and local to the client when the script runs on the server, as there is no way to guarantee the scripts will run at the same time on both the client and server.

Also, you can't add/remove weapons during briefing, so your script will only work when you preview your mission in single player editor (as that skips the briefing). Try it in multilayer, export to single missions or just shift-click the preview button in single player so that you see the briefing and you'll see that your script doesn't work. That's why the sleep .1 is needed which doesn't help the issue mentioned above.

In any case, the problem I'm describing in this thread isn't that, it's that the script simply won't even execute for some units in missions with respawn and AI disabled. The issues you are describing are then solved by the fact you only need to run the script for players and not for AI, but a new issue probably caused by the presence of no AI and respawn that seems to prevent init lines from even executing in certain situations.

Share this post


Link to post
Share on other sites

I made the changes as you suggested and it works just as well as far as I can see, guessing that this way its more stable though.

In case you want to take a look...

//hNil = [this, "cmd_US"] execVM "assigngear.sqf";

if (!local _unit) exitWith {};

waitUntil {!isNil "ace_sys_ruck"};

waitUntil {ace_sys_ruck};

_unit = _this select 0;

_strLoadout = _this select 1;

removeAllWeapons _unit;

switch (_strLoadout) do

{

case "LDR":

{

{_unit addMagazine "RH_20Rnd_762x51_hk417";} count [1,2,3,4,5,6];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

_unit addMagazine "SmokeShellGreen";

_unit addMagazine "SmokeShellRed";

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2];

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

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sglacog";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_hk417", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "1Rnd_HE_M203", 20] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShellGreen", 2] call ACE_fnc_PackMagazine;

[_unit, "SmokeShellRed", 2] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Morphine", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Epinephrine", 2] call ACE_fnc_PackMagazine;

};

case "AR":

{

{_unit addMagazine "200Rnd_556x45_M249";} count [1,2,3,4];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_M249Para";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "200Rnd_556x45_M249", 2] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

case "GRN":

{

{_unit addMagazine "RH_20Rnd_762x51_hk417";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "1Rnd_HE_M203";} count [1,2,3,4,5,6];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sgleotech";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_hk417", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Rucksack_MOLLE_Green"] call ACE_fnc_PutWeaponOnBack;

_unit addWeapon "M136";

};

case "MRK":

{

{_unit addMagazine "RH_20Rnd_762x51_SD_hk417";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sdsp";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_SD_hk417", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 8] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

case "ENG":

{

{_unit addMagazine "ACE_8Rnd_12Ga_Slug";} count [1,2,3,4];

{_unit addMagazine "ACE_8Rnd_12Ga_Buck00";} count [1,2,3,4];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "ACE_C4_M";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4,5,6];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_SPAS12";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "ACE_8Rnd_12Ga_Slug", 12] call ACE_fnc_PackMagazine;

[_unit, "ACE_8Rnd_12Ga_Buck00", 12] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_C4_M", 6] call ACE_fnc_PackMagazine;

[_unit, "PipeBomb", 2] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

[_unit, "ACE_Rucksack_MOLLE_Green"] call ACE_fnc_PutWeaponOnBack;

_unit addWeapon "M136";

};

case "MED":

{

{_unit addMagazine "RH_20Rnd_762x51_SD_hk417";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "HandGrenade_West";} count [1,2];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2];

{_unit addMagazine "ACE_Bandage"} count [1,2];

{_unit addMagazine "ACE_Morphine"} count [1,2];

{_unit addMagazine "ACE_Epinephrine"} count [1,2];

// Weapons

_unit addWeapon "RH_hk417sdaim";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "RH_20Rnd_762x51_SD_hk417", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 8] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "HandGrenade_West", 8] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 20] call ACE_fnc_PackMagazine;

[_unit, "ACE_Morphine", 20] call ACE_fnc_PackMagazine;

[_unit, "ACE_Epinephrine", 20] call ACE_fnc_PackMagazine;

};

case "MG":

{

{_unit addMagazine "100Rnd_762x51_M240";} count [1,2,3,4,5,6];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_M60";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "100Rnd_762x51_M240", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 4] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

case "SPR":

{

{_unit addMagazine "ACE_5Rnd_127x99_S_TAC50";} count [1,2,3,4,5,6,7,8];

{_unit addMagazine "SmokeShell";} count [1,2];

// 4 Minislots

{_unit addMagazine "ACE_15Rnd_9x19_P226";} count [1,2,3,4,5,6];

{_unit addMagazine "ACE_Bandage"} count [1,2];

// Weapons

_unit addWeapon "ACE_TAC50_SD";

_unit addWeapon "ACE_P226";

_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";

// Backpack

_unit addWeapon "ACE_Rucksack_MOLLE_Green";

[_unit, "ACE_5Rnd_127x99_S_TAC50", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_15Rnd_9x19_P226", 8] call ACE_fnc_PackMagazine;

[_unit, "SmokeShell", 4] call ACE_fnc_PackMagazine;

[_unit, "ACE_Knicklicht_IR", 1] call ACE_fnc_PackMagazine;

[_unit, "ACE_Bandage", 6] call ACE_fnc_PackMagazine;

};

};

if (!(_unit hasWeapon "itemGPS")) then

{

_unit addWeapon "itemGPS";

};

_primaryWeapon = primaryWeapon _unit;

_unit selectweapon _primaryWeapon;

// Fix for weapons with grenade launcher

_muzzles = getArray(configFile>>"cfgWeapons" >> _primaryWeapon >> "muzzles");

_unit selectWeapon (_muzzles select 0);

In regards to your script running, forgive my ignorance if I'm totally off here, but I see this line:

if (player != _this select 0) exitWith {};

but I don't see anywhere that actually runs

player = _this select 0;

could that be the reason the script isnt working?

Edited by franklin

Share this post


Link to post
Share on other sites

player is a magic variable. It automatically refers to the local player object (or at least SHOULD refer to the local player object. The chance that it might sometimes be slow to be defined is a possible issue here, judging from Galzohar's stuff.

However, since it is a by the game engine automatically defined variable you never need to (and never should) assign a value to it yourself.

In some scripts you see waitUntil {!isNil "player"}; and waitUntil {player == player}; which are two stages of verifying that the variable has been initialized and defined. If Galzohar and Xeno are right though, it seems that there could be the tiniest of delay between the variable being assigned, and the client getting 'ownership' of the player character, so that the player variable is properly initialized, but the character is still not in the player's control for some microseconds yet.

Edited by Inkompetent

Share this post


Link to post
Share on other sites

I also added waitUntil {local player}; but it didn't solve the problem, so there's something else to it.

Share this post


Link to post
Share on other sites

How about starting the script from trigger on server, via a local player activation, then in the script:

_loadout = switch (true) do {

case (player in [alpha2, alpha6, bravo2, bravo6]) : {"FTL"};

...this is probably something you won't change much around anyway.

};

followed by

switch (_loadout) do {

case "FTL": {player addMagazine..... player addWeapon...};

};

etc. Note: Be sure _loadout is defined, either as an empty string or via private command.

Share this post


Link to post
Share on other sites

I did something similar (but easier to add more units later) by just giving the player weapons based on its vehicleVarName which should work if it's actually init lines failing to execute, but again I wonder what the hell is wrong with init lines of units in mission with respawn and disabled AI.

If I want to setGroupID for example for a lot of groups, I will have to have some kind of spawn {waitUntil {!isNil "unitName"}; unitName setGroupID ["unitGroupID"]}; for every unit, which means a lot of unneeded scripts are running for no real purpose (for all the units that don't and never will exist). Though if there is no better solution I suppose that's what I'll do to handle groupIDs as well (as init lines seem to fail here too in certain situations).

Share this post


Link to post
Share on other sites

What situations? I'm using setGroupID from each units init line, without any waiting, and haven't seen anything unusual about it yet. Same setup; disabled AI and respawn. The only thing is when the player gets a "bad connect", identified by not showing up correctly on chat channels etc.

SetFormation only for the group leader, but setGroupID for everyone. And that's everything I have in my units init line.

Share this post


Link to post
Share on other sites

I JIPed into a game in progress once and my groupID wasn't set properly (had setGroupID typed in every unit's init line in editor). Don't know if it has somethign to do with units respawning at least once before I joined or other problems, but the fact is the init line was not executed, or was not acting as intended. Same for the loadout script - on occasion it simply won't run at all (at least the script not even running in the firstplace is the only explanation I can think of as the script itself should be perfectly fine based on what we discussed in this thread).

What is this "bad connect" and how do you work around it? In a mission where gear is supposed to be limited, it kinda messes things up when someone comes in with an M16A4/ACOG/M203, even if he reconnects to fix it. I could just make a check if the script ran and if not remove all his weapons so he has to reconnect, but I'd rather understand the exact problem with units' init lines (or just use better workarounds).

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  

×