SRTT Player cash (LUA)

I have tried (but I had given up) to create a system which takes away your cash when you die according to how much money you currently have ;(like in GTA games).What I tried to do was to decrease 10% of the current cash the player has when he gets smoked.
This is the code written in LUA:

function cash_penalty(player_cash)
on_death("the_penalty",LOCAL_PLAYER)
end

function the_penalty()
cash_add( -((player_cash*10) /100)) ) --- the minus before means that it adds negative cash which means that it decreases the cash
end

Nothing happens when I get smoked...player_cash is not working accordingly and it's obvious that it doesn't get called like in bulding_purchase.lua.Here is a slice of code taken from builing_purchase.lua which uses the same variable player_cash as I used :

if player_cash < store_cost then
-- Show Dialog that says you can't afford it.
...
else
-- Ask player if they really want to purchase it.
...
end

What's wrong with my code and why player_cash doesn't get called from C++ but in the other ones from the [stores].lua do get called?
 
I don't know how familiar you are with programming, but there's not a lot of detail here, so i start at the bottom... what is calling cash_penalty, and where is player_cash defined, in your file? player_cash is not a function; judging by the code snippet you included, it's a variable that is set earlier in the file.
 
I don't know how familiar you are with programming, but there's not a lot of detail here, so i start at the bottom... what is calling cash_penalty, and where is player_cash defined, in your file? player_cash is not a function; judging by the code snippet you included, it's a variable that is set earlier in the file.

Yeah player_cash is not supposed to be a function but an already defined variable.
To be more detailed here is the full thing,it's all in sr3_city.lua obviously:
function sr3_city_main()
cash_penalty()
end
and then the functions also defined in sr3_city.lua:
function cash_penalty(player_cash)
on_death("the_penalty",LOCAL_PLAYER)
end

function the_penalty()
cash_add( -((player_cash*10) /100)) ) --- the minus before means that it adds negative cash which means that it decreases the cash
end
player_cash is not defined because it's a variable which can only be called from C++ from what I've seen in building_purchase.lua or other lua files which represents acquisitions of goods.Here is a dev commentary from store_crib_stash.lua:
-- Called by C++ via data responder
--
-- cash_from_bank how much the bank is paying the player
-- player_cash how much cash the player has before withdrawl
-- daily_cash how much cash the player earns per day...
-- transfer_cap How much cash the bank can max out on.
I've never ever seen player_cash being defined in any of the lua files from the game files so it's clear that player_cash is a C++ variable which tracks the current cash the player has but it can only be called from certain lua files but not from sr3_city.lua so the main question is how can I call player_cash to track the cash the player has in sr3_city.lua ?

EDIT

To make it more simple...Is there any lua function which tracks the current cash the player has?
 
The main problem is that player_cash is not a general function/variable that you can use anywhere. It is a value that is pushed to the specific UI script as part of the data responder and if you look is actually just a parameter to "store_crib_cash_populate" so is local to that function. Looking through the SR3 code I don't actually see any scripting exposure that would return the current amount of money the player has.

Another problem that you would have trying to do this (assuming that you could get the current amount of money the player has) will be that the SR engine only allows one of each callback at a time. That means that if you setup your on_death callback during level load like you are and any mission you play were to set the on_death callback your new penalty would stop being called.

Also, it totally won't work like you expect in coop ;) but don't feel bad about that. Even actual devs on SR couldn't always get that right.
 
Back
Top