Jump to content
zagor64bz

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

Recommended Posts

Just now, GEORGE FLOROS GR said:

waitUntil {uisleep 1;

 

if it show an error for the waituntil , then remove the uisleep 1;

because they changed something in the current version and i haven't manage to check it further.

Share this post


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

You can have this reedited similar script :

Thanks a lot buddy!!!

However right now my brain is fried...been trying to get this working for the past few hours...I'm hitting the bunk and continue tomorrow....

just one thing: would you be so kind as to set me up with some instruction on how to make your script working with what I need?

LOL..I can barely speak..hahahaha hope you understand

  • Haha 1

Share this post


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

LOL..I can barely speak..hahahaha hope you understand

Haha !

Sure!

 

all you need is to add the classnames of the certain units , just have in mind that every unit included and not only the recruits , will change their loadouts.

 

and exec the script from the initserver as in the script that i uploaded.

if you want more info , i'll be here !

Share this post


Link to post
Share on other sites

Hey Guys,

I guess you did messing around with a forum bug (invisible chars)

 

this error message contains an invisible char:

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

 

I mark it in next code bloxk with: !HERE!

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

 

  • Thanks 2

Share this post


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

Sure!!

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...

Hey there guys. I do have an idea what the problem might be. It's called precedence (of course you know that) and it has caused quite some trouble to me as well.

 

So, isEqualTo does NOT throw an error when it compares different types. Now this is where the precedence comes into play. in the way you have typed the code

4 hours ago, zagor64bz said:

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

isEqualTo actually checks _unit against "CFP_B_USRANGERS_Rifleman_AT_WDL_01" and then typeOf is called on the result (or something like that). So, if instead you type

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

// Just added parentheses around typeOf _unit

So then, when you reach the hint it finds a problem. Don't ask why, but I think that this could possibly be a solution. I had similar problems in the past with ArmA scripts. So, if it's not such a bother to try you could just let us know if you had any luck.

 

I know it doesn't really make sense to throw an error in there because it is supposed to never reach it, but still I did have similar problems in the past. I do hope that this is the problem which could be solved easily.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, sarogahtyp said:

Hey Guys,

I guess you did messing around with a forum bug (invisible chars)

 

this error message contains an invisible char:


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

 

I mark it in next code bloxk with: !HERE!


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

 

Damn little bug....thanks man!

Just 2 questions: what is it, and how can I get rid of it? 

 

EDIT: I see it now...if I paste the code in the code windows and not "directly" it shows red dots....damn...sneaky bug!!! hahahahahha

  • Like 2

Share this post


Link to post
Share on other sites
6 hours ago, ZaellixA said:

So, if it's not such a bother to try you could just let us know if you had any luck.

First of all, let me thank you for your help, but no, I had no luck. It not throw any error now, but is not working either. Just for testing, I run this code:

if((typeOf _unit) isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then { 
 hint "ATgear detected";
};

The hint didn't show up. So I'm guessing the script doesn't go past the "if statement.". For testing, I switch to the AT unit and run this code:

if((typeOf player) isEqualto "CFP_B_USRANGERS_Rifleman_AT_WDL_01") then { 
 hint "ATgear detected";
};

it shows the hint and no errors. However, if I run the previous code:

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

it throws this error:

12:06:07 Error in expression <"FirstAidKit";
for "_i" from 1 to 2 do {this addItemToUniform "CUP_15Rnd_9x19_M9>
12:06:07   Error position: <this addItemToUniform "CUP_15Rnd_9x19_M9>
12:06:07   Error Undefined variable in expression: this

So I changed the loadout from "this" to "_unit", but...

12:07:04 Error in expression <"FirstAidKit";
for "_i" from 1 to 2 do {_unit addItemToUniform "CUP_15Rnd_9x19_M>
12:07:04   Error position: <_unit addItemToUniform "CUP_15Rnd_9x19_M>
12:07:04   Error Undefined variable in expression: _unit

So, what I'm getting out of this is: (and mind you, I'm just guessing and shooting in the dark here):

- "typeOf _unit" is not working, because if I use "player" it is

- something is wrong with the "ATgear.sqf", where "this" or "_unit" throw an error...

 

Sooo...WHAT THE HECK IT'S GOING ON HERE????:headscratch:😜

  • Like 1

Share this post


Link to post
Share on other sites

Hhhhhhmmmmmmm, I haven't checked all the code you guys provided above so I cannot really say what this "FirstAidKit" error is. What I suggest is to hint the type of the _unit before you go into the check. For example you could

hint (typeOf _unit);

Then you can see what its type is. Then you will be able to go further down to the direction of the problem. Because if for example the returned string is "" it means that the object doesn't have a config class. Otherwise you will see if the class you check against is indeed the one you are looking for.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

From the code shown in this post of @zagor64bz

Add to the top of ATGear.sqf ...

params[ "_unit" ];

And change all this to _unit.

 

12 hours ago, zagor64bz said:

So, what I'm getting out of this is: (and mind you, I'm just guessing and shooting in the dark here):

- "typeOf _unit" is not working, because if I use "player" it is

- something is wrong with the "ATgear.sqf", where "this" or "_unit" throw an error...

this does not work, as per the error is undefined. this is for referencing an entity in its init box.

_unit does not work as it is undefined in the ATGear.sqf. It is defined in the recruit script but as soon as you execVM ATGear.sqf it is a separate variable space, so any previous local variables are lost( out of scope).

The above fixes this, much like how you have _unit = _this select 0; in your recruit script to extract the passed unit, you need to do the same when passing the unit from the recruit script to the ATGear script. So either _unit = _this select 0; OR params[ "_unit" ]; they both do the same thing, extract the unit from the arguments passed to each scripts.

Then for the rest of ATGear you can use _unit as a reference to the unit, instead of this.

  • Like 1
  • Thanks 2

Share this post


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

From the code shown in this post of @zagor64bz

Add to the top of ATGear.sqf ...


params[ "_unit" ];

And change all this to _unit.

 

this does not work, as per the error is undefined. this is for referencing an entity in its init box.

_unit does not work as it is undefined in the ATGear.sqf. It is defined in the recruit script but as soon as you execVM ATGear.sqf it is a separate variable space, so any previous local variables are lost( out of scope).

The above fixes this, much like how you have _unit = _this select 0; in your recruit script to extract the passed unit, you need to do the same when passing the unit from the recruit script to the ATGear script. So either _unit = _this select 0; OR params[ "_unit" ]; they both do the same thing, extract the unit from the arguments passed to each scripts.

Then for the rest of ATGear you can use _unit as a reference to the unit, instead of this.

100.webp?cid=790b76115d04ea6154672f7373b

I'm such a noob..thank you Larrow. Now it NOT reports any error, but still, don't change the inventory. It works if I change _unit to player tho...

So....after spending the last 48 hours trying to make this work...and getting VERY frustrated, I opted for a workaround.

The main reason for changing that particular unit loadout was that he was overloaded, so fatigue kicked in as soon as he moved.

So, a 

_unit = {_x enableFatigue false} foreach units group player;

did the trick. I'll dig into it when I'm more relaxed about it..LOL. 

However, I learn something IMPORTANT today: I become aware of that forum bug which screws up every code you copy/paste without running it through the "code" window.🤬

 

  • Like 1
  • Haha 1

Share this post


Link to post
Share on other sites
16 hours ago, sarogahtyp said:

this error message contains an invisible char:

 

6 hours ago, Larrow said:

you need to do the same when passing the unit from the recruit script to the ATGear script.

 

I was thinking of them as well and i was about to post them !

 

This invisible character bug , is a real mess !

 

4 hours ago, zagor64bz said:

Now it NOT reports any error, but still, don't change the inventory.

 

Did you succeed , or still trying ?

Share this post


Link to post
Share on other sites
11 hours ago, GEORGE FLOROS GR said:

This invisible character bug , is a real mess !

Something I didn't really know before, but a MESS indeed!

 

11 hours ago, GEORGE FLOROS GR said:

Did you succeed , or still trying ?

NOPE....so I put this on hold..for now..let's call it a "strategic retreat" LOL

  • Haha 2

Share this post


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

NOPE....so I put this on hold..for now..let's call it a "strategic retreat" LOL

 

I will download the script and check it on later today !

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, GEORGE FLOROS GR said:

 

I will download the script and check it on later today !

Thank you mate, I really appreciate your help!!

  • Like 1
  • Thanks 1

Share this post


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

Thank you mate, I really appreciate your help!!

 

Here is the script with the loadout changes in the :

bon_recruit_units\init_newunit.sqf

 

( this is from my test mission example , rifleman and at)

#recruit.Stratis.zip

_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,""];



//	change loadout

switch true do {
	
	case (typeOf _unit isEqualto "B_Soldier_F") :{_unit execvm "Loadouts\bluefor\B_Soldier_F.sqf";};
	case (typeOf _unit isEqualto "B_soldier_LAT_F") :{_unit execvm "Loadouts\bluefor\B_soldier_LAT_F.sqf";};
};

 

B_soldier_LAT_F

Spoiler

params["_unit"];

//	Paste your exported loadout and change _unit to _unit

//________________ Paste here : ________________


comment "Exported from Arsenal by [GR]GEORGE F";

comment "[!] UNIT MUST BE LOCAL [!]";
if (!local _unit) exitWith {};

comment "Remove existing items";
removeAllWeapons _unit;
removeAllItems _unit;
removeAllAssignedItems _unit;
removeUniform _unit;
removeVest _unit;
removeBackpack _unit;
removeHeadgear _unit;
removeGoggles _unit;

comment "Add containers";
_unit forceAddUniform "U_B_HeliPilotCoveralls";
_unit addItemToUniform "FirstAidKit";
_unit addItemToUniform "Chemlight_green";
for "_i" from 1 to 2 do {_unit addItemToUniform "30Rnd_65x39_caseless_black_mag";};
_unit addVest "V_PlateCarrier1_blk";
for "_i" from 1 to 2 do {_unit addItemToVest "16Rnd_9x21_Mag";};
_unit addItemToVest "SmokeShell";
_unit addItemToVest "SmokeShellGreen";
_unit addItemToVest "Chemlight_green";
for "_i" from 1 to 2 do {_unit addItemToVest "HandGrenade";};
_unit addItemToVest "30Rnd_65x39_caseless_black_mag";
_unit addBackpack "B_Kitbag_rgr";
for "_i" from 1 to 3 do {_unit addItemToBackpack "NLAW_F";};

comment "Add weapons";
_unit addWeapon "arifle_MX_Black_F";
_unit addPrimaryWeaponItem "acc_pointer_IR";
_unit addWeapon "launch_NLAW_F";
_unit addWeapon "hgun_P07_F";

comment "Add items";
_unit linkItem "ItemMap";
_unit linkItem "ItemCompass";
_unit linkItem "ItemWatch";
_unit linkItem "ItemRadio";

comment "Set identity";
[_unit,"WhiteHead_04","male12eng"] call BIS_fnc_setIdentity;

 

  • Like 1

Share this post


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

 

Here is the script with the loadout changes in the :

bon_recruit_units\init_newunit.sqf

 

( this is from my test mission example , rifleman and at)

#recruit.Stratis.zip


_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,""];



//	change loadout

switch true do {
	
	case (typeOf _unit isEqualto "B_Soldier_F") :{_unit execvm "Loadouts\bluefor\B_Soldier_F.sqf";};
	case (typeOf _unit isEqualto "B_soldier_LAT_F") :{_unit execvm "Loadouts\bluefor\B_soldier_LAT_F.sqf";};
};

 

B_soldier_LAT_F

  Reveal hidden contents


params["_unit"];

//	Paste your exported loadout and change _unit to _unit

//________________ Paste here : ________________


comment "Exported from Arsenal by [GR]GEORGE F";

comment "[!] UNIT MUST BE LOCAL [!]";
if (!local _unit) exitWith {};

comment "Remove existing items";
removeAllWeapons _unit;
removeAllItems _unit;
removeAllAssignedItems _unit;
removeUniform _unit;
removeVest _unit;
removeBackpack _unit;
removeHeadgear _unit;
removeGoggles _unit;

comment "Add containers";
_unit forceAddUniform "U_B_HeliPilotCoveralls";
_unit addItemToUniform "FirstAidKit";
_unit addItemToUniform "Chemlight_green";
for "_i" from 1 to 2 do {_unit addItemToUniform "30Rnd_65x39_caseless_black_mag";};
_unit addVest "V_PlateCarrier1_blk";
for "_i" from 1 to 2 do {_unit addItemToVest "16Rnd_9x21_Mag";};
_unit addItemToVest "SmokeShell";
_unit addItemToVest "SmokeShellGreen";
_unit addItemToVest "Chemlight_green";
for "_i" from 1 to 2 do {_unit addItemToVest "HandGrenade";};
_unit addItemToVest "30Rnd_65x39_caseless_black_mag";
_unit addBackpack "B_Kitbag_rgr";
for "_i" from 1 to 3 do {_unit addItemToBackpack "NLAW_F";};

comment "Add weapons";
_unit addWeapon "arifle_MX_Black_F";
_unit addPrimaryWeaponItem "acc_pointer_IR";
_unit addWeapon "launch_NLAW_F";
_unit addWeapon "hgun_P07_F";

comment "Add items";
_unit linkItem "ItemMap";
_unit linkItem "ItemCompass";
_unit linkItem "ItemWatch";
_unit linkItem "ItemRadio";

comment "Set identity";
[_unit,"WhiteHead_04","male12eng"] call BIS_fnc_setIdentity;

 

Oh man, it finally works!!!!

THANK YOU, DUDE!!!

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, zagor64bz said:

Oh man, it finally works!!!!

THANK YOU, DUDE!!!

 

No problem Zagor !

Have fun !  :thumbs-up:

  • Like 1
  • Thanks 1

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

×