revv 15 Posted April 17, 2016 Hello all I am at the point of begging for help to solve this issue. I have been on the wiki, searched google and spent hours on youtube trying to find a solution and I just cant work it out.I have a shop system in place which is working fine, I have a currency system in place which also works fine...what I can't get to work is saving player's money variable so when they come back they have the same amount of money. Gear saves and loads fine using the OO_PDW script but it doesn't handle custom variables. I looked through the pdw script so see how it saves gear and no matter what I do every time a player leaves and reconnects they have 0 cash and right now I have a box set up with an addAction to add more cash for testing and it seems the very first player to connect gets everything working fine but as soon as someone leaves and comes back they can't even use the box to get money.In my init.sqf I have some code which determines if someone has been on the server or not which works fine and if they have not been on the server they run this:initPlayerFirstJoin.sqf //////Set Initial Loadout\\\\\\ if ((typeOf player) == "B_Soldier_F") then { private ["_unit"]; _unit = _this select 0; removeAllWeapons _unit; removeallassigneditems _unit; removeallcontainers _unit; removeuniform _unit; removevest _unit; removebackpack _unit; // "Add containers"; _unit forceAddUniform "TRYK_U_B_Denim_T_BG_WH"; _unit addItemToUniform "ACE_epinephrine"; _unit addItemToUniform "ACE_IR_Strobe_Item"; for "_i" from 1 to 5 do {_unit addItemToUniform "ACE_fieldDressing";}; _unit addItemToUniform "ACE_EarPlugs"; _unit addVest "V_TacVestIR_blk"; for "_i" from 1 to 5 do {_unit addItemToVest "CUP_15Rnd_9x19_M9";}; for "_i" from 1 to 6 do {_unit addItemToVest "CUP_30Rnd_556x45_Stanag";}; _unit addHeadgear "CUP_H_PMC_Cap_PRR_Grey"; _unit addGoggles "CUP_TK_NeckScarf"; // "Add weapons"; _unit addWeapon "CUP_arifle_M4A1_black"; _unit addPrimaryWeaponItem "CUP_acc_ANPEQ_2"; _unit addPrimaryWeaponItem "optic_Hamr"; _unit addWeapon "CUP_hgun_M9"; // "Add items"; _unit linkItem "ItemMap"; _unit linkItem "ItemCompass"; _unit linkItem "ItemWatch"; _unit linkItem "ItemRadio"; }; //////Money Stuff\\\\\\ //HG_myCash = 100000; player setVariable["HG_myCash", 100000]; private ["_oldVal"]; _oldVal = player getVariable "HG_myCash"; ["_oldVal"] call Bank_fnc_saveAccount; hint "First Time Setup Complete..."; I know they money stuff is wrong as it is not working, this is just how it ended up today after messing around with functions for the first time.Now the saveAccount isfn_saveAccount.sqf params ["_oldVal"]; private "_oldVal"; profileNamespace setVariable ["myMoney", (player getVariable "HG_myCash")]; saveProfileNamespace; player sideChat format ["Balance: %1", (player getVariable "HG_myCash")]; So if the player has already been on the server they load:fn_loadAccount.sqf player setVariable["HG_myCash",(profileNamespace getVariable "myMoney")]; So if someone can help me get this working I would appreciate it greatly as I have spent pretty much every waking moment on this for a week now and it's driving me nuts.Just to reiterate this is working perfect for the first person who joins, everything does as it's supposed to for them but anyone else who joins after it does not work and then if that first person leaves and comes back it no longer works for them either. Any help is appreciated BUT please dont just give me a link to the BIKI becasue I have been living on there for a week already lol, if you know what I need is on there then please point it out with some sort of description of what I'm looking for. Thanks! Share this post Link to post Share on other sites
revv 15 Posted April 17, 2016 A little more infor on this I have an error that comes up saying undefined variable #_oldVal line 14 in this file:fn_addOrSubCash.sqf /* Author - HoverGuy Description - Used to add or substract money from the money variable */ params["_amount","_mode"]; private "_oldVal"; switch(_mode) do { case 0: { _oldVal = player getVariable "HG_myCash"; player setVariable["HG_myCash",(_oldVal + _amount)]; }; case 1: { _oldVal = player getVariable "HG_myCash"; player setVariable["HG_myCash",(_oldVal - _amount)]; }; }; _oldVal = player getVariable "HG_myCash"; ["_oldVal"] call Bank_fnc_saveAccount; This is from Hover Guy's simple shop system and it's used for adding and subtracting money via it's function. Share this post Link to post Share on other sites
hoverguy 177 Posted April 17, 2016 A little more infor on this I have an error that comes up saying undefined variable #_oldVal line 14 in this file: fn_addOrSubCash.sqf /* Author - HoverGuy Description - Used to add or substract money from the money variable */ params["_amount","_mode"]; private "_oldVal"; switch(_mode) do { case 0: { _oldVal = player getVariable "HG_myCash"; player setVariable["HG_myCash",(_oldVal + _amount)]; }; case 1: { _oldVal = player getVariable "HG_myCash"; player setVariable["HG_myCash",(_oldVal - _amount)]; }; }; _oldVal = player getVariable "HG_myCash"; ["_oldVal"] call Bank_fnc_saveAccount; This is from Hover Guy's simple shop system and it's used for adding and subtracting money via it's function. If the variable is set on the player, there shouldnt be any problems: [100,1] call HG_fnc_addOrSubCash params["_amount","_mode"]; private "_oldVal"; _oldVal = player getVariable "HG_myCash"; switch(_mode) do { case 0: { player setVariable["HG_myCash",(_oldVal + _amount)]; }; case 1: { player setVariable["HG_myCash",(_oldVal - _amount)]; }; }; Share this post Link to post Share on other sites
revv 15 Posted April 17, 2016 If the variable is set on the player, there shouldnt be any problems: [100,1] call HG_fnc_addOrSubCash params["_amount","_mode"]; private "_oldVal"; _oldVal = player getVariable "HG_myCash"; switch(_mode) do { case 0: { player setVariable["HG_myCash",(_oldVal + _amount)]; }; case 1: { player setVariable["HG_myCash",(_oldVal - _amount)]; }; }; That's what I thought and I tried that exactly but it gives the same error Share this post Link to post Share on other sites
davidoss 552 Posted April 17, 2016 You do not need to define extra private variable params["_amount","_mode"]; private "_oldVal"; params["_amount","_mode", "_oldVal"]; has the same meaning Share this post Link to post Share on other sites
hoverguy 177 Posted April 17, 2016 That's what I thought and I tried that exactly but it gives the same error Try to debug it, add right after _oldVal: hint str _oldVal; Share this post Link to post Share on other sites
revv 15 Posted April 17, 2016 Try to debug it, add right after _oldVal: hint str _oldVal; Sorry where exactly do I put that? Near top after _oldVal = player getVariable "HG_myCash"; ? Or after where the error is on line 14? Share this post Link to post Share on other sites
revv 15 Posted April 18, 2016 So I am still looking for help on this if anyone can have a look. Trying to figure out why this keeps giving an error. After some more investigation I found that the server must be trying to execute some code where it should not.Here is the file Im having trouble with and the error /* Author - HoverGuy Description - Used to add or substract money from the money variable © All Fucks Reserved To add cash [_amount,0] call HG_fnc_addOrSubCash; To sub cash [_amount,1] call HG_fnc_addOrSubCash; */ params["_amount","_mode"]; private "_oldVal"; _oldVal = player getVariable "HG_myCash"; switch(_mode) do { case 0: { player setVariable["HG_myCash",(_oldVal + _amount)]; }; case 1: { player setVariable["HG_myCash",(_oldVal - _amount)]; }; }; [] call Bank_fnc_saveAccount; The error is line 19 undefined variable _oldValAny help appreciated Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 18, 2016 u should check the return value of player getVariable "HG_myCash"; in line 13 Share this post Link to post Share on other sites
revv 15 Posted April 18, 2016 u should check the return value of player getVariable "HG_myCash"; in line 13 Okay, how can I do that exactly? thanks for the response :) Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 18, 2016 systemChat format ["%1", (player getVariable "HG_myCash")]; Share this post Link to post Share on other sites
revv 15 Posted April 18, 2016 systemChat format ["%1", (player getVariable "HG_myCash")]; Oh right, I have an addAction on players to check that variable. It returns nil and after the money variable is updated like when recieved money it also checks but that returns scalar NaN Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 18, 2016 that means that first the player has no defined HG_myCash and after ur money update it has a wrong value. idk what scalar NaN means but its not ur desired value. Now u have to get a step back and check what is happening with HG_myCash before u start hoverguys script. How do u update that value? Share this post Link to post Share on other sites
revv 15 Posted April 18, 2016 that means that first the player has no defined HG_myCash and after ur money update it has a wrong value. idk what scalar NaN means but its not ur desired value. Now u have to get a step back and check what is happening with HG_myCash before u start hoverguys script. How do u update that value? So on initPlayerLocal.sqf I have this: params["_player","_jip"]; /* ----- PDW ----- */ call compilefinal preprocessFileLineNumbers "oo_pdw.sqf"; pdw = ["new","profile"] call OO_PDW; /* ----- End PDW ----- */ HG_myCash = 10000; /* ----- If not first time join, restore gear else set initial loadout ----- */ if(!isNil {profileNamespace getVariable["DMP_FirstJoin",false]}) then { ["clearInventory",_player] call pdw; ["loadPlayer",_player] call pdw; ["loadInventory",[(name _player),_player]] call pdw; remoteExecCall ["Bank_fnc_loadAccount", -2, false]; } else { profileNamespace setVariable["DMP_FirstJoin",true]; saveProfileNamespace; removeAllWeapons _player; removeAllAssignedItems _player; removeAllContainers _player; removeUniform _player; removeVest _player; removeBackpack _player; _player forceAddUniform "TRYK_U_B_Denim_T_BG_WH"; _player addItemToUniform "ACE_epinephrine"; _player addItemToUniform "ACE_IR_Strobe_Item"; for "_i" from 1 to 5 do {_player addItemToUniform "ACE_fieldDressing";}; _player addItemToUniform "ACE_EarPlugs"; _player addVest "V_TacVestIR_blk"; for "_i" from 1 to 5 do {_player addItemToVest "CUP_15Rnd_9x19_M9";}; for "_i" from 1 to 6 do {_player addItemToVest "CUP_30Rnd_556x45_Stanag";}; _player addHeadgear "CUP_H_PMC_Cap_PRR_Grey"; _player addGoggles "CUP_TK_NeckScarf"; _player addWeapon "CUP_arifle_M4A1_black"; _player addPrimaryWeaponItem "CUP_acc_ANPEQ_2"; _player addPrimaryWeaponItem "optic_Hamr"; _player addWeapon "CUP_hgun_M9"; _player linkItem "ItemMap"; _player linkItem "ItemCompass"; _player linkItem "ItemWatch"; _player linkItem "ItemRadio"; [100000,0] remoteExecCall ["HG_fnc_addOrSubCash", -2, false]; remoteExecCall ["Bank_fnc_saveAccount", -2, false]; hint "First Time Setup Complete..."; }; /* ---------- */ _player addAction ["Check Balance", "scripts\myBalance.sqf"]; _player addAction["<t color='#ff9900'>Add Money (+100000)</t>", "scripts\addCash.sqf"]; /* ----- Briefing ----- */ player createDiaryRecord [ "Diary", [ "Welcome", "Welcome to Ronin!<br>Don't forget to equip earplugs before executing an operation, <br>safety first people!" ] ]; /* ---------- */ /* ----- Spawn a thread to give cash to player every 2 minutes ----- */ [] spawn { while {true} do { uiSleep 120; [1000,0] call HG_fnc_addOrSubCash; }; }; /* ---------- */ /* ----- Spawn a thread to save gear every 60 seconds ----- */ [] spawn { while {true} do { uiSleep 60; ["savePlayer",player] call pdw; ["saveInventory",[(name player),player]] call pdw; }; }; /* ---------- */ So HG_myCash is set to 0 which means nothing as it is either updated from Bank_fnc_loadAccount or 100000 is added to it if player has no DPM_FirstJoin. The [100000,0] remoteExecCall ["HG_fnc_addOrSubCash", -2, false]; is the code in post#8 Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 18, 2016 I cant see a mistake. add this to your load account script: systemChat format ["%1", (profileNamespace getVariable "myMoney")]; Share this post Link to post Share on other sites
revv 15 Posted April 18, 2016 I cant see a mistake. add this to your load account script: systemChat format ["%1", (profileNamespace getVariable "myMoney")]; It says <null> Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 18, 2016 thats not good. looks like ur saving does not work. what now happens is that u load a value which not exists (null) and then save that value. thats complete nonesense. "myMoney" and HG_myCash cant have ever a value at this point. what u have to get to work is the saving when player connects first time. look with those systemChats if the correct value is saved after your players init code. if that is the case then u ve to look if loading gets the correct value. I showed u that systemChat thing. Use it for debugging. We cant do the whole thing step by step here. u ve to do some debugging urself. if u get odd things or something u dont understand then just ask. U ve to track the value of players money value through ur code with that systemchats... Share this post Link to post Share on other sites
hoverguy 177 Posted April 18, 2016 That is what I told him on Steam... the var is not set on you so addOrSubCash func does not know what _oldVal is since it is trying to store it hence why it throws the error. As sarogahtyp said, track your profileNamespace variable (DMP_myMoney) when you first connect to see if things are setup properly. On a side note you can remove the two remoteExecCall lines in initPlayerLocal.sqf and just use the functions without remote execution. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 18, 2016 lol, that should be the mistake. that remoteexec will call the function at all clients except the server and players client. i thought that is executed by server. i didnt notice that its running at client. Share this post Link to post Share on other sites
hoverguy 177 Posted April 18, 2016 lol, that should be the mistake. that remoteexec will call the function at all clients except the server and players client. i thought that is executed by server. i didnt notice that its running at client. The thing is that he sent the mission to me and these two lines were not in the file. I guess he just tried so many things, he ended up using remote execution for whatever reason. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted April 19, 2016 assuming from ur other post where u now use hoverguys script I think that this topic is solved. Why not sharing the solution. If u ask for help then its the minimum u could payback to share the solution. We help to learn from it... Share this post Link to post Share on other sites
revv 15 Posted April 19, 2016 assuming from ur other post where u now use hoverguys script I think that this topic is solved. Why not sharing the solution. If u ask for then its the minimum u could payback to share the solution. Because without sharing my entire mission folder it would make no sense to anyone reading it.All of the broken things were to do with my scripts interacting with Hover Guy's scripts AND the OO_PDW system. Aside from that all of the information on the wiki regarding the saving and loading profileNamespace is accurate, I just wasn't getting the locality stuff right. Having said that I will be publishing my mission when it's complete but if you want to see anything specific just PM me and I can send it to you :) Share this post Link to post Share on other sites