Jump to content
zagor64bz

[SOLVED]Help with "typeOf" and LoadouI would like to give to spawned unit

Recommended Posts

Ok..I have a script that allows me to recruit units and adding them to my group. I would like to "customize" the loadout of some of the recruits.

I try with:

if ((typeOf OBJECT) == "UNIT_CLASS_NAME") then { 
 
execVM "loadout.sqf";
};

and

if ("man" iskindof "UNIT_CLASS_NAME") then { 
 
execVM "loadout.sqf"; 
};

obviously with no luck....:headscratch:

 

Any idea?

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, zagor64bz said:

Any idea? 

 

Hello there Zagor !

 

#How is it going ?!

 

Here is an example :

if(typeOf _this isEqualto "I_Soldier_TL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_TL_F.sqf";
};

You can check for a similar script here :

 

 

Share this post


Link to post
Share on other sites
15 minutes ago, GEORGE FLOROS GR said:

 

Hello there Zagor !

 

#How is it going ?!

 

Here is an example :


if(typeOf _this isEqualto "I_Soldier_TL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_TL_F.sqf";
};

You can check for a similar script here :

 

 

Hey GEORGE!!!! How is it going, mate???

Unfortunately, if I run your code like this:

if(typeOf _this isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then{
[_this] execVM "Scripts\ATgear.sqf";
};

 

it gives me this error:

23:52:24 Error in expression <if(typeOf _this isEqualto "CFP_B_USRANGERS_>
23:52:24   Error position: <typeOf _this isEqualto "CFP_B_USRANGERS_>
23:52:24   Error typeof: Type Array, expected Object
23:52:24 Error in expression <if(typeOf _this isEqualto "CFP_B_USRANGERS_>
23:52:24   Error position: <typeOf _this isEqualto "CFP_B_USRANGERS_>
23:52:24   Error Generic error in expression

:headscratch:

 

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, zagor64bz said:

[_this] execVM

 

Generally going good !

Thanks for asking !

 

add below how and where you use your script in order to adjust "_this" to the needed one !

  • Thanks 1

Share this post


Link to post
Share on other sites

OK.... I use the recruit script from an object with an add-action: the unit spawn and join my group. In the script, there's a new_unit_init.sqf where you can add local commands..

_unit = _this select 0;

/*****************************************************************
	following section to run only on server.
	Note: duplicate respective code in the pve in the init.sqf
******************************************************************/
if(isServer) then{
	[_unit] execFSM (BON_RECRUIT_PATH+"unit_lifecycle.fsm");
} else {
	bon_recruit_newunit = _unit;
	publicVariable "bon_recruit_newunit";
};




/*****************************************************************
	Client Stuff
******************************************************************/
_unit addAction ["<t color='#949494'>Dismiss</t>",BON_RECRUIT_PATH+"dismiss.sqf",[],-10,false,true,""];
camo = [_unit,"",0,1,0,1,5] spawn compile preprocessFile "Scripts\camoscriptv1.5.sqf";
[player,_unit] call RYD_HAS_NewUnits;
_unit = {addSwitchableUnit _x} foreach units group player;
_unit = {doStop _x} foreach units group player;
sleep 1;
_unit = {_x addPrimaryWeaponItem "CUP_muzzle_snds_SCAR_H"} foreach units group player;
_unit = {_x addPrimaryWeaponItem "optic_ERCO_blk_F"} foreach units group player;
_unit = {_x linkItem "NVGogglesB_grn_F"} foreach units group player;

So far, for testing, I run your code in the console, after I spawn the AT soldier and he joined...

  • Like 1

Share this post


Link to post
Share on other sites
2 minutes ago, zagor64bz said:

_unit = _this select 0;

 

so change _this to _unit and try.

Share this post


Link to post
Share on other sites
47 minutes ago, GEORGE FLOROS GR said:

 

so change _this to _unit and try.

nope...sorry, not working...:headscratch:

Share this post


Link to post
Share on other sites
3 minutes ago, zagor64bz said:

nope...sorry, not working...:headscratch:

 

is this your code ?

if(typeOf _unit isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then{
	[_unit] execVM "Scripts\ATgear.sqf";
};

 

Share this post


Link to post
Share on other sites
1 minute ago, GEORGE FLOROS GR said:

 

is this your code ?


if(typeOf _unit isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then{
	[_unit] execVM "Scripts\ATgear.sqf";
};

 

It is...:headscratch:

Share this post


Link to post
Share on other sites
3 minutes ago, zagor64bz said:

It is...:headscratch:

 

What's the given error ?

Or it doesn't show up anything?

Share this post


Link to post
Share on other sites

NO error report..just doesn't change the loadout....

Share this post


Link to post
Share on other sites
Just now, zagor64bz said:

NO error report..just doesn't change the loadout....

 

add a systemchat info or diag_log and check the rpt

Share this post


Link to post
Share on other sites
4 minutes ago, GEORGE FLOROS GR said:

 

add a systemchat info or diag_log and check the rpt

???HOW??

where?

:headscratch:

 

ps: thank you a lot 4 your help, mate!!

 

  • Thanks 1

Share this post


Link to post
Share on other sites
3 minutes ago, zagor64bz said:

ps:

No problem !

 

You can add in the code :

 

if(typeOf _unit isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then{
	[_unit] execVM "Scripts\ATgear.sqf";
	hint "ATgear detected";
};

 

and this inside the ATgear.sqf at the bottom.

systemchat "ATgear loadout";
diag_log "ATgear loadout";

 

Do you know where to find the rpt ?

Share this post


Link to post
Share on other sites
3 minutes ago, GEORGE FLOROS GR said:

Do you know where to find the rpt ?

Sure!!

4 minutes ago, GEORGE FLOROS GR said:

You can add in the code :

 


if(typeOf _unit isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then{
	[_unit] execVM "Scripts\ATgear.sqf";
	hint "ATgear detected";
};

Now it trows this error if I try to execute that

1:42:49 Error in expression <gear.sqf"; 
 hint "ATgear detected"; 
};>
 1:42:49   Error position: <>
 1:42:49   Error Invalid number in expression

and no hint pops up...

Share this post


Link to post
Share on other sites
9 minutes ago, zagor64bz said:

and no hint pops up...

 

try

_unit execVM "Scripts\ATgear.sqf";

and if there is an error try as well without to check for the hint.

Share this post


Link to post
Share on other sites
4 minutes ago, GEORGE FLOROS GR said:

 

try

_unit execVM "Scripts\ATgear.sqf";

and if there is an error try as well without to check for the hint.

It trows the same error..

2:02:44 Error in expression <
 _unit execVM "Scripts\ATgear.sqf"; 
};>
 2:02:44   Error position: <>
 2:02:44   Error Invalid number in expression
 

Share this post


Link to post
Share on other sites
2 minutes ago, zagor64bz said:

It trows the same error..

 

paste below the full code that you are using , also is this an init sqf ? no right ?

Share this post


Link to post
Share on other sites

Ok....

init_newunits.sqf///is part of a folder which spawn/allow recruit of units

init_newunits.sqf/// this is part of a script folder which let you recruit the units...

_unit = _this select 0;

/*****************************************************************
	following section to run only on server.
	Note: duplicate respective code in the pve in the init.sqf
******************************************************************/
if(isServer) then{
	[_unit] execFSM (BON_RECRUIT_PATH+"unit_lifecycle.fsm");
} else {
	bon_recruit_newunit = _unit;
	publicVariable "bon_recruit_newunit";
};




/*****************************************************************
	Client Stuff
******************************************************************/
_unit addAction ["<t color='#949494'>Dismiss</t>",BON_RECRUIT_PATH+"dismiss.sqf",[],-10,false,true,""];
camo = [_unit,"",0,1,0,1,5] spawn compile preprocessFile "Scripts\camoscriptv1.5.sqf";///add a camo scripyt to unit
[player,_unit] call RYD_HAS_NewUnits;/// add unit to an array for a chopper support
_unit = {addSwitchableUnit _x} foreach units group player;///make unit playable
_unit = {doStop _x} foreach units group player;///avoid them running around the base at spawn
sleep 1;
_unit = {_x addPrimaryWeaponItem "CUP_muzzle_snds_SCAR_H"} foreach units group player;///add silencer to units
_unit = {_x addPrimaryWeaponItem "optic_ERCO_blk_F"} foreach units group player;///add optic to units
_unit = {_x linkItem "NVGogglesB_grn_F"} foreach units group player;///add NVG to units

if (typeOf _unit isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then { 
[_unit] execVM "Scripts\ATgear.sqf"; 
};////your code

ATgear.sqf

removeAllWeapons this;
removeAllItems this;
removeAllAssignedItems this;
removeUniform this;
removeVest this;
removeBackpack this;
removeHeadgear this;
removeGoggles this;
this forceAddUniform "CFP_75th_CRYE_V2b_Sleeved";
this addItemToUniform "FirstAidKit";
for "_i" from 1 to 2 do {this addItemToUniform "CUP_15Rnd_9x19_M9";};
this addVest "CFP_HV5_Ciras_Olive";
this addItemToVest "CUP_HandGrenade_M67";
this addItemToVest "B_IR_Grenade";
this addItemToVest "Chemlight_green";
this addItemToVest "Chemlight_red";
this addItemToVest "SmokeShell";
for "_i" from 1 to 3 do {this addItemToVest "CUP_30Rnd_556x45_Stanag";};
this addBackpack "CFP_Kitbag_MCam_Grn";
for "_i" from 1 to 2 do {this addItemToBackpack "CUP_MAAWS_HEDP_M";};
this addItemToBackpack "CUP_MAAWS_HEAT_M";
this addHeadgear "CFP_OpsC_Uncov_Goggle_Off";
this addGoggles "CFP_Tac_Goggles_Blk_Clr";
this addWeapon "CUP_arifle_mk18_black";
this addPrimaryWeaponItem "CUP_muzzle_snds_M16_desert";
this addPrimaryWeaponItem "CUP_acc_ANPEQ_15_OD";
this addPrimaryWeaponItem "CUP_optic_Elcan_reflex_OD";
this addWeapon "CUP_launch_MAAWS";
this addSecondaryWeaponItem "CUP_optic_MAAWS_Scope";
this addWeapon "CUP_hgun_M9";
this addWeapon "Binocular";
this linkItem "ItemMap";
this linkItem "ItemCompass";
this linkItem "ItemWatch";
this linkItem "ItemRadio";
this linkItem "CFP_ANPVS15_Camo_V4";
[this,"WhiteHead_06","male06eng"] call BIS_fnc_setIdentity;

systemchat "ATgear loadout";
diag_log "ATgear loadout";

BTW..I try the code on a NON spawned unit..same soup....

 

 

Share this post


Link to post
Share on other sites
2 minutes ago, zagor64bz said:

if(isServer) then{ [_unit] execFSM (BON_RECRUIT_PATH+"unit_lifecycle.fsm");

 

try to add the code here :

 

if(isServer) then{
	[_unit] execFSM (BON_RECRUIT_PATH+"unit_lifecycle.fsm");
	if (typeOf _unit isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then{
	[_unit] execVM "Scripts\ATgear.sqf";
	};
} else {
	bon_recruit_newunit = _unit;
	publicVariable "bon_recruit_newunit";
};

 

Share this post


Link to post
Share on other sites
5 minutes ago, GEORGE FLOROS GR said:

 

try to add the code here :

 


if(isServer) then{
	[_unit] execFSM (BON_RECRUIT_PATH+"unit_lifecycle.fsm");
	if (typeOf _unit isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then{
	[_unit] execVM "Scripts\ATgear.sqf";
	};
} else {
	bon_recruit_newunit = _unit;
	publicVariable "bon_recruit_newunit";
};

 

NOPE.....

 2:34:44   Error Undefined variable in expression: _unit
 2:34:44 Error in expression <{isPlayer _x} count (units group _unit) == 0>
 2:34:44   Error position: <_unit) == 0>
 2:34:44   Error Undefined variable in expression:

 

Share this post


Link to post
Share on other sites
14 minutes ago, zagor64bz said:

_unit = _this select 0;

 

try just below this.

Share this post


Link to post
Share on other sites

Nope.... would be more simple if I use your script posted above i/e "GF Exported Loadouts Script - Mod"???

If so, how do I set it up?

  • Haha 1

Share this post


Link to post
Share on other sites
6 minutes ago, zagor64bz said:

would be more simple if I use your script

 

Yes !

I thought that this last one would be ok , but surprisingly nothing !

 

You can have this reedited similar script :

Spoiler




//________________  Author : GEORGE FLOROS [GR] ___________	02.03.19	_____________

/*
________________ GF Exported Loadouts Script - Mod  MCD version  MCD version	________________

https://forums.bohemia.net/forums/topic/221232-gf-exported-loadouts-script-mod/

Please keep the Credits or add them to your Diary

https://community.bistudio.com/wiki/SQF_syntax
Don't try to open this with the simple notepad.
For everything that is with comment  //  in front  or between /*
means that it is disabled , so there is no need to delete the extra lines.

You can open this ex:
with notepad++
https://notepad-plus-plus.org/

ArmA 3 | Notepad ++ SQF tutorial
https://www.youtube.com/watch?v=aI5P7gp3x90

and also use the extra pluggins
(this way will be better , it will give also some certain colors to be able to detect ex. problems )
http://www.armaholic.com/page.php?id=8680

or use any other program for editing .

For the Compilation List of my GF Scripts - Mods , you can search in:
https://forums.bohemia.net/forums/topic/215850-compilation-list-of-my-gf-scripts-mods/

BI Forum Ravage Club Owner :
https://forums.bohemia.net/clubs/73-bi-forum-ravage-club/
*/

//________________	You can add in the init of a unit to exclude 	________________	
//	this setVariable ["Var_GF_Exported_Loadouts_MCD", true];


//________________ Settings ________________
//________________ Set true or false  ________________

GF_Exported_Loadouts_MCD_Systemchat_info				= true;
GF_Exported_Loadouts_MCD_diag_log_info					= true;	

//________________ Settings ________________

GF_Exported_Loadouts_MCD_Change_Loadout_on_Respawn		= true;	




if(GF_Exported_Loadouts_MCD_Systemchat_info) then {
systemchat "GF Exported Loadouts Script - Mod  MCD version Initializing";
};

if(GF_Exported_Loadouts_MCD_diag_log_info) then {
diag_log "//________________	GF Exported Loadouts Script - Mod  MCD version Initializing	_____________";
diag_log "//________________	GF_Exported_Loadouts_MCD.sqf	_____________";
};




GF_Exported_Loadouts_MCD = {


//________________	Change_Loadout_on_Respawn	________________	

if (GF_Exported_Loadouts_MCD_Change_Loadout_on_Respawn) then {

_this addEventHandler ["Respawn", {
	params ["_unit", "_corpse"];
	_unit setVariable ["Var_GF_Exported_Loadouts_MCD",false];
}];
};


//________________	GF_Exported_Loadouts_MCD_For_Certain_Classnames	________________	

//________________	independent	________________	

if(typeOf _this isEqualto "I_Soldier_TL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_TL_F.sqf";
};

if(typeOf _this isEqualto "I_Soldier_GL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_GL_F.sqf";
};

if(typeOf _this isEqualto "I_Soldier_AR_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_AR_F.sqf";
};

if(typeOf _this isEqualto "I_Soldier_LAT_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_LAT_F.sqf";
};

if(typeOf _this isEqualto "I_Soldier_SL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_SL_F.sqf";
};

if(typeOf _this isEqualto "I_Soldier_A_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_A_F.sqf";
};

if(typeOf _this isEqualto "I_soldier_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_soldier_F.sqf";
};

if(typeOf _this isEqualto "I_Soldier_M_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_Soldier_M_F.sqf";
};

if(typeOf _this isEqualto "I_medic_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\independent\I_medic_F.sqf";
};


//________________	east	________________	

if(typeOf _this isEqualto "O_Soldier_TL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_Soldier_TL_F.sqf";
};

if(typeOf _this isEqualto "O_Soldier_GL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_Soldier_GL_F.sqf";
};

if(typeOf _this isEqualto "O_Soldier_AR_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_Soldier_AR_F.sqf";
};

if(typeOf _this isEqualto "O_Soldier_LAT_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_Soldier_LAT_F.sqf";
};

if(typeOf _this isEqualto "O_Soldier_SL_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_Soldier_SL_F.sqf";
};

if(typeOf _this isEqualto "O_Soldier_A_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_Soldier_A_F.sqf";
};

if(typeOf _this isEqualto "O_Soldier_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_Soldier_F.sqf";
};

if(typeOf _this isEqualto "O_soldier_M_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_soldier_M_F.sqf";
};

if(typeOf _this isEqualto "O_medic_F") then{
[_this] execVM "GF_Exported_Loadouts_MCD\Loadouts\east\O_medic_F.sqf";
};


};




[] spawn { 
	while {true} do {		
		waitUntil {uisleep 1; 
	
		{		
		if (
		(alive _x) 
		&& (!(isPlayer _x))		//	comment this to include player
		&& (!(_x getVariable ["Var_GF_Exported_Loadouts_MCD",false]))


		) then {
			
			_x spawn GF_Exported_Loadouts_MCD;
			
			};						
			_x setVariable ["Var_GF_Exported_Loadouts_MCD",true];
		}forEach allUnits;
		};
	};
};		


if(GF_Exported_Loadouts_MCD_Systemchat_info) then {
systemchat "GF Exported Loadouts Script - Mod  MCD version Initialized";
};

if(GF_Exported_Loadouts_MCD_diag_log_info) then {
diag_log "//________________	GF Exported Loadouts Script - Mod  MCD version Initialized	_____________";
};

 

https://ufile.io/pdifhyd4

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

×