Skip to content
Permalink
Browse files

Moved extraction of money to after the heli is confirmed to be at dro…

…p point. This way players will not be charged if heli flys off with the cargo.
  • Loading branch information...
osuapoc committed May 12, 2015
1 parent 07197d9 commit 1167ec7fc13f7a5044d6fc767e72d5bf5805df25
@@ -41,7 +41,7 @@ if (_price > _playerMoney) exitWith
playSound "FD_CP_Not_Clear_F";
};

_confirmMsg = format ["This airdrop will deduct $%1 from your bank account<br/>",_price];
_confirmMsg = format ["This airdrop will deduct $%1 from your bank account upon delivery<br/>",_price];
_confirmMsg = _confirmMsg + format ["<br/><t font='EtelkaMonospaceProBold'>1</t> x %1",_selectionName];

// Display confirm message
@@ -24,12 +24,7 @@ switch (_type) do {
_selectionName = (_selectionArray select _selectionNumber) select 0;
_selectionClass = (_selectionArray select _selectionNumber) select 1;
_price = (_selectionArray select _selectionNumber) select 2;

_playerMoney = _player getVariable ["bmoney", 0];
if (_price > _playerMoney) exitWith{};

_playermoney = _player setVariable ["bmoney", _playermoney - _price, true];
[_player] spawn fn_savePlayerData;
// Moved money removal until after the drop point.

//OK, now the real fun

@@ -132,6 +127,18 @@ While {true} do {
sleep 0.1;
if (currentWaypoint _grp >= 2) exitWith {}; //Completed Drop Waypoint
};
// Let's handle the money after this tricky spot - This way players won't be charged for non-delivered goods!
_playerMoney = _player getVariable ["bmoney", 0];
if (_price > _playerMoney) exitWith{
{ _x setDamage 1; } forEach units _grp;
_heli setDamage 1;
_object setDamage 1;
diag_log format ["Apoc's Airdrop Assistance - Player Account Too Low, Drop Aborted. %1. Bank:$%2. Cost: $%3", _player, _playerMoney, _price]; //A little log love to mark the Scallywag who tried to cheat the valiant pilot
}; //Thought you'd be tricky and not pay, eh?

_playermoney = _player setVariable ["bmoney", _playermoney - _price, true];
[_player] spawn fn_savePlayerData;
// Now on to the fun stuff:

diag_log format ["Apoc's Airdrop Assistance - Object at %1, Detach Up Next", position _object]; //A little log love to confirm the location of this new creature
detach _object; //WHEEEEEEEEEEEEE

15 comments on commit 1167ec7

@LouDnl

This comment has been minimized.

Copy link
Contributor

replied May 12, 2015

Apoc,

After your latest commits this error is in my RPT. Which is strange as the line is the same as it was before but it's later on in the script. Maybe the _player part becomes undefined? Didn't have this error before your latest commit.

[code]
2015/05/12, 15:30:08 "Apoc's Airdrop Assistance - Object at [13827.5,18732.6,196.04], Detach Up Next"
2015/05/12, 15:30:08 Error in expression <rmoney - _price, true];
[_player] spawn fn_savePlayerData;

diag_log format ["A>
2015/05/12, 15:30:08 Error position: <fn_savePlayerData;

diag_log format ["A>
2015/05/12, 15:30:08 Error Undefined variable in expression: fn_saveplayerdata
2015/05/12, 15:30:08 File mpmissions__cur_mp.Altis\addons\APOC_Airdrop_Assistance\APOC_srv_startAirdrop.sqf, line 146
[/code]

@osuapoc

This comment has been minimized.

Copy link
Member Author

replied May 12, 2015

Interesting @LouDnl , I'll take a look at it in about an hour when lunch hits and see if I get the same error. I don't recall having any errors last night on final testing, but it was after midnight so I may have missed something. It is weird though, considering that the code was just moved from the top of the script to the bottom, and nothing is undefining or nullifying that _player variable that I can see.

@LouDnl

This comment has been minimized.

Copy link
Contributor

replied May 12, 2015

Remember that fn_savePlayerData is local to the player. See: https://github.com/MayhemServers/MAYHEM_A3Wasteland.Altis/blob/Development_main/persistence/client/players/setupPlayerDB.sqf#L7-L13
This error only occured after I added your latest commit. So my guess (really a guess) is that _player becomes undefined so the spawn cannot be executed.

@osuapoc

This comment has been minimized.

Copy link
Member Author

replied May 12, 2015

Actually, based on that, I'm surprised we weren't seeing this error before. According to the first check of that file, the server should have never compiled that function, and should have always thrown an error. Placing the [_player] argument doesn't change the locality of the script/function execution. I'm guessing to get this done properly, I'll just have to pass the _player argument via BIS_fnc_MP to the player to run that function. Wonder why we didn't see the error before?

Well, not pass _player, but use that to target the appropriate player.

@LouDnl

This comment has been minimized.

Copy link
Contributor

replied May 12, 2015

Have searched my logs and have never gotten this error before. Only after this latest commit. Very strange!

@LouDnl

This comment has been minimized.

Copy link
Contributor

replied May 12, 2015

Have even tested the saving after I gave you the tip to add this in. It did work.

@osuapoc

This comment has been minimized.

Copy link
Member Author

replied May 12, 2015

Interestingly, fn_savePlayerData does not actually save the bank money directly. I'm thinking the server picks up the fact that the player is executing a data save, and adds the bank money into the data packet heading to the SQL update, but I've not stared at it long enough to make sense of it.

@AgentRev What is the best way to have a server function run a save of a player's data (specifically bank money)?

@osuapoc

This comment has been minimized.

Copy link
Member Author

replied May 12, 2015

So I think I have managed it at this point. Using the BIS_fnc_MP, coupled with a new AH exception.
fdde656

@LouDnl

This comment has been minimized.

Copy link
Contributor

replied May 12, 2015

Could you reproduce the error?

@osuapoc

This comment has been minimized.

Copy link
Member Author

replied May 12, 2015

Yes, I was able to reproduce, much to my dismay. I have no idea why the bug didn't crop up until that code was moved lower. It SHOULD have errored. As near as I can tell, there is no argument call in fn_savePlayerData, and the server doesn't compile the function, so the server should have full-derped when it was called.

Anyhow, everything else seems OK at this point. Hopefully the bloomin' chopper will continually drop for people.

@LouDnl

This comment has been minimized.

Copy link
Contributor

replied May 12, 2015

Allright will implement it :)

@AgentRev

This comment has been minimized.

Copy link
Contributor

replied May 12, 2015

You're doing it wrong. Anything that messes with bmoney should be located in processTransaction.sqf server-side. Otherwise, money will be lost out of the blue if client and server try to change bmoney at the same time. The odds of it actually happening are low (maybe once a week), but never underestimate Murphy's law.

@osuapoc

This comment has been minimized.

Copy link
Member Author

replied May 12, 2015

Well, maybe this is a more proper method then, @AgentRev .
486ee20

I wasn't sure if I should use publicVariableServer, considering the function is running on the server.

@AgentRev

This comment has been minimized.

Copy link
Contributor

replied May 13, 2015

Okay, I think we misunderstood each other. If bmoney was already being set server-side, then there is no need to use processTransaction.

Indeed, fn_savePlayerData does not save the bank money directly, the value is added to the request before being handed to extDB: https://github.com/A3Wasteland/ArmA3_Wasteland.Altis/blob/2729dbb342283ed7164e2e6f65aa87dcd75525f0/persistence/server/players/setupPlayerDB.sqf#L32-L33

If you want to save bmoney alone server-side, just do the same thing as processTransaction:

[getPlayerUID _player, [["BankMoney", _newBalance]], []] call fn_saveAccount; 
@osuapoc

This comment has been minimized.

Copy link
Member Author

replied May 13, 2015

ahhh, I see. Well then. I'll end up reversing this latest commit and doing it properly, then.
Thanks for your help, Rev!

Please sign in to comment.
You can’t perform that action at this time.