Jump to content
  • 0

Skins based on humanity


BetterDeadThanZed

Question

I've read some threads here about humanity based loadouts and none have really helped me, so I'm creating my own in the hopes of getting this sorted.

 

I have a custom loadout script I use. I want to further develop it by giving a player a skin based on his humanity. Here's the part that is supposed to do that:

_humanity = player getVariable["humanity",0];

if (_humanity >= 0) then {
	DZE_defaultSkin = [["Skin_Soldier_Sniper_PMC_DZ","Skin_GUE_Commander_DZ","Skin_Soldier_Bodyguard_AA12_PMC_DZ","Skin_Haris_Press_EP1_DZ"],["Skin_SurvivorW2_DZ","Skin_SurvivorW3_DZ","Skin_SurvivorWcombat_DZ","Skin_SurvivorWdesert_DZ","Skin_SurvivorWurban_DZ","Skin_SurvivorWpink_DZ"]];
	} else {
	DZE_defaultSkin = [["Skin_Bandit1_DZ","Skin_GUE_Soldier_MG_DZ","Skin_GUE_Soldier_Crew_DZ","Skin_GUE_Soldier_CO_DZ","Skin_GUE_Soldier_2_DZ","Skin_Ins_Soldier_GL_DZ"],["Skin_BanditW1_DZ","Skin_BanditW2_DZ"]];
	};

When I die and respawn, I get this in my log and spawn with the skins in the first "DZE_defaultSkin" line:

19:21:10 Error in expression < player getVariable["humanity",0];

if (_humanity >= 0) then {
DZE_defaultSkin =>
19:21:10   Error position: <_humanity >= 0) then {
DZE_defaultSkin =>
19:21:10   Error Undefined variable in expression: _humanity

Any suggestions?

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

I think the problem is that the loadout.sqf is called early in init.sqf, aiming to change some DZE_* default variables.

 

I suppose at this point 'player' has not been set up completely (him being dead and in need of a new character does not help), meaning his humanity has not yet been read from the DB and been added to the in-game entity 'player' via 'setvariable'. Thus the getvariable returns empty for 'humanity'.

 

The custom loadoud scripts out there seem to aim for a UID based loadout, for this there seems to be a function: (getPlayerUID player).

 

Other references:

 

Here http://opendayz.net/threads/humanity-based-loadouts.10447/#post-90311 an ugly dll call is used to fetch the humanity from the DB.

 

Here suspects the same issue I did above and a solution is proposed in the posts below. But then you had already posted there....and it does not cover skins.

 

The location of the loadout.sqf call relative to the call to player_monitor seems crucial.

I don't know when the changed DZE_* variables are referenced, so simply placing the loadout.sqf after player_monitor (before spawn selection) might be too late.

Might calling player_monitor twice (the first time just to attach the humanity) work?

Link to comment
Share on other sites

  • 0

DId you see specifically the bit of using spawn for the script to wait till player_monitor has finished its work?

 

As far as I understand it from that post, everything called with execVM is basically started in a parallel thread that may well be still running when the ones started after have long finished.

Link to comment
Share on other sites

  • 0

I moved the code below the player monitor and I spawned without any loadout, only the default Dayz/Epoch loadout.

	[] spawn {
		waitUntil {!isNil ("PVDZE_plr_LoginRecord")};	//Wait Till logged in
		waitUntil {(!isNull player) and (alive player) and (player == player)};

			[] execVM "custom\loadout\loadout.sqf";
	};
Link to comment
Share on other sites

  • 0

An interesting error, but ekroemer is right - a player object does not exist yet.

getVariable is used to find a variable in a namespace (object - player in this case), if variable does not exist in this NS then use 0 as stated in OP post.

However the object/namespace itself does not exist, hence the variable is nil.

 

Dayz kicks you to lobby everytime you die, this means mission namespace gets deleted and all global variables with it. My suggestion would be creating a variable inside uiNamespace and use that. uiNamespace persists while game is loaded.

[] spawn {
	waitUntil {player == player};
	uiNamespace setVariable ["humanity",(player getVariable["humanity",0])];
	
	if ((uiNamespace getVariable "humanity") >= 0) then {
		//...
	} else {
		//...
	};
};
Link to comment
Share on other sites

  • 0

With that code, Raymix, I'm not getting any errors, but I'm not spawning with the bandit skin when my humanity is below 0.

plug this somewhere while testing, see if humanity is correctly applied to uiNamespace:

diag_log (uiNamespace getVariable ["humanity","humanity var does not exist"]); 

also try dying 1 or 2 times, I posted the code as an idea more than a solution.

Link to comment
Share on other sites

  • 0

Raymix, as Zed is trying to define player skin by setting DZE_defaultSkin, do you know where this variable is referenced?

 

If, for example,

  • we need to getVariable "humanity" after the player object has been set up (by player_monitor, right?)
  • and only then can define DZE_defaultSkin
  • but DZE_defaultSkin is already evaluated in player_monitor

then changes made to it would not be processed.

 

In that case changing DZE_defaultSkin won't be a feasible method and one would have to fallback to changing the skin later (something with player_morph?).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...