Jump to content
Quengis

public variable number all over the place

Recommended Posts

Hello, I recently started mission scripting in arma 3 and wanted to create a money system and a vehicle shop for multiplayer. but my friends balance is 650 and mine is 100 even though i set my variable: cash = 100. i need some help with this
here's my script in init.sqf:


 

cash=100;


    shop1 addAction ["Count Cash Balance", {hint format ["Your Balance is: $%1", cash];},[],6];

    shop1 addAction ["Buy Prowler (Unarmed) for $75", {if (cash >= 75)
        then {
        cash=cash-75;
        shop1 sideChat "Thank you for your purchase!";
        dude1 = "B_LSV_01_unarmed_F" createVehicle getMarkerPos "garage_1";}
    else{
    shop1 sideChat "Not enough money";}}];

    shop1 addAction ["Buy Hunter (GMG) for $300", {if (cash >= 300)
        then {
        cash=cash-300;
        shop1 sideChat "Thank you for your purchase!";
        dude1 = "B_MRAP_01_gmg_F" createVehicle getMarkerPos "garage_1";}
    else{
    shop1 sideChat "Not enough money";}}];

    shop1 addAction ["Buy IFV-6c Panther for $550", {if (cash >= 550)
        then {
        cash=cash-550;
        shop1 sideChat "Thank you for your purchase!";
        dude1 = "B_APC_Tracked_01_rcws_F" createVehicle getMarkerPos "garage_1";}
    else{
    shop1 sideChat "Not enough money";}}];

    shop1 addAction ["Buy AMV-7 Marshall for $1000", {if (cash >= 1000)
        then {
        cash=cash-1000;
        shop1 sideChat "Thank you for your purchase!";
        dude1 = "B_APC_Wheeled_01_cannon_F" createVehicle getMarkerPos "garage_1";}
    else{
    shop1 sideChat "Not enough money";}}];

 

Share this post


Link to post
Share on other sites

Your friends are smart. Ask them for some money

Spoiler

... or try to share your code.

 

  • Haha 2

Share this post


Link to post
Share on other sites
8 hours ago, Quengis said:

and mine is 100 even though i set my variable: cash = 100

Sounds about right. Try to invest maybe?

Share this post


Link to post
Share on other sites
1 hour ago, killzone_kid said:

Sounds about right. Try to invest maybe?

 

In these times of war, I would recommend to put your money into a good mix of commodities and maybe shares in the defence industry. Nothing with production facilities in the area of chernarus (redux) however, things seem to have gone south there. 

Avoid real-estate, altis and co just do not seem to be stable enough. Nuked real estate loses its value quickly.

Share this post


Link to post
Share on other sites
14 minutes ago, Vandeanson said:

 

In these times of war, I would recommend to put your money into a good mix of commodities and maybe shares in the defence industry. Nothing with production facilities in the area of chernarus (redux) however, things seem to have gone south there. 

Avoid real-estate, altis and co just do not seem to be stable enough. Nuked real estate loses its value quickly.

I put most of my savings into stock of the biggest furniture company on altis.

Go figure.

 

Cheers

  • Haha 3

Share this post


Link to post
Share on other sites
48 minutes ago, Grumpy Old Man said:

I put most of my savings into stock of the biggest furniture company on altis.

Go figure.

 

Cheers

My women's sanitary products company fared equally well.

  • Haha 3

Share this post


Link to post
Share on other sites

no like seriously, im making a mission using cash, and i set the cash for 100 for all of us, testing it he somehow gets more. im super confused. even when i set cash to 0 he gets 550

Share this post


Link to post
Share on other sites
11 hours ago, Tankbuster said:

Thoughts and prayers.

THOUGHTS AND PRAYERS.

 

When done twice they just cancel each other out.

 

33 minutes ago, Quengis said:

no like seriously, im making a mission using cash, and i set the cash for 100 for all of us, testing it he somehow gets more. im super confused. even when i set cash to 0 he gets 550

 

So is everyone else here. You need to show your work/code or explain what steps you've taken (especially if you're doing everything in the editor) otherwise no one has any idea what you're doing. For example, if I took my car into a mechanics and said "Yeah nah she's fucked aye" and walked out, it's not going to get me very far. Obviously there are people here who can help, but you gotta help them help yourself.

  • Like 2

Share this post


Link to post
Share on other sites

Now this is what happens when someone, as we say in English, tries to run before learning to walk.

 

@Quengis, I'm afraid, you're going to have a terribly hard time making this mission you've envisaged if you can't even get this working. Not only that, you aren't even asking the right questions. Not only have I been there, but I've written this same post warning them a dozen times. I'm not having a go or being nasty, but I think it's important you know where you're going wrong and at the moment, it's everywhere.

Share this post


Link to post
Share on other sites

You added a code in your question.  Now, it's obvious, you can't script something consistent but you need a whole cash system.

I suggest you to have a look at some existing topics, at least for having a more accurate view on what to do. Scripting in MP is not so easy. So, try to run some existing public codes prior to adapt them.

 

https://forums.bohemia.net/forums/topic/211208-need-help-making-simple-money-system/

http://www.armaholic.com/forums.php?m=posts&q=31516

https://forums.bohemia.net/forums/topic/219677-release-virtual-arsenal-shop-system/

https://forums.bohemia.net/forums/topic/188529-help-with-add-action-and-passing-a-value/

https://forums.bohemia.net/forums/topic/216787-pass-variable-from-client-to-a-object-with-addaction-via-remoteexec/

 

Share this post


Link to post
Share on other sites
9 hours ago, Quengis said:

no like seriously, im making a mission using cash, and i set the cash for 100 for all of us, testing it he somehow gets more. im super confused. even when i set cash to 0 he gets 550

If the debug console is enabled for everyone and he knows how to use it he simply might have added the cash himself.

 

It's usually better practice to keep stuff like cash variables on the holding object, instead of putting it as a global variable.

You also could condense all these multiple addAction lines into a few functions, which will make adding more items more convenient, and also increase the customization of messages etc., so instead of this:

 shop1 addAction ["Buy Prowler (Unarmed) for $75", {if (cash >= 75)
        then {
        cash=cash-75;
        shop1 sideChat "Thank you for your purchase!";
        dude1 = "B_LSV_01_unarmed_F" createVehicle getMarkerPos "garage_1";}
    else{
    shop1 sideChat "Not enough money";}}];

    shop1 addAction ["Buy Hunter (GMG) for $300", {if (cash >= 300)
        then {
        cash=cash-300;
        shop1 sideChat "Thank you for your purchase!";
        dude1 = "B_MRAP_01_gmg_F" createVehicle getMarkerPos "garage_1";}
    else{
    shop1 sideChat "Not enough money";}}];

    shop1 addAction ["Buy IFV-6c Panther for $550", {if (cash >= 550)
        then {
        cash=cash-550;
        shop1 sideChat "Thank you for your purchase!";
        dude1 = "B_APC_Tracked_01_rcws_F" createVehicle getMarkerPos "garage_1";}
    else{
    shop1 sideChat "Not enough money";}}];

You could use something this:


//list for vendor
_pricelist = [["B_LSV_01_unarmed_F",75],["B_MRAP_01_gmg_F",300],["B_APC_Tracked_01_rcws_F",550]];


//functions to handle money and vendor items
TAG_fnc_changeMoney = {
	params ["_unit","_amount"];
	_currentMoney = _unit getVariable ["TAG_fnc_money",0];

	if (_currentMoney + _amount < 0) exitWith {
		hint "Not enough money";false
	};

	_newAmount = _currentMoney + _amount;
	_unit setVariable ["TAG_fnc_money",_newAmount];
	hint format ["You %1 $%2.\nYou now have $%3.",["spent","received"] select (_amount > 0),abs _amount,_newAmount];
	true
};


TAG_fnc_addVendorItem = {
	params ["_vendor","_item","_price"];
	_itemName = getText (configFile >> "CfgVehicles" >> _item >> "displayName");
	_vendor addAction [format ["Buy %1 - $%2",_itemName,_price],{
		params ["_vendor","_buyer","_ID","_arguments"];
		_arguments params ["_item","_price","_itemName"];
		_canBuy = [_buyer,-_price] call TAG_fnc_changeMoney;
		_message = "I'm afraid you can't quite afford that.";

		if (_canBuy) then {
			_message = format ["Enjoy your new %1, %2!",_itemName, name _buyer];
			_item createVehicle getMarkerPos "garage_1"
		};
		
	_vendor sideChat _message;
	},[_item,_price,_itemName],1.5,true,true,"","_target distance2D _this < 3"];
};

//add items and radio to vendor
_vendor = shop1;
if !("ItemRadio" in assigneditems _vendor) then {_vendor linkItem "ItemRadio"};
{
	[_vendor,_x#0,_x#1] call TAG_fnc_addVendorItem
} forEach _pricelist;
[player,850] call TAG_fnc_changeMoney;//for testing

You basically set up a few functions to handle money change and vendor items, then all you need to add further items is to enhance the list on top with class name and price.

You could even add custom vendor messages depending on which item has been bought, add random messages if money wasn't enough and all other flavor stuff.

Should get you started anyway, of course you'd need to keep locality in mind and adjust it accordingly.

 

BpLZGvh.png

 

Cheers

Share this post


Link to post
Share on other sites

thanks, ill look into that

 

for clarification, the script you sent me have personal balances, which means that i have my own while another player has theirs? and also another thing: if i were to make a trigger to update the currency, which variable would i have to change?

 

Share this post


Link to post
Share on other sites
10 hours ago, Quengis said:

for clarification, the script you sent me have personal balances, which means that i have my own while another player has theirs? and also another thing: if i were to make a trigger to update the currency, which variable would i have to change?

 

Yes, that's how it works, would even work with global variable if they're not broadcast to other clients, saving variables on objects is preferable though.

To change the amount of money someone has, simply use the TAG_fnc_changeMoney function, as shown in the snippet.

As already stated by others earlier, doing something like a money system for MP is a more intermediate undertaking and can be approached differently depending on how secure/foolproof you want it to be.

Take my snippet as a mere starting point, since it doesn't take locality into account due to reasons mentioned earlier, heh.

 

Cheers

Share this post


Link to post
Share on other sites

thanks, i tested it with my friend and it works now, we have different balances and everything is good. thanks for your help


Quengis 

  • Like 2

Share this post


Link to post
Share on other sites

turns out that i'm back here again. here's the thing: I was testing with the same friend in my test server, and it was absolutely fine meaning that i got the same amount of money. (note that i hosted the server using server browser)

then comes my real mission, which i implemented the new script. (also hosting it using server browser)

init.sqf:

_pricelist = [["B_LSV_01_unarmed_F",75],["B_MRAP_01_gmg_F",200],["B_APC_Tracked_01_rcws_F",550],["B_APC_Wheeled_01_cannon_F",1000],["B_MBT_01_cannon_F",3500],["B_APC_Tracked_01_AA_F",4000]];
TAG_fnc_changeMoney = {
	params ["_unit","_amount"];
	_currentMoney = _unit getVariable ["TAG_fnc_money",0];

	if (_currentMoney + _amount < 0) exitWith {
		hint "Not enough money";false
	};

	_newAmount = _currentMoney + _amount;
	_unit setVariable ["TAG_fnc_money",_newAmount];
	hint format ["You %1 $%2. You now have $%3.",["spent","received"] select (_amount > 0),abs _amount,_newAmount];
	true
};


TAG_fnc_addVendorItem = {
	params ["_vendor","_item","_price"];
	_itemName = getText (configFile >> "CfgVehicles" >> _item >> "displayName");
	_vendor addAction [format ["Buy %1 - $%2",_itemName,_price],{
		params ["_vendor","_buyer","_ID","_arguments"];
		_arguments params ["_item","_price","_itemName"];
		_canBuy = [_buyer,-_price] call TAG_fnc_changeMoney;
		_message = "I'm afraid you can't quite afford that.";

		if (_canBuy) then {
			_message = format ["Enjoy your new %1, %2!",_itemName, name _buyer];
			_item createVehicle getMarkerPos "garage_1"
		};

	_vendor sideChat _message;
	},[_item,_price,_itemName],1.5,true,true,"","_target distance2D _this < 3"];
};

//add items and radio to vendor
_vendor = shop1;
if !("ItemRadio" in assigneditems _vendor) then {_vendor linkItem "ItemRadio"};
{
	[_vendor,_x#0,_x#1] call TAG_fnc_addVendorItem
} forEach _pricelist;

i made my mission so that we receive 200 dollars at a certain point in the mission, having a notification. the only thing was my friend got money from the start, getting his notification saying that he had 550 dollars. He also did not have the debug console. i need help again 😕

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

×