Jump to content
Sign in to follow this  
williampett

Changing Variables

Recommended Posts

Hi, I'm trying to create a shop that sells a Civilian Mi-17 to the player. This works up to the point where I want the money to be taken off the player.

I have searched for methods of doing this and have found any.

The player starts with £1000 which is decided by the script:

player setVariable ["money", 1000]; 

I placed this script in the init.sqf for the mission.

Here is the script that I am trying to use:

_player= if (player getVariable "money" > 499) then
{
_vehicle = createVehicle ["Mi17_Civilian", getMarkerPos "test", [], 50, "CAN_COLLIDE"];
player getVariable ["money", money -500];
player groupChat "You have bought an MI-17"
}
else
{
player groupChat "You do not have enough money";
};

The part that I am having the problem with is:

player getVariable ["money", money -500];

here I am trying to alter the variable "money", and take 500 away from it.

I understand that my knowledge on scripting is very limited as I am still in the learning stages.

Is it possible for me to change this variable? If so, how can I do it?

Share this post


Link to post
Share on other sites
_p = player;
_m = _p getVariable "money";

if (_m > 499) then {
_m = _m - 500;
_p setVariable ["money", _m];
_p groupChat "You just bought an Mi-17!";
_v = createVehicle ["Mi17_Civilian", getMarkerPos "test", [], 50, "CAN_COLLIDE"];
} else {
_p groupChat "Sorry, you do not have enough money!";	
};

Share this post


Link to post
Share on other sites

You have to do this with at least two separate commands (untested code follows):

_temp = player getVariable "money";
player setVariable ["money", _temp - 500];

Edit: kylania was faster and has psted correct code

Edited by zwobot
wrong code and faster answer

Share this post


Link to post
Share on other sites
_p = player;
_m = _p getVariable "money";

if (_m > 499) then {
_m = _m - 500;
_p setVariable ["money", _m];
_p groupChat "You just bought an Mi-17!";
_v = createVehicle ["Mi17_Civilian", getMarkerPos "test", [], 50, "CAN_COLLIDE"];
} else {
_p groupChat "Sorry, you do not have enough money!";	
};

This has helped a lot, thank you :)

Share this post


Link to post
Share on other sites
Edit: kylania was faster and has psted correct code

We had the same code essentially, I just spelled it out longer. :)

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
Sign in to follow this  

×