Jump to content
MuRaZorWitchKING

Need help with Playernamespace for Heroes Survive

Recommended Posts

Hello all, I recently have started utilizing Heros Survive and am looking into Saving some important variables via playernamespace, as I'm going to be running it via a dedicated server. Any and all help is seriously appreciated as I think my error is possibly due to the fact that HS uses client side vars? @Sgt Bombadil was helping out, but we haven't figured it out yet. 



initplayerlocal.sqf:

[] execVM "persistency db\savedb.sqf";
private ["_player"];
_player =_this select 0;
waitUntil {!isNull _player};
if (isNil {profileNamespace getVariable "HALs_money_funds"}) then {
   profileNamespace setVariable ["HALs_money_funds", 0];
};
_profile = (profileNamespace getVariable "HALs_money_funds");
_player setVariable ["HALs_money_funds", _profile];
//Heroes Survive persistentcy system:
//Hunger
if (isNil {profileNamespace getVariable "Her_L_Hunger"}) then {
   profileNamespace setVariable ["Her_L_Hunger", 100];
};
_profile = (profileNamespace getVariable "Her_L_Hunger");
Her_L_Hunger = 100;
//thirst
if (isNil {profileNamespace getVariable "Her_L_Thirst"}) then {
   profileNamespace setVariable ["Her_L_Thirst", 100];
};
_profile = (profileNamespace getVariable "Her_L_Thirst");
Her_L_Thirst = 100;
//Temperature
if (isNil {profileNamespace getVariable "Her_L_BodyTemp"}) then {
   profileNamespace setVariable ["Her_L_BodyTemp", 37];
};
_profile = (profileNamespace getVariable "Her_L_BodyTemp");
Her_L_BodyTemp = 37;

savedb.sqf:
 

[] spawn {
    waitUntil {!isNull(findDisplay 46)};

    (findDisplay 46) displayAddEventHandler ["KeyDown", {
        if(_this select 1 == 1) //esc key
        then {

[] execVM "Persistency db\autosave.sqf";              
        };
    }];
};

Autosave.sqf:
 

_moneys = (player getVariable "HALs_money_funds");
profileNamespace setVariable ["HALs_money_funds", _moneys];

_Hunger = (player getVariable "Her_L_Hunger");
profileNamespace setVariable ["Her_L_Hunger", _Hunger];

_Thirst = (player getVariable "Her_L_Thirst");
profileNamespace setVariable ["Her_L_Thirst", _Thirst];

_TemperatureH = (player getVariable "Her_L_BodyTemp");
profileNamespace setVariable ["Her_L_BodyTemp", _TemperatureH];


HALs money is saving perfectly, it's only the "Her_L" vars that are not working properly.

Thanks again 


 

Share this post


Link to post
Share on other sites

perhaps you have to "clean" your profileNameSpace variables if you tested some arrays, then figures,... I mean the variables are perhaps not nil but doesn't meet anymore the type.

Try to hint profileNameSpace getvariable ["Her_L_Hunger", "not defined"]  // will temporarily return "not defined" or a value. You can also reset these variables setting them to nil (from any other mission preview). This way the code should completely run at mission start.

  • Thanks 1

Share this post


Link to post
Share on other sites

So this within the debug returns the value of the players current status whether it be Temperature, hunger, thirst:

In debug console:
 

profileNameSpace getvariable ["Her_L_BodyTemp","not defined"];

I tested this via initplayerlocal.sqf:
 

player setVariable["Saved_Loadout",getUnitLoadout player];

[] execVM "persistency db\savedb.sqf";
private ["_player"];
_player =_this select 0;
waitUntil {!isNull _player};
if (isNil {profileNamespace getVariable "HALs_money_funds"}) then {
    profileNamespace setVariable ["HALs_money_funds", 0];
};
_profile = (profileNamespace getVariable "HALs_money_funds");
_player setVariable ["HALs_money_funds", _profile];
//Heroes Survive persistentcy system:
//Hunger
if (isNil {profileNamespace getVariable "Her_L_Hunger"}) then {
    profileNamespace setVariable ["Her_L_Hunger", "not defined"];
};
_profile = (profileNamespace getVariable "Her_L_Hunger");
Her_L_Hunger = _profile;
//thirst
if (isNil {profileNamespace getVariable "Her_L_Thirst"}) then {
    profileNamespace setVariable ["Her_L_Thirst", "not defined"];
};
_profile = (profileNamespace getVariable "Her_L_Thirst");
Her_L_Thirst = _profile;
//Temperature
if (isNil {profileNamespace getVariable "Her_L_BodyTemp"}) then {
    profileNamespace setVariable ["Her_L_BodyTemp", "not defined"];
};
_profile = (profileNamespace getVariable "Her_L_BodyTemp");
Her_L_BodyTemp = _profile;

No syntax errors but still did not save 

Hmmm... 🤔
 

Share this post


Link to post
Share on other sites

Okay, so putting a sleep 5; infront of the code fixes it... So our problem most likely lies within the Heros Survive mod itself. Because on scenario / mission start with profileNamespace loading I think since it loads immediately upon player login / join that the mod is essentially "overwriting" these variables with starting parameters.

This may be the fix as I know of no other way to work through it, especially since the code enforces starting parameters even if you uncomment like so:

 

//Her_L_Hunger=100;
//Her_L_Thirst=100;
//Her_L_BodyTemp=37;
//Her_L_Money=0;

These are in the settings file of HS...

If I tune the sleep just right I can most likely get it to where player's won't even see the vars change.

Unless there's some other way?

Current "fixed code":


initplayerlocal.sqf:

 

sleep 5;
[] execVM "persistency db\savedb.sqf";
private ["_player"];
_player =_this select 0;
waitUntil {!isNull _player};
if (isNil {profileNamespace getVariable "HALs_money_funds"}) then {
    profileNamespace setVariable ["HALs_money_funds", 0];
};
_profile = (profileNamespace getVariable "HALs_money_funds");
_player setVariable ["HALs_money_funds", _profile];
//Heroes Survive persistentcy system:
//Hunger
if (isnil {profileNamespace getVariable "Her_L_Hunger"}) then {
    profileNamespace setVariable ["Her_L_Hunger", 100];
};
_profile = (profileNamespace getVariable "Her_L_Hunger");
Her_L_Hunger = _profile;
//thirst
if (isnil {profileNamespace getVariable "Her_L_Thirst"}) then {
    profileNamespace setVariable ["Her_L_Thirst", 100];
};
_profile = (profileNamespace getVariable "Her_L_Thirst");
Her_L_Thirst = _profile;
//Temperature
if (isnil {profileNamespace getVariable "Her_L_BodyTemp"}) then {
    profileNamespace setVariable ["Her_L_BodyTemp", 37];
};
_profile = (profileNamespace getVariable "Her_L_BodyTemp");
Her_L_BodyTemp = _profile;


 

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

×