Jump to content
Sign in to follow this  
Remag

Some help with "basic" scripting please!

Recommended Posts

Hi chaps,

So....I'm a noob at this scripting stuff. Basically I want to spawn in the units and have them run an SQF file which will have commands to gear them up etc and for them to be reequipped with the same gear when they respawn (i've got the respawns working fine). So I've made various sqf files for each outfit, which will include all the guns etc...but I just can't get it to run the scripts, so it would be great if someone could tell me what i'm doing wrong!

I've put the below in the initialization space in the editor for the specific soldier:

Null = [this] execVM "outfit1.sqf"; this addeventhandler ["respawn","_this execVM 'outfit1.sqf'"];

And then the contents of the outfit1.sqf is:

_removeallweapons _this;
_removeallassigneditems _this;
_removeallcontainers this;
_this addHeadGear "H_MilCap_mcamo";
_this adduniform "U_B_CombatUniform_mcam_tshirt";
_this addbackpack "B_AssaultPack_mcamo";
_this addVest "V_TacVest_khk";
_this addweapon "Binocular"; 
_this additem "ItemCompass"; 
_this assignItem "ItemCompass"; 
_this additem "ItemMap"; 
_this assignItem "ItemMap"; 
_this additem "FirstAidKit"; 
_this additem "FirstAidKit"; 
_this addmagazines ["HandGrenade",2]; 
_this addmagazines ["DemoCharge_Remote_Mag",1]; 
_this addmagazines ["30Rnd_65x39_case_mag_Tracer",11]; 
_this addMagazines ["1Rnd_HE_Grenade_shell",5]; 
_this addweapon "arifle_TRG21_GL_F"; 
_this addPrimaryWeaponItem "muzzle_snds_H"; 
_this addPrimaryWeaponitem "optic_Arco"; 
_this addprimaryweaponitem "acc_flashlight"; 
_this addweapon "launch_RPG32_F"; 
_this addMagazine ["RPG32_F",3]; 
_this addMagazine ["RPG32_F",3]; 
_this addMagazine ["RPG32_F",3];

If you more knowledgeable chaps could help me out that would be lovely :)

Regards,

Remag

Share this post


Link to post
Share on other sites
removeallweapons _this;
removeallassigneditems _this;
removeallcontainers _this;

_this addHeadGear "H_MilCap_mcamo";
_this adduniform "U_B_CombatUniform_mcam_tshirt";
_this addbackpack "B_AssaultPack_mcamo";
_this addVest "V_TacVest_khk";
_this addweapon "Binocular"; 
_this additem "ItemCompass"; 
_this assignItem "ItemCompass"; 
_this additem "ItemMap"; 
_this assignItem "ItemMap"; 
_this additem "FirstAidKit"; 
_this additem "FirstAidKit"; 
_this addmagazines ["HandGrenade",2]; 
_this addmagazines ["DemoCharge_Remote_Mag",1]; 
_this addmagazines ["30Rnd_65x39_case_mag_Tracer",11]; 
_this addMagazines ["1Rnd_HE_Grenade_shell",5]; 
_this addweapon "arifle_TRG21_GL_F"; 
_this addPrimaryWeaponItem "muzzle_snds_H"; 
_this addPrimaryWeaponitem "optic_Arco"; 
_this addprimaryweaponitem "acc_flashlight";  
_this addMagazine ["RPG32_F",3]; 
_this addMagazine ["RPG32_F",3]; 
_this addMagazine ["RPG32_F",3];
_this addweapon "launch_RPG32_F";

Share this post


Link to post
Share on other sites

Thanks for the response. This does not work either unfortunately.

I've got uniform1 uniform2 uniform3 uniform4 sqf files in the mission folder so I can mix up the look of the soldiers in the squads etc. Could it be a problem having multiple files?

If not then I'm still unsure how to get this to work...on paper it should execute the files and work but it doesn't.

Any other ideas? I'll let you guys know when It works!

Share this post


Link to post
Share on other sites

_null = [this] execVM "yourscript.sqf"

_unit = _this select 0;

//remove equipment and weapons
removeallweapons _unit;
removeallassigneditems _unit;
removeallcontainers _unit;

//add uniform stuff
_unit addHeadGear "H_MilCap_mcamo";
_unit adduniform "U_B_CombatUniform_mcam_tshirt";
_unit addbackpack "B_AssaultPack_mcamo";
_unit addVest "V_TacVest_khk";

//add items
_unit addweapon "Binocular"; 
_unit additem "ItemCompass"; 
_unit assignItem "ItemCompass"; 
_unit additem "ItemMap"; 
_unit assignItem "ItemMap"; 
_unit additem "FirstAidKit"; 
_unit additem "FirstAidKit"; 

//add primary weapons and magazines
_unit addmagazines ["HandGrenade",2]; 
_unit addmagazines ["DemoCharge_Remote_Mag",1]; 
_unit addmagazines ["30Rnd_65x39_case_mag_Tracer",11]; 
_unit addMagazines ["1Rnd_HE_Grenade_shell",5]; 
_unit addweapon "arifle_TRG21_GL_F"; 

//add primary weapon attachments
_unit addPrimaryWeaponItem "muzzle_snds_H"; 
_unit addPrimaryWeaponitem "optic_Arco"; 
_unit addprimaryweaponitem "acc_flashlight";  

//add secondary weapons and magazines
_unit addMagazine ["RPG32_F",3]; 
_unit addMagazine ["RPG32_F",3]; 
_unit addMagazine ["RPG32_F",3];
_unit addweapon "launch_RPG32_F";

Edited by cobra4v320

Share this post


Link to post
Share on other sites

That works perfectly. Thank you very much kind sir!

Share this post


Link to post
Share on other sites

Right! So I'm experiencing a new issue. It seems that when people join the multiplayer game, the script does not load for them properly. So some will have the gear, some wont, or parts of it wont be loaded. Is there something I can do to make the script load every time for every person on the server?

Share this post


Link to post
Share on other sites

Placed into your init.sqf

changeLoadout = {
private ["_unit"];
_unit = _this;

// Remove the unit's default weapons
removeallweapons _unit;
removeallassigneditems _unit;
removeallcontainers _unit;

// Add rifle with suppressor and magazines
_unit addmagazines ["HandGrenade",2]; 
_unit addmagazines ["DemoCharge_Remote_Mag",1]; 
_unit addMagazines ["1Rnd_HE_Grenade_shell",5]; 
_unit addmagazines ["30Rnd_65x39_case_mag_Tracer",11];
_unit addweapon "arifle_TRG21_GL_F";
_unit addPrimaryWeaponItem "muzzle_snds_H";
_unit addPrimaryWeaponitem "optic_Arco"; 
_unit addprimaryweaponitem "acc_flashlight"; 

// Add secondary weapons and magazines
_unit addMagazine ["RPG32_F",3]; 
_unit addMagazine ["RPG32_F",3]; 
_unit addMagazine ["RPG32_F",3];
_unit addweapon "launch_RPG32_F";

// Add items
_unit addweapon "Binocular"; 
_unit additem "ItemCompass"; 
_unit assignItem "ItemCompass"; 
_unit assignItem "ItemMap"; 
_unit additem "FirstAidKit"; 
_unit additem "FirstAidKit";

// Add uniform stuff
_unit addHeadGear "H_MilCap_mcamo";
_unit adduniform "U_B_CombatUniform_mcam_tshirt";
_unit addbackpack "B_AssaultPack_mcamo";
_unit addVest "V_TacVest_khk";
};

// Doesn't need to be run on the dedicated server itself
if (!(isDedicated)) then {
// Wait for JIP
waitUntil {!(isNull player)};

// Change the player's loadout initially
player call changeLoadout;
};

// Apply to all units set to Playable
{
// Change loadout upon respawn
_x addEventHandler [
	"Respawn",	// Respawn event handler
	{
		// Find the newly-respawned unit
		private ["_unit"];
		_unit = _this select 0;

		// Change loadout
		_unit call changeLoadout;
	}
];
} forEach playableUnits;

Edited by cobra4v320

Share this post


Link to post
Share on other sites

Thanks for your quick response again. I'll test it in a bit. I take it when you say Init.sqf you mean the outfit1/outfit2/outfit3 sqf files I have made? Because I want each soldier to have a different loadout.

Share this post


Link to post
Share on other sites

The script above will load that loadout to ALL playable units. You could do a switch for different classes (grenadier, rifleman, AT, etc)

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  

×