Jump to content
Sign in to follow this  
rjtwins

Unit scripting costum unit templates and respawming them.

Recommended Posts

Hello,...

I'm working on a script to spawm units with basic templates and respawm them with the template given in via a sqf file.

My code so far

_u = player;

removeAllItems _u;
removeAllWeapons _u;
removeVest _u;
removeUniform _u;
removeBackpack _u;

_u addUniform "U_B_CombatUniform_mcam";
_u addVest "V_TacVest_oli";
_u addbackpack "B_Carryall_ocamo";

clearAllItemsFromBackpack _u;
{_u removeMagazine _x} forEach magazines _u;

unitbackpack _U addMagazineCargoGlobal ["20Rnd_762x45_Mag",15];
_u addWeapon "srifle_EBR_Hamr_point_grip_F";
_u addPrimaryWeaponItem "muzzle_snds_B";

_urimw = primaryWeapon _u;
if (_urimw != "") then {
   _u selectWeapon _urimw;
   // Fix for weapons with grenade launcher
   _muzzles = getArray(configFile>>"cfgWeapons" >> _urimw >> "muzzles");
   _u selectWeapon (_muzzles select 0);
};

waitUntil {!alive player};
waitUntil {alive player};

_u = player;

player execVM "Marksman.sqf";

and

_g = player;

removeAllItems _g;
removeAllWeapons _g;
removeVest _g;
removeUniform _g;
removeBackpack _g;

_g addUniform "U_B_CombatUniform_gcam";
_g addVest "V_TacVest_oli";
_g addbackpack "B_Carryall_ocamo";

clearAllItemsFromBackpack _g;
{_g removeMagazine _x} forEach magazines _g;

unitbackpack _g addMagazineCargoGlobal ["200Rnd_65x39_cased_Box_Tracer",5];
_g addWeapon "LMG_gk200_COWS_pointer_bipod_F";
_g addPrimaryWeaponItem "optic_Hamr";


_grimw = primaryWeapon _g;
if (_grimw != "") then {
   _g selectWeapon _grimw;
   // Fix for weapons with grenade launcher
   _guzzles = getArray(configFile>>"cfgWeapons" >> _grimw >> "muzzles");
   _g selectWeapon (_guzzles select 0);
};

waitUntil {!alive player};
waitUntil {alive player};

_g = player;

player execVM "SupportGunner.sqf";

I emply the script by executing it by putting _handle = player execVM "the file" in the init of the unit wich is recieving the template.

Its all running just fine while i'm on my own in a server but....

When I enable both scripts ingame, so I put _handle = player execVM "file for gunner" in one units init and _handle = player execVM "file for marksman" in the other. It for some reason overides the gunner and both players spawn as marksman.

WHY ???

Can sombody help me out here please ?

Greatings,

rj twins

Share this post


Link to post
Share on other sites

It might be because the "player" command is local for every player, and they're being cross-executed in some weird fashion? Since you put them in the init box, use _handle = this execVM "the file" instead of "player", and in the script, use "_g = _this;". It could solve the problem.

As far as I know, this script only gives the correct equipment for a single respawn, though, I think you need some kind of a loop for multiple ones.

Edit: Eh, of course it doesn't, since the whole script is executed again. You need to leave the last "player"'s intact, at least.

Edited by Magirot
I'm slow

Share this post


Link to post
Share on other sites

Thank you, I'm trying it right now.

Its not working, the script is now not giving me the weapon uniform or vest anymore, it does give me the backpack with the ammo i specified.. ??..

Is there a way to get a dubugger working for this ? fo fiend out where the script stops working.

Edited by rjtwins

Share this post


Link to post
Share on other sites

I've got it working.

script :

//wmdWeaponSpawn.sqf//
//////////////////////////////////////////////////////////////////////////////////////////
//Put the following in the INI field of the soldier you want to template to apply to.	//
//handle = [this, "classname"] execVM "wmdWeaponSpawnWorking.sqf";						//
//clasenames : 																			//
//sl : Squad leader																		//
//rifle : Atandart rifleman																//
//autorifle : Automatic rifleman (support gunner)										//
//at : Anti tank specialist																//
//medic : Medic																			//
//explosive : Explosives specialist														//
//marksman : Ranged rifleman/sniper (uses EBR)											//
//repair : Repair spacialist															//
//////////////////////////////////////////////////////////////////////////////////////////


waitUntil {!isNull player};
_unit = _this select 0;
_type = _this select 1;


removeAllItems _unit;
removeAllWeapons _unit;
removeVest _unit;
removeUniform _unit;
removeBackpack _unit;
removeHeadgear _unit;

switch (_type) do {
case "sl":{
_unit addUniform "U_B_CombatUniform_mcam";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light";
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit; 
_unit addMagazine "20Rnd_762x45_Mag"; 
_unit addWeapon "srifle_EBR_Hamr_point_grip_F";
_unit addPrimaryWeaponItem "muzzle_snds_B";
bp = unitBackpack _unit; 
bp addMagazineCargoGlobal["20Rnd_762x45_Mag",15];
_unit addMagazine "HandGrenade";
_unit addMagazine "HandGrenade";
_unit addMagazine "HandGrenade";
_unit addMagazine "HandGrenade";
_unit addMagazine "HandGrenade";
_unit addMagazine "HandGrenade";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
};

case "rifle":{
_unit addUniform "U_B_CombatUniform_mcam";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light";
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit; 
_unit addMagazine "30Rnd_65x39_caseless_mag"; 
_unit addWeapon "arifle_MX_F"; 
_unit addPrimaryWeaponItem "optic_Aco"; 
_unit addPrimaryWeaponItem "muzzle_snds_H";
bp = unitBackpack _unit; 
bp addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag",10];
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addMagazine "HandGrenade";
};

case "autorifle":{
_unit addUniform "U_B_CombatUniform_mcam_tshirt";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light"; 
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit;
unitbackpack _unit addMagazineCargoGlobal ["200Rnd_65x39_cased_Box_Tracer",10];
_unit addWeapon "LMG_Mk200_F";
_unit addPrimaryWeaponItem "optic_Hamr"; 
_unit addPrimaryWeaponItem "muzzle_snds_H_MG";
unitbackpack _unit addWeapon "MineDetector";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addMagazine "HandGrenade";
};

case "at":{
_unit addUniform "U_B_CombatUniform_mcam";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light";
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit; 
_unit addWeapon "arifle_MX_F"; 
_unit addPrimaryWeaponItem "optic_Aco"; 
_unit addPrimaryWeaponItem "muzzle_snds_H";
_unit addWeapon "launch_NLAW_F";
_bp = unitBackpack _unit; 
_bp addMagazineCargoGlobal ["100Rnd_65x39_caseless_mag_Tracer",10];
_bp addMagazineCargoGlobal ["NLAW_F", 4];
};

case "medic":{
_unit addUniform "U_B_CombatUniform_mcam";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light";
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit; 
_unit addMagazine "30Rnd_65x39_caseless_mag"; 
_unit addWeapon "arifle_MX_F"; 
_unit addPrimaryWeaponItem "optic_Aco"; 
_unit addPrimaryWeaponItem "muzzle_snds_H";
bp = unitBackpack _unit; 
bp addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag",10];
_unit addItem "Medikit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
};

case "explosive":{
_unit addUniform "U_B_CombatUniform_mcam";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light";
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit; 
_unit addMagazine "30Rnd_65x39_caseless_mag"; 
_unit addWeapon "arifle_MX_F"; 
_unit addPrimaryWeaponItem "optic_Aco"; 
_unit addPrimaryWeaponItem "muzzle_snds_H";
bp = unitBackpack _unit; 
bp addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag",10];
_unit addItem "Toolkit";
_unit addWeapon "MineDetector";
_unit addMagazine "DemoCharge_Remote_Mag";
_unit addMagazine "DemoCharge_Remote_Mag";
_unit addMagazine "DemoCharge_Remote_Mag";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addMagazine "HandGrenade";
};

case "marksman":{
_unit addUniform "U_B_CombatUniform_mcam";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light";
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit;   
_unit addMagazine "30Rnd_65x39_caseless_mag"; 
_unit addMagazine "20Rnd_762x45_Mag"; 
_unit addWeapon "srifle_EBR_Hamr_point_grip_F";
_unit addPrimaryWeaponItem "muzzle_snds_B";
bp = unitBackpack _unit; 
bp addMagazineCargoGlobal["20Rnd_762x45_Mag",15];
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addMagazine "HandGrenade";
};

case "repair":{
_unit addUniform "U_B_CombatUniform_mcam";
_unit addVest "V_PlateCarrier1_cbr"; 
_unit addbackpack "B_Carryall_ocamo";
_unit addHeadgear "H_HelmetB_light";
clearAllItemsFromBackpack _unit;
{_unit removeMagazine _x} forEach magazines _unit; 
_unit addMagazine "30Rnd_65x39_caseless_mag"; 
_unit addWeapon "arifle_MX_F"; 
_unit addPrimaryWeaponItem "optic_Aco"; 
_unit addPrimaryWeaponItem "muzzle_snds_H";
bp = unitBackpack _unit; 
bp addMagazineCargoGlobal ["30Rnd_65x39_caseless_mag",10];
_unit addItem "Toolkit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addItem "FirstAidKit";
_unit addMagazine "HandGrenade";
};
};

sleep 5;

weaponsvar = weapons player;
magazinesvar = magazines player;
vestvar = vest player;
uniformvar = uniform player;
headgearvar = headgear player;
backpackvar = backpack player;
primaccvar = primaryWeaponItems player; 
secaccvar = secondaryWeaponItems player;
itemsvar = items player;
assitemsvar = assignedItems player;
hint "loadout saved";

while {true} do {
waitUntil {!alive player};
waitUntil {alive player};

removeAllItems player;
removeAllWeapons player;
removeAllAssignedItems player;
removeAllContainers player;

player addBackpack backpackvar;
player addVest vestvar;
player addUniform uniformvar;
player addHeadgear headgearvar;

{player addItem _x} forEach itemsvar;
{player addMagazine _x} forEach magazinesvar;
{player addWeapon _x} forEach weaponsvar;
{player addPrimaryWeaponItem _x} forEach primaccvar;
{player addSecondaryWeaponItem _x} forEach secaccvar;
{player addItem _x} forEach assitemsvar;
{player assignItem _x} forEach assitemsvar;
hint "Loadout Restored";

_primw = primaryWeapon player;
if (_primw != "") then {
   player selectWeapon _primw;
   // Fix for weapons with grenade launcher
   _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
   player selectWeapon (_muzzles select 0);
};
};

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  

×