Jump to content
Conmanxful

Trying to use addaction to give loudouts to players.

Recommended Posts

So i'm trying to make a script where a Crate is empty but has the "AddAction" command to give certain loadouts. However i'm trying to do it the easy way by exporting the loadouts from VA and just have the player call the whole script to give them the new gear... In the init line of the crate i put

this addaction ["Give Rifleman Loadout", "Rifleman.sqf"];

Then for the rifleman.sqf script i pasted the exported arsenal loadout into there hoping it would work and added in a (_this =_this = ["give rifleman loadout", [_this] select 1];) to target the caller for the script to execute on. for reference

 

_this = ["give rifleman loadout", [_this] select 1];

removeAllWeapons this;
removeAllItems this;
removeAllAssignedItems this;
removeUniform this;
removeVest this;
removeBackpack this;
removeHeadgear this;
removeGoggles this;

comment "Add containers";
this forceAddUniform "rhs_uniform_FROG01_wd";
for "_i" from 1 to 10 do {this addItemToUniform "ACE_fieldDressing";};
this addItemToUniform "ACE_EarPlugs";
for "_i" from 1 to 10 do {this addItemToUniform "ACE_morphine";};
this addItemToUniform "ACE_MapTools";
this addItemToUniform "ACE_microDAGR";
this addItemToUniform "ACE_Flashlight_XL50";
this addItemToUniform "rhs_mag_m18_purple";
this addVest "rhsusf_spc_teamleader";
for "_i" from 1 to 6 do {this addItemToVest "rhs_mag_30Rnd_556x45_M855A1_Stanag_No_Tracer";};
for "_i" from 1 to 6 do {this addItemToVest "rhs_mag_M433_HEDP";};
for "_i" from 1 to 2 do {this addItemToVest "rhs_mag_an_m8hc";};
for "_i" from 1 to 2 do {this addItemToVest "rhs_mag_m67";};
this addItemToVest "rhs_mag_mk84";
this addItemToVest "rhs_mag_mk3a2";
for "_i" from 1 to 3 do {this addItemToVest "rhsusf_mag_17Rnd_9x19_FMJ";};
this addBackpack "rhsusf_falconii";
this addItemToBackpack "rhsusf_acc_nt4_black";
this addItemToBackpack "rhsusf_acc_anpeq15_bk";
this addItemToBackpack "acc_flashlight_pistol";
this addItemToBackpack "rhsusf_ANPVS_15";
this addItemToBackpack "rhsusf_acc_omega9k";
for "_i" from 1 to 4 do {this addItemToBackpack "rhs_mag_30Rnd_556x45_M855A1_Stanag_No_Tracer";};
for "_i" from 1 to 3 do {this addItemToBackpack "rhs_mag_M585_white";};
for "_i" from 1 to 3 do {this addItemToBackpack "rhs_mag_m715_Green";};
for "_i" from 1 to 3 do {this addItemToBackpack "rhs_mag_m713_Red";};
for "_i" from 1 to 3 do {this addItemToBackpack "rhs_mag_m714_White";};
this addItemToBackpack "Laserbatteries";
this addHeadgear "rhsusf_lwh_helmet_marpatwd";
this addGoggles "rhsusf_oakley_goggles_blk";

comment "Add weapons";
this addWeapon "rhs_weap_mk18_m320";
this addPrimaryWeaponItem "rhsusf_acc_ACOG_RMR";
this addWeapon "rhsusf_weap_glock17g4";
this addWeapon "Laserdesignator";

comment "Add items";
this linkItem "ItemMap";
this linkItem "ItemCompass";
this linkItem "ACE_Altimeter";
this linkItem "ItemRadio";
this linkItem "ItemGPS";

Thats the whole Rifleman.sqf Script and it says that "this" is an undefined variable... Please note i'm not well versed in scripting, hell i'm starting out mostly, so i don't even know what i'm doing wrong.

Share this post


Link to post
Share on other sites

To see the problem first read up about parameters.

https://community.bistudio.com/wiki/addAction

Addaction passes these parameters, [target, caller, ID, arguments]. In a script, these can be accessed like below.

_target = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_arguments = _this select 3;

And in an external script you cannot use this. It can only be used in the editor. So to make your script work, you'd need something like...

Spoiler

_unit = _this select 1;

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

comment "Add containers";
_unit forceAddUniform "rhs_uniform_FROG01_wd";
for "_i" from 1 to 10 do {_unit addItemToUniform "ACE_fieldDressing";};
_unit addItemToUniform "ACE_EarPlugs";
for "_i" from 1 to 10 do {_unit addItemToUniform "ACE_morphine";};
_unit addItemToUniform "ACE_MapTools";
_unit addItemToUniform "ACE_microDAGR";
_unit addItemToUniform "ACE_Flashlight_XL50";
_unit addItemToUniform "rhs_mag_m18_purple";
_unit addVest "rhsusf_spc_teamleader";
for "_i" from 1 to 6 do {_unit addItemToVest "rhs_mag_30Rnd_556x45_M855A1_Stanag_No_Tracer";};
for "_i" from 1 to 6 do {_unit addItemToVest "rhs_mag_M433_HEDP";};
for "_i" from 1 to 2 do {_unit addItemToVest "rhs_mag_an_m8hc";};
for "_i" from 1 to 2 do {_unit addItemToVest "rhs_mag_m67";};
_unit addItemToVest "rhs_mag_mk84";
_unit addItemToVest "rhs_mag_mk3a2";
for "_i" from 1 to 3 do {_unit addItemToVest "rhsusf_mag_17Rnd_9x19_FMJ";};
_unit addBackpack "rhsusf_falconii";
_unit addItemToBackpack "rhsusf_acc_nt4_black";
_unit addItemToBackpack "rhsusf_acc_anpeq15_bk";
_unit addItemToBackpack "acc_flashlight_pistol";
_unit addItemToBackpack "rhsusf_ANPVS_15";
_unit addItemToBackpack "rhsusf_acc_omega9k";
for "_i" from 1 to 4 do {_unit addItemToBackpack "rhs_mag_30Rnd_556x45_M855A1_Stanag_No_Tracer";};
for "_i" from 1 to 3 do {_unit addItemToBackpack "rhs_mag_M585_white";};
for "_i" from 1 to 3 do {_unit addItemToBackpack "rhs_mag_m715_Green";};
for "_i" from 1 to 3 do {_unit addItemToBackpack "rhs_mag_m713_Red";};
for "_i" from 1 to 3 do {_unit addItemToBackpack "rhs_mag_m714_White";};
_unit addItemToBackpack "Laserbatteries";
_unit addHeadgear "rhsusf_lwh_helmet_marpatwd";
_unit addGoggles "rhsusf_oakley_goggles_blk";

comment "Add weapons";
_unit addWeapon "rhs_weap_mk18_m320";
_unit addPrimaryWeaponItem "rhsusf_acc_ACOG_RMR";
_unit addWeapon "rhsusf_weap_glock17g4";
_unit addWeapon "Laserdesignator";

comment "Add items";
_unit linkItem "ItemMap";
_unit linkItem "ItemCompass";
_unit linkItem "ACE_Altimeter";
_unit linkItem "ItemRadio";
_unit linkItem "ItemGPS";

 


 

Share this post


Link to post
Share on other sites

Thank you MKD, i'll give it a try and report back if i manage to get it working with this :) i've given scripting a break for a day or two and i have a clan event that i'm quickly trying to sort the last bits of the map for the event, still need to upload to server and see if it works XD.

Share this post


Link to post
Share on other sites

Get rid of the first line of code you added, and replace with if (!local player) exitWith {};. Then replace "this" with "player". Done.

 

Example:



if (!local player) exitWith {}; 

// Remove existing items
removeAllWeapons player;
removeAllItems player;
removeAllAssignedItems player;
removeUniform player;
removeVest player;
removeBackpack player;
removeHeadgear player;

// Add containers
player forceAddUniform "rhs_uniform_g3_mc";
player addItemToUniform "ACE_IR_Strobe_Item";
player addItemToUniform "ACE_Flashlight_XL50";
player addItemToUniform "SmokeShellGreen";
player addItemToUniform "SmokeShellBlue";
for "_i" from 1 to 2 do {player addItemToUniform "HandGrenade";};
for "_i" from 1 to 2 do {player addItemToUniform "ACE_M84";};
player addVest "milgp_v_jpc_hgunner_belt_mc";
player addItemToVest "ACE_EntrenchingTool";
for "_i" from 1 to 2 do {player addItemToVest "ACE_EarPlugs";};
for "_i" from 1 to 2 do {player addItemToVest "ACE_CableTie";};
for "_i" from 1 to 2 do {player addItemToVest "rhsusf_mag_17Rnd_9x19_JHP";};
for "_i" from 1 to 8 do {player addItemToVest "rhs_mag_30Rnd_556x45_Mk318_Stanag";};
for "_i" from 1 to 6 do {player addItemToVest "SmokeShell";};
player addBackpack "B_TacticalPack_mcamo";
player addItemToBackpack "acc_flashlight";
for "_i" from 1 to 15 do {player addItemToBackpack "ACE_quikclot";};
player addItemToBackpack "ACE_salineIV_250";
for "_i" from 1 to 2 do {player addItemToBackpack "ACE_tourniquet";};
for "_i" from 1 to 3 do {player addItemToBackpack "150Rnd_762x51_Box_Tracer";};
for "_i" from 1 to 5 do {player addItemToBackpack "rhs_mag_M441_HE";};
player addHeadgear "milgp_h_opscore_04_RGR";

// Add weapons
player addWeapon "rhs_weap_m4a1_blockII_grip_bk";
player addPrimaryWeaponItem "rhsusf_acc_nt4_black";
player addPrimaryWeaponItem "rhsusf_acc_anpeq15side_bk";
player addPrimaryWeaponItem "SMA_ELCAN_SPECTER_RDS";
player addPrimaryWeaponItem "rhsusf_acc_grip3";
player addWeapon "rhsusf_weap_glock17g4";
player addHandgunItem "rhsusf_acc_omega9k";
player addWeapon "Binocular";

// Add items
player linkItem "ItemMap";
player linkItem "ItemCompass";
player linkItem "ItemWatch";
player linkItem "tf_anprc152";
player linkItem "ItemMicroDAGR";
player linkItem "rhsusf_ANPVS_15";

//DO NOT EDIT BELOW UNLESS THE NAME OF THE SOLDIER CHANGES
//DO NOT EDIT BELOW UNLESS THE NAME OF THE SOLDIER CHANGES
player setSpeaker "ace_novoice";
hint "Assistant Automatic Rifleman loaded";

Share this post


Link to post
Share on other sites
if (!local player) exitWith {};  

That would be a bit redundant because player is always local, and the code executed by addactions is also local. So it may aswell not be there at all.

 

Share this post


Link to post
Share on other sites

addAction in the init of the playable unit is just good for SP. In MP the code will run at each JIP. and the result is not very beautiful, adding the same action on this player.

 

 if (local this) then { this addAction...} is probably better. (see initialization order... stay on server)

But you should consider the initPlayerLocal.sqf  This script is a charm for running something for a JIP player.

myFunction = {

  player addAction [...]

};

call myFunction;

player addEventHandler ["respawn", {call myFunction}];

 

That for the principle.

Now, for an  addAction, the code is local indeed. That doesn't mean all the effects of your coded behaviors are locals. That means the  EG functions/commands will work without any problem (example: addItemToBackpack you see AG EG). As contrary example a simple hint "new loadout" (EL) will stay local to the caller. This kind of command needs to be remote Executed to have effect on each PCs. Some of them have a global variant (enableSimulationGobal).

Share this post


Link to post
Share on other sites
14 hours ago, MKD3-FHI said:

if (!local player) exitWith {};  

That would be a bit redundant because player is always local, and the code executed by addactions is also local. So it may aswell not be there at all.

 

 

Fair enough. I just know that it works in MP.

Share this post


Link to post
Share on other sites
7 hours ago, BadHabitz said:

 

Fair enough. I just know that it works in MP.


It will always work & be true. Unless executed on a dedicated server.

Share this post


Link to post
Share on other sites
2 hours ago, MKD3-FHI said:


It will always work & be true. Unless executed on a dedicated server.

 

What I posted works fine on a dedicated, as in your guy (and only your guy) gets the loadout. I've been doing it for years.

Share this post


Link to post
Share on other sites

You may misunderstand what I mean.

Quote

Person controlled by player. In MP this value is different on each computer and on dedicated server this value is null.

 

Share this post


Link to post
Share on other sites
On 27.11.2017 at 10:11 AM, BadHabitz said:

 

What I posted works fine on a dedicated, as in your guy (and only your guy) gets the loadout. I've been doing it for years.

It just works. Because it doesn't do anything and everything already works like you want it to work.
You can also say
Adding a "if false exitWith{}" makes my code work just fine. But if you actually think about it.. That's bullshit.

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

×