Closed BrianV1981 closed 3 years ago
The problem with saving and loading bank and container values is going to be how you are going to save the reference to the player and container objects.
It would have to look something like this for players:
//initServer.sqf
{_x call brian_fnc_loadPlayerBankaccount} forEach allPlayers;
addMissionEventHandler ["HandleDisconnect", {
params ["_player","","_uid"];
private _bankbalance = _player getVariable ["grad_moneymenu_myBankBalance",0];
["brian_bankbalance_" + _uid,_bankbalance] call ALiVE_fnc_setData;
}];
// brian_fnc_loadPlayerBankaccount
[{!isNil {(_this select 0) getVariable "grad_moneymenu_myBankBalance"}},{
params [["_player",objNull]];
private _uid = getPlayerUID _player;
private _bankbalance = (["brian_bankbalance_" + _uid] call ALiVE_fnc_getData);
if (isNil "_bankbalance") exitWith {
diag_log ["Bank balance not loaded for player: ",_player];
};
_player setVariable ["grad_moneymenu_myBankBalance",_bankbalance,true];
},_this] call CBA_fnc_waitUntilAndExecute;
And like this for containers:
//initServer.sqf
//find a way to get all containers into an array (_allContainers) with fixed order
private _containerBalanceArray = ["brian_containerBalance"] call ALiVE_fnc_getData;
{
_x setVariable ["grad_lbm_myFunds",_containerBalanceArray param [_forEachIndex,0]];
} forEach _allContainers;
//execute regulary and before mission end I guess?
//find a way to get all containers into an array (_allContainers) with the same order as above
private _containerBalanceArray = [];
{
_containerBalanceArray pushBack (_x getVariable ["grad_lbm_myFunds",0]);
} forEach _allContainers;
["brian_containerBalance",_containerBalanceArray] call ALiVE_fnc_setData;
You can get a container's value with _container getVariable ["grad_lbm_myFunds",0]
and a player's bank account with _player getVariable ["grad_moneymenu_myBankBalance",0]
. With that info you might be able to get a better answer from someone who knows more about ALiVE than I do.
Hello again, McDiod! Thank you for taking the time to write such an in-depth response. While I believe it is possible to incorporate ALiVE's persistence with grad-moneyMenu, I believe it is out of my league :)
I have been trying to manually save wallet and ATM accounts utilizing grad-persistence without any luck, probably from my own lack of understanding of how all of this works. I have been trying my hardest to figure it out without asking for help, but I have a few questions that may be able to get me over this hurdle. In short, I want wallets and ATM's to stay persistent through player disconnects and server restarts. Something similar to what we see on Altis Life and KOH servers.
First, I am building a mission utilizing a dedicated server, I do understand that this changes a lot of dynamics. I would also like to mention that the "setStorage" on objects (unsecured) works for me during disconnects and server restarts. Also, If I use a playerUID the "setStorage" on objects (secured) works perfectly during player disconnects and server restarts.
However, at this time, I do not know how to create a "secured" container without already having a playerUID during the creation process. I assumed that if I plopped a player character in Eden and gave it a variable name, like "p_1" and "setStorage" to an object with a variable name of "box1",
[box1, p_1] call grad_moneymenu_fnc_setStorage
that it would work through disconnects, as long as the disconnected person rejoined on the same player character (p_1). This idea does work up until that player disconnects. Upon re-entering the game, the "secured" storage container becomes unusable. Any thoughts on why this happens?
Does grad-moneyMenu "ATM accounts" persist during disconnect without the utilization of grad_persistence? If a player disconnects and reconnects, should the ATM and wallet stay persistent without another mod?
I have been able to accomplish this while utilizing ALiVE, but I have no idea what I did to make it happen. Because now, no matter what I try, I cannot get wallets and ATM accounts to persist through disconnects. I have a version of my scenario that lets players completely lose connection and reload back in, and their wallet and ATM "bank account" will stay persistent, so long as they log back into the same character. They do not have to execute
[true,30] call grad_persistence_fnc_saveMission
before logging out, or
[] call grad_persistence_fnc_loadMission
after logging back in. Yet, their wallet and ATM bank accounts persist. However, I cannot figure out how to get this versions' ATM and wallets to persist through server restarts.
I figure that I must be doing something wrong here...In short:
Any help would be appreciated!
Brian
However, at this time, I do not know how to create a "secured" container without already having a playerUID during the creation process.
This will only work across restarts with UID, yes. So what you will need to do is to get the UID of the specific unit on mission start. Assuming you are putting this into the init field of the storage container, something like this:
[{
params ["_unit"];
!isNull _unit &&
{local _unit} &&
{isPlayer _unit} &&
{getPlayerUID _unit != ""}
},{
params ["_unit","_storageContainer"];
[_storageContainer,getPlayerUID _unit] remoteExecCall ["grad_moneymenu_fnc_setStorage",0,_storageContainer]:
},[p_1,this],30,{}] call CBA_fnc_waitUntilAndExecute;
(might contain bugs)
Does grad-moneyMenu "ATM accounts" persist during disconnect without the utilization of grad_persistence?
No, you need grad-persistence. Bank account and player money will be saved across disconnects and restart, if you are setting the savePlayerMoney flag.
All Versions OTHER than v20:
Whats v20? Version 20 of what?
Hello and thanks again for responding! I apologize for writing a long and confusing post. I went back and started from scratch and this is blowing my mind, but I am having the exact opposite problem that I was describing above...
I went back to the persistence config and switched loadOnMissionStart = 0
to loadOnMissionStart = 1
and renamed the missionTag
to a different name. At that point, ATM accounts and wallets started to persist through disconnects and server restarts. (I initially was trying to save and load everything manually), however, now I can not get 'setStorage' containers to persist through player disconnects and server restarts...
First, let me explain what I meant by "v20" even though it is kind of just an amusing story/bug at this point. I am working on a scenario that utilizes your mods along with ALiVE called arma3mercenaries. I have a version 20 that has the grad persistence config set to loadOnMissionStart = 0
yet ATM accounts and wallets persisted through disconnects (Although, I could not get the manual save to bring over wallets and ATM accounts through a server restart). I could not figure out how or why this was possible. That is why I was wondering if wallets and ATM accounts persisted through disconnects without grad-persistence.
I have that repository here if you are interested in taking a peek. I am pretty happy with the results so far. It does require a dedicated server to make it playable. But, I usually have a server up (server name: Operation Infinite Justice) with the latest arma3mercenaries scenario.
However, I do all of my testing of your modules by themselves. Only ACE and CBA are loaded when testing your modules. I have that repository here. My only issue at this point are the 'setStorage' containers. I can not get 'setStorage' containers to persist through player disconnects and server restarts...I would appreciate any help. If you do decide to look at my testing repository, it requires grad_presistence, grad_moneyMenu, grad-listBuymenu, and grad-fortifications.
You have saveContainers
set to the right value though, right? See here. If the container object is not being saved, the moneymenu variables that it contains will not be saved either.
Also make sure you are not re-executing grad_moneymenu_fnc_setStorage
in your mission initialization. If grad-persistence has a container saved as a moneymenu storage, it will automatically set it up as a moneymenu storage again when loading.
This might also be a bug, I don't know, but I will only get around to testing it on Tuesday.
You have
saveContainers
set to the right value though, right? See here. If the container object is not being saved, the moneymenu variables that it contains will not be saved either.
That was my issue. I was only trying to save the money, and it never occurred to me that the containers needed to be saved as well. I needed to set saveContainers = 2
for the results that I was looking for.
If the container object is not being saved, the moneymenu variables that it contains will not be saved either.
I do apologize if it said that somewhere in the wiki. I totally overlooked the saveContainers
configuration thinking it only applied to ammo boxes etc. I did not realize it was essential to saving the money tied to them. It is very obvious now, lmao, but it wasn't a few days ago :)
I did learn about the grad-persistence and setStorage "bug" if you want to call it that. I noticed that if I initialized the setStorage objects in the init.sqf it would double the interaction menu for those objects(2 options to store money, 2 options to get money) after a server restart and a grad-persistence autoload. Also, if you manually load grad-persistence, it will add a 3rd menu, 4th menu, etc...
I really appreciate your help with everything! Thank you!
Hello McDiode! I am going to toss another question in this thread that pertains to grad-persistence and the ALiVE mod. I want to show you one example of how the ALiVE mod incorporates structure persistence from ACEX Fortify.
Persist ACEX Fortify Objects In initServer.sqf (or wherever you choose to execute server-only code):
["acex_fortify_objectPlaced", {
[ALiVE_SYS_LOGISTICS, "updateObject", [(_this select 2)]] call ALIVE_fnc_logistics;
}] call CBA_fnc_addEventHandler;
["acex_fortify_objectDeleted", {
[ALiVE_SYS_LOGISTICS, "removeObject", [(_this select 2)]] call ALIVE_fnc_logistics;
}] call CBA_fnc_addEventHandler;
If you choose to make this event handler client side, be sure to make it only be triggered by the user that moved the object.
I was hoping that your grad-fortifications (maybe I should have asked this question over there) had some class names for the grad-fortifications that are placed and deleted.
If you are wondering why I can't just utilize grad-persistence saveStatics, it is because ALiVE spawns in persistent roadblocks, but apparently the fortifications do not have variable names. So, it obviously dupes all of the roadblocks if I use grad-persistence saveStatics :) After a few restarts, some roadblocks turn into fortresses :)
Thank you for all of your help, Brian
See #32 @BrianV1981
First off, thank you for sharing your scripts! I am utilizing GRAD MoneyMenu and GRAD List-Buymenu with the ALiVE mod. The ALiVE mod has its' own persistence but I was hoping to add the GRAD bank, wallet and container variables to ALiVE's persistence.
["MyCustomVariable", _value] call ALiVE_fnc_setData //will save to the Cloud on next Server Save & Exit
_value = ["MyCustomVariable"] call ALiVE_fnc_getData //will load on next mission start or when command is executed
I am not a scripter, but I do enjoy the creation process. Am I off base for thinking that this is a possibility? http://alivemod.com/wiki/index.php/Persistence