Jump to content
Sign in to follow this  
Razor[42JTF]

Loadouts Multiplayer sqf issues

Recommended Posts

In summary; I want to change the way in which I script loadouts in multiplayer. Instead of scripting the full loadouts in each units initialisation line, I want to script an sqf that is called in the initialisation line. 

 

=========================================================================================================

I have a working system where units are initialised with the correct loadouts, but my script is in the init of each playable unit.
 
For the purpose of future ease in editing loadouts, I was hoping to script it into an sqf. However this is giving me problems.
 
Here is an example of my script in the init line of a playable unit: Grenadier. (For readability I have put each line onto its own line, but this is unnecessary)

 

This script works perfectly, but if I want to change Grenadiers loadouts, I have to edit each grenadier on the map. 
 

if (!local this) exitWith {};   //Check if unit is initialised by local client. If not, ignore the rest of the initialisation. 
removeAllWeapons this;  
removeAllItems this;  
removeAllAssignedItems this;  
removeUniform this;  
removeVest this;  
removeBackpack this;  
removeHeadgear this;  
removeGoggles this; 
this forceAddUniform "MNP_CombatUniform_Scorpion_A";  
for "_i" from 1 to 2 do {this addItemToUniform "ACE_CableTie";};  
this addItemToUniform "ACE_EarPlugs";  
for "_i" from 1 to 3 do {this addItemToUniform "HandGrenade";};  
this addVest "MNP_Vest_Scorpion_1";  
for "_i" from 1 to 8 do {this addItemToVest "rhs_mag_30Rnd_556x45_Mk318_Stanag";};  
for "_i" from 1 to 3 do {this addItemToVest "11Rnd_45ACP_Mag";};  
for "_i" from 1 to 4 do {this addItemToVest "SmokeShell";};  
for "_i" from 1 to 2 do {this addItemToVest "SmokeShellGreen";};  
this addItemToVest "SmokeShellYellow";  
for "_i" from 1 to 2 do {this addItemToVest "SmokeShellRed";};  
this addItemToVest "SmokeShellBlue";  
this addBackpack "B_Kitbag_rgr";  
for "_i" from 1 to 10 do {this addItemToBackpack "ACE_packingBandage";};  
for "_i" from 1 to 20 do {this addItemToBackpack "rhs_mag_M441_HE";};  
for "_i" from 1 to 10 do {this addItemToBackpack "1Rnd_SmokeRed_Grenade_shell";};  
for "_i" from 1 to 2 do {this addItemToBackpack "1Rnd_Smoke_Grenade_shell";};  
for "_i" from 1 to 2 do {this addItemToBackpack "1Rnd_SmokeGreen_Grenade_shell";};  
this addItemToBackpack "1Rnd_SmokeYellow_Grenade_shell";  
this addHeadgear "H_HelmetSpecB_snakeskin";  
this addGoggles "G_Bandanna_oli"; 
this addWeapon "rhs_weap_m4a1_m320"; 
this addPrimaryWeaponItem "RH_SFM952V"; 
this addPrimaryWeaponItem "optic_Hamr";  
this addWeapon "hgun_Pistol_heavy_01_F";  
this addWeapon "Binocular"; 
this linkItem "ItemMap";  
this linkItem "ItemCompass";  
this linkItem "ACE_Altimeter";  
this linkItem "tf_anprc152_2"; 
this linkItem "ItemGPS";

I therefore tried to initialise each playable unit with this:

if (!local this) exitWith {}; 
null = [this] execVM "Scripts\Loadouts\GR2IC.sqf";

where GR2IC.sqf is:

_plyer = _this select 0;

//Clearing Inventory
removeAllWeapons _plyer;  removeAllItems _plyer;  removeAllAssignedItems _plyer;  removeUniform _plyer;  removeVest _plyer;  removeBackpack _plyer;  removeHeadgear _plyer;  removeGoggles _plyer; 

//Uniform
_plyer forceAddUniform "MNP_CombatUniform_Scorpion_A";
for "_i" from 1 to 2 do {_plyer addItemToUniform "ACE_CableTie";};  
_plyer addItemToUniform "ACE_EarPlugs";  
for "_i" from 1 to 3 do {_plyer addItemToUniform "HandGrenade";};  
_plyer addItemToUniform "ACE_key_west"; 

//Vest
_plyer addVest "MNP_Vest_Scorpion_1";  
for "_i" from 1 to 8 do {_plyer addItemToVest "rhs_mag_30Rnd_556x45_Mk318_Stanag";};  
for "_i" from 1 to 3 do {_plyer addItemToVest "11Rnd_45ACP_Mag";};  
for "_i" from 1 to 4 do {_plyer addItemToVest "SmokeShell";};  
for "_i" from 1 to 2 do {_plyer addItemToVest "SmokeShellGreen";};  
_plyer addItemToVest "SmokeShellYellow"; 
for "_i" from 1 to 2 do {_plyer addItemToVest "SmokeShellRed";};  
_plyer addItemToVest "SmokeShellBlue";  

//Backpack
_plyer addBackpack "B_Kitbag_rgr";  
for "_i" from 1 to 10 do {_plyer addItemToBackpack "ACE_packingBandage";};  
for "_i" from 1 to 20 do {_plyer addItemToBackpack "rhs_mag_M441_HE";};  
for "_i" from 1 to 10 do {_plyer addItemToBackpack "1Rnd_SmokeRed_Grenade_shell";};  
for "_i" from 1 to 2 do {_plyer addItemToBackpack "1Rnd_Smoke_Grenade_shell";};  
for "_i" from 1 to 2 do {_plyer addItemToBackpack "1Rnd_SmokeGreen_Grenade_shell";};  
_plyer addItemToBackpack "1Rnd_SmokeYellow_Grenade_shell";  
_plyer addItemToBackpack "ACE_MapTools";

//Headgear
_plyer addHeadgear "H_HelmetB_snakeskin";  
_plyer addGoggles "G_Bandanna_oli"; 
 
//Weapon
_plyer addWeapon "rhs_weap_m4a1_m320"; 
_plyer addPrimaryWeaponItem "RH_SFM952V"; 
_plyer addPrimaryWeaponItem "optic_Hamr";  
_plyer addWeapon "hgun_Pistol_heavy_01_F";  
_plyer addWeapon "Binocular";
 
//MiscGear
_plyer linkItem "ItemMap";  
_plyer linkItem "ItemCompass";  
_plyer linkItem "ACE_Altimeter";  
_plyer linkItem "tf_anprc152_2";  
_plyer linkItem "ItemGPS";

This is where I need help. I am getting weird issues which I have tried to explain below.

 

  1. If I have 3 squads of 12 units on the map, but I only script one squad with the new approach, it seems to work 90% of the time. Sometimes the first player to load in, gets half the gear. I attributed that to the possibility that the server was still initialising everything. 
  2. If all squads are scripted with the new approach, units get some of the gear that has been scripted, but not all. 

 

My guess is that Arma handles sqf files very differently to the way it handles initialisation of the units within the mission file. Since we are running VCOM, BFT and ACE3 on the server, it may be possible that the sqf gets cut off half way through the initialisation process, but I would love to know why and how to fix it. It also works in the editor which is why I believe it must be how the server handles the initialisation process with each client.

 

I also tried using the following. It gave similar issues however. 


_handle = execVM "123.sqf"; waitUntil {isNull _handle};

Any assistance will be massively appreciated.

 

Sorry for the long post

Share this post


Link to post
Share on other sites

http://killzonekid.com/arma-scripting-tutorials-basic-multiplayer-coding-v2/KK explained the issue in his blog very thoroughly. It has most likely to to with the issue that some commands are global/global others are local/global etc.

KK did an awesome job of explaining it and providing solutions. Read it, understand it and if it still doesn't work, we'll try to find the error. ;)

Share this post


Link to post
Share on other sites

Hey R3vo

 

I actually stumbled onto this blog a while ago. That's why I have the line of code:

if (!local this) exitWith {}; 

I also added in a line to make sure the local variables in each of the scripts are private.

 

My next step is to add in a global variable that increments everytime a loadout script is called to make sure they are only being called once by each client. My guess however is that the issue is the script being halted for some reason. I'm not sure if it will help, but I am going to write it as a function that gets called to see if that helps. 

 

Razor

Share this post


Link to post
Share on other sites

If you mean from the initialisation line, then 

 

this

null = [this] execVM "Scripts\Loadouts\GR2IC.sqf";

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  

×