Jump to content

[DEVS] Universal remove/add Coins function


Recommended Posts

Universal Develoment functions for script developers, also included in the compiles of the singel currency.

 

Updated 28-08-2014

Always succes when removing 0 coins.

 

999 Headshot system:

// usage
// _removed = [player, 5000] call SC_fnc_removeCoins;
// if(_removed = true)then{  GREAT SUCCES  }else{ IT FAILED, not enoguh money};

SC_fnc_removeCoins=
    {
                private ["_player","_amount","_wealth","_newwealth", "_result"];
                _player = _this select 0;
                _amount = _this select 1;
                _result = false;
                _wealth = _player getVariable["headShots",0];  
                if(_amount > 0)then{
                if (_wealth < _amount) then {
                    _result = false;
                } else {                         
                _newwealth = _wealth - _amount;
                _player setVariable["headShots",_newwealth, true];
                _player setVariable ["moneychanged",1,true];    
                _result = true;
                PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
                publicVariableServer "PVDZE_plr_Save";            
                };
                }else{
                _result = true;
                };
                _result
    };

// usage
// _added = [player, 5000] call SC_fnc_addCoins;
// if(_added = true)then{ GREAT SUCCES }else{ IT FAILED, Something went wrong};
	
SC_fnc_addCoins = 
{
	private ["_player","_amount","_wealth","_newwealth", "_result"];			
			_player =  _this select  0;
			_amount =  _this select  1;
			_result = false;	
			_wealth = _player getVariable["headShots",0];
			_player setVariable["headShots",_wealth + _amount, true];
			PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
			publicVariableServer "PVDZE_plr_Save";
			_player setVariable ["moneychanged",1,true];					
			_newwealth = _player getVariable["headShots",0];		
			if (_newwealth >= _wealth) then { _result = true; };			
			_result
};	

2.0 Cashmoney system (Soul):

// usage
// _removed = [player, 5000] call SC_fnc_removeCoins;
// if(_removed = true)then{  GREAT SUCCES  }else{ IT FAILED, not enoguh money};

SC_fnc_removeCoins=
    {
                private ["_player","_amount","_wealth","_newwealth", "_result"];
                _player = _this select 0;
                _amount = _this select 1;
                _result = false;
                _wealth = _player getVariable["cashMoney",0];  
                if(_amount > 0)then{
                if (_wealth < _amount) then {
                    _result = false;
                } else {                         
                _newwealth = _wealth - _amount;
                _player setVariable["cashMoney",_newwealth, true];
                _player setVariable ["moneychanged",1,true];    
                _result = true;
                PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
                publicVariableServer "PVDZE_plr_Save";            
                };
                }else{
                _result = true;
                };
                _result
    };

// usage
// _added = [player, 5000] call SC_fnc_addCoins;
// if(_added = true)then{ GREAT SUCCES }else{ IT FAILED, Something went wrong};
	
SC_fnc_addCoins = 
{
	private ["_player","_amount","_wealth","_newwealth", "_result"];			
			_player =  _this select  0;
			_amount =  _this select  1;
			_result = false;	
			_wealth = _player getVariable["cashMoney",0];
			_player setVariable["cashMoney",_wealth + _amount, true];
			PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
			publicVariableServer "PVDZE_plr_Save";
			_player setVariable ["moneychanged",1,true];					
			_newwealth = _player getVariable["cashMoney",0];		
			if (_newwealth >= _wealth) then { _result = true; };			
			_result
};	
Link to comment
Share on other sites

 

OK guys, i got limited time, i wrote these compile functions that will make adding and removing coins universal and easy: ( So easy to edit scripts where u have to pay quick.)

 

On top of your compiles.sqf (best outside of the isDedi):

 

THIS ISNT TESTED, so would be great if a experience guy can test it first. ( i'm leaving like soon to a festival).

 

THIS IS FOR 999: 1.1 version

// usage
// _removed = [player, 5000] call SC_fnc_removeCoins;
// if(_removed = true)then{  GREAT SUCCES  }else{ IT FAILED, not enoguh money};

SC_fnc_removeCoins=
	{
				private ["_player","_amount","_wealth","_newwealth", "_result"];
				_player =  _this select  0;
				_amount =  _this select  1;
				_result = false;
				_wealth = _player getVariable["headShots",0];		
				if (_wealth <= _amount) then { 
					_result = false;
				} else { 						
				_newwealth = _wealth - _amount;
				_player setVariable["headShots",_newwealth, true];
				_player setVariable ["moneychanged",1,true];	
				_result = true;
				PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
				publicVariableServer "PVDZE_plr_Save";			
				};
				_result
	};

// usage
// _added = [player, 5000] call SC_fnc_addCoins;
// if(_added = true)then{ GREAT SUCCES }else{ IT FAILED, Something went wrong};
	
SC_fnc_addCoins = 
{
	private ["_player","_amount","_wealth","_newwealth", "_result"];			
			_player =  _this select  0;
			_amount =  _this select  1;
			_result = false;	
			_wealth = _player getVariable["headShots",0];
			_player setVariable["headShots",_wealth + _amount, true];
			PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
			publicVariableServer "PVDZE_plr_Save";
			_player setVariable ["moneychanged",1,true];					
			_newwealth = _player getVariable["headShots",0];		
			if (_newwealth >= _wealth) then { _result = true; };			
			_result
};	

Nice one Zupa. Have a good time!

Link to comment
Share on other sites

This is useful, but there's a minor error in it. When trying to SC_fnc_removeCoins it won't remove player's coins when you have the exact amount.

For example when trying to buy something for 2000 and you have exactly 2000, most scripts reply with: You need another 0 coins. Easy fix for that.

 

Find:

if (_wealth <= _amount) then { 

Replace with:

if (_wealth < _amount) then { 

Edit// This is now fixed on the 1st post

Link to comment
Share on other sites

Trying to get the Skin trader script to use this. But i am struggling. (Not my field this.)

 

Currently its looking like this. 

It works if i remove the if(_removed = true) then { line, but it will let you buy skins regardless of how many coins you have.

If i keep the if(_removed = true) then { line, then it wont do anything.

 

Link to original script: 

 

I hope someone can assist me here as im sure there are more people who want to use this with coins. :)

 

if(not local player) exitWith{};
#include "dialog\definitions.sqf"
disableSerialization;
_display = findDisplay SKINS_DIALOG;
_listbox = _display displayCtrl SKINS_UNITLIST;
_sel = lbCurSel _listbox; if(_sel < 0) exitWith{};
_unittype = Men_Clothing select _sel;
_typename = lbtext [sKINS_UNITLIST,_sel];
_hasGPS = false;
_hasCompass = false;
_hasRadio = false;
_hasWatch = false;
_hasMap = false;
 
/********************* Buy Skin ********************/
_cash = 5000;
_removed = [player, _cash] call SC_fnc_removeCoins;
if(_removed = true) then {
_msg = format ["Payed %1 %2. Skin Change incoming!",_cash, DNCurrency];
systemChat ("(DayZNorway.com): "+str _msg+"");
_msg spawn AH_fnc_dynTextMsg;
 
 
if (player hasWeapon "ItemCompass") then {
_hasCompass = true;
};
if (player hasWeapon "ItemRadio") then {
_hasRadio = true;
};
if (player hasWeapon "ItemGPS") then {
_hasGPS = true;
};
if (player hasWeapon "ItemWatch") then {
_hasWatch = true;
};
if (player hasWeapon "ItemMap") then {
_hasMap = true;
};
player playActionNow "Medic";
sleep 7;
CloseDialog 0;
sleep 1;
[dayz_playerUID,dayz_characterID,_unittype] spawn player_humanityMorph;
sleep 0.2;
vehicle player switchCamera 'EXTERNAL';
sleep 3;
if (!_hasCompass) then {
player removeWeapon "ItemCompass";
};
if (!_hasRadio) then {
player removeWeapon "ItemRadio";
};
if (!_hasGPS) then {
player removeWeapon "ItemGPS";
};
if (!_hasWatch) then {
player removeWeapon "ItemWatch";
};
if (!_hasMap) then {
player removeWeapon "ItemMap";
};
}else{
_msg = format ["You need another %1 %2.",_cash, DNCurrency];
systemChat ("(DayZNorway.com): "+str _msg+"");
_msg spawn AH_fnc_dynTextMsg;
};
};
/*******************************************************/

Link to comment
Share on other sites

  • 4 months later...
  • 3 months later...
  • 1 month later...
  • 1 month later...
  • 2 weeks later...

I am using the SC 3.0 on my Overpoch server and am wanting to use SC rearm/refuel by axe cop so I do need this in my ZSC compiles right?

 

How would I put this into my ZSC Compiles? Do I replace what is currently in there or just paste this underneath?

 

 

Current SC_fnc_removeCoins

 

private ["_player","_amount","_wealth","_newwealth", "_result"];
_player = _this select 0;
_amount = _this select 1;
_result = false;
_wealth = _player getVariable["cashMoney",0];  
if(_amount > 0)then{
if (_wealth < _amount) then {
_result = false;
} else {                         
_newwealth = _wealth - _amount;
_player setVariable["cashMoney",_newwealth, true];
_player setVariable ["moneychanged",1,true];    
_result = true;
PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
publicVariableServer "PVDZE_plr_Save";            
};
}else{
_result = true;
};
_result

 

 

 

Current SC_fnc_addCoins

 

private ["_player","_amount","_wealth","_newwealth", "_result"];
_player =  _this select  0;
_amount =  _this select  1;
_result = false;
_wealth = _player getVariable["cashMoney",0];
_player setVariable["cashMoney",_wealth + _amount, true];
PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
publicVariableServer "PVDZE_plr_Save";
_player setVariable ["moneychanged",1,true];
_newwealth = _player getVariable["cashMoney",0];
if (_newwealth >= _wealth) then { _result = true; };
_result

 

Link to comment
Share on other sites

  • 6 months later...
On 12/08/2014 at 11:37 PM, Zupa said:

Universal Develoment functions for script developers, also included in the compiles of the singel currency.

 

Updated 28-08-2014

Always succes when removing 0 coins.

 

999 Headshot system:


// usage
// _removed = [player, 5000] call SC_fnc_removeCoins;
// if(_removed = true)then{  GREAT SUCCES  }else{ IT FAILED, not enoguh money};

SC_fnc_removeCoins=
    {
                private ["_player","_amount","_wealth","_newwealth", "_result"];
                _player = _this select 0;
                _amount = _this select 1;
                _result = false;
                _wealth = _player getVariable["headShots",0];  
                if(_amount > 0)then{
                if (_wealth < _amount) then {
                    _result = false;
                } else {                         
                _newwealth = _wealth - _amount;
                _player setVariable["headShots",_newwealth, true];
                _player setVariable ["moneychanged",1,true];    
                _result = true;
                PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
                publicVariableServer "PVDZE_plr_Save";            
                };
                }else{
                _result = true;
                };
                _result
    };

// usage
// _added = [player, 5000] call SC_fnc_addCoins;
// if(_added = true)then{ GREAT SUCCES }else{ IT FAILED, Something went wrong};
	
SC_fnc_addCoins = 
{
	private ["_player","_amount","_wealth","_newwealth", "_result"];			
			_player =  _this select  0;
			_amount =  _this select  1;
			_result = false;	
			_wealth = _player getVariable["headShots",0];
			_player setVariable["headShots",_wealth + _amount, true];
			PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
			publicVariableServer "PVDZE_plr_Save";
			_player setVariable ["moneychanged",1,true];					
			_newwealth = _player getVariable["headShots",0];		
			if (_newwealth >= _wealth) then { _result = true; };			
			_result
};	

2.0 Cashmoney system (Soul):


// usage
// _removed = [player, 5000] call SC_fnc_removeCoins;
// if(_removed = true)then{  GREAT SUCCES  }else{ IT FAILED, not enoguh money};

SC_fnc_removeCoins=
    {
                private ["_player","_amount","_wealth","_newwealth", "_result"];
                _player = _this select 0;
                _amount = _this select 1;
                _result = false;
                _wealth = _player getVariable["cashMoney",0];  
                if(_amount > 0)then{
                if (_wealth < _amount) then {
                    _result = false;
                } else {                         
                _newwealth = _wealth - _amount;
                _player setVariable["cashMoney",_newwealth, true];
                _player setVariable ["moneychanged",1,true];    
                _result = true;
                PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
                publicVariableServer "PVDZE_plr_Save";            
                };
                }else{
                _result = true;
                };
                _result
    };

// usage
// _added = [player, 5000] call SC_fnc_addCoins;
// if(_added = true)then{ GREAT SUCCES }else{ IT FAILED, Something went wrong};
	
SC_fnc_addCoins = 
{
	private ["_player","_amount","_wealth","_newwealth", "_result"];			
			_player =  _this select  0;
			_amount =  _this select  1;
			_result = false;	
			_wealth = _player getVariable["cashMoney",0];
			_player setVariable["cashMoney",_wealth + _amount, true];
			PVDZE_plr_Save = [_player,(magazines _player),true,true] ;
			publicVariableServer "PVDZE_plr_Save";
			_player setVariable ["moneychanged",1,true];					
			_newwealth = _player getVariable["cashMoney",0];		
			if (_newwealth >= _wealth) then { _result = true; };			
			_result
};	

Ummm so where do you put this code? in compiles.sqf or?

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...