Jump to content

[RE-RELEASE, v1.2] 'fn_SC_uniCoins' dev function for Single Currency (rewritten and updated for Epoch 1.0.6.1+)


iben

Recommended Posts

Hello guys,

because I was couple times asked for updated and unified dev function for single currency (originally posted in ZSC thread),
I've decided release it here so you can have all info in one place.
So here it is with specific example (with detailed comments) you can try for fun...

===

First thing first - let's start with giving credits for these great guys:

===

This function was reworked and updated for Epoch 1.0.6.1+

===

Changelog:

  • [2017-05-08], v1.0 | Initial release, published at Epoch forum
  • [2017-05-28], v1.1 | Added: debug (parameters check, exec time to analyze code performace in game)
  • [2017-05-31], v1.2 | Improved: removed unnecessary checks during player sync

===

Read "Goodbye". Wish you the best guys!

===

How it looks like:

Check source code (Github)

===

FEATURES:

  • Function is able to manage money processing with single line code (see bellow) and can be easily integrated into your code
  • You can use debug option to check your fnc parameters + exec time (code performance) showed on screen (global chat):
    just uncoment line: '#define: __ DEBUG__' is src code;
  • It's pretty fast but remember: use it only if you're developing some addon or you know exactly what to do.
    Otherwise, you can stil use common methods used by addons authors - mostly it's even faster their way, because of scoped approach;
  • It's a function - you can easily maintain your "money" code...

===

How to install:

It's actually very easy: practical example is the best way to explain, what needs to be done - see repo structure and files.

Source files are available at Github repo (specific usage example included!). You can download them from here.

===

How to use it:

= General usage:

// [_player,_amount,_action,_target] call fnc_SC_uniCoins;
// '_player' : object : player, _killer...etc
// '_amount' : number : 1000
// '_action' : string : 'add'   / 'remove'
// '_target' : string : 'cache' / 'bank'
// ==========================================================
// @example 01: Remove 5.000 Coins from player's wallet:
[player,5000,'remove','cache'] call fnc_SC_uniCoins;

// @example 02: Add 1.000 Coins to player's wallet:
[player,1000,'add','cache'] call fnc_SC_uniCoins;

// @example 03: Remove 7.000 Coins from player's bank account:
[player,7000,'remove','bank'] call fnc_SC_uniCoins;

// @example 04: Add 15.000 Coins to player's bank account:
[player,15000,'add','bank'] call fnc_SC_uniCoins;

===

...easy enough, isn't it?

===

Specific usage (with detailed description):

// === Scenario:

// Award player for killing local zombies.
// If player kills zombie, he will receive random amount of money from 0 to 250 Coins for kill.
// Let's make it interesting - player receive money only in case he used the gun defined by you:

// === What to do:

// Save file "local_eventKill.sqf" to your custom compiles folder, load it in your custom compiles file
// outside (!isDedicated) and (isServer) - we need this file for both client and server.
// (it's in 'dayz_code' folder: you can download file from:
// https://github.com/EpochModTeam/DayZ-Epoch/blob/master/SQF/dayz_code/compile/local_eventKill.sqf)

// Open your custom variables file (or add bellow code to your init.sqf file) and add:
playerZedKillAward = true; // ... so you can quickly turn ON/OFF your script

// Now, let's create some code in 'local_eventKill.sqf' file:


if (local _zed) then {
private["_killer","_fnc_uniCoinsTest","_allowedWps"];

  // code

  // ...find last line of code:
  _killer setVariable["humanity",_humanity,true];
  // Bellow we define local function "_fnc_killZedsAward" so we can call it easily:

  // ===

  _fnc_killZedsAward = {
    private ["_action","_target","_money","_curWep"];

    _action = _this select 0; // @info: we take parameter from call in main code bellow this fnc and assign value to local var
    _target = _this select 1; // @info: we take parameter from call in main code bellow this fnc and assign value to local var
    _money = (round(random 5) * 50); // @info: now from 0 to 250 Coins, define to your liking
    _curWep = getText (configFile >> 'CfgWeapons' >> currentWeapon _killer >> 'displayName'); // @info: What's the name of player current weapon? We need this for info in hint or dayz_rollingMessages

    call {
      // Player has 20% chance to get 0 coins from random (if you will use round(random 5) - meaning staying with 5, scale from 0 to 4)
      // So let's check it first and prevent display msg on screen in such a case
      if (_money == 0) exitWith {
      //@info: You can pick 'dayz_rollingMessages' and comment 'hintSilent' if your hint layer is occupied by your debug monitor
      ["Sorry, our bank is low on money!"] call dayz_rollingMessages;
      hintSilent "Sorry, our bank is low on money!";
      };
      // If random money are above zero, let's call dev fnc_SC_uniCoins.
      // First parameter '_killer' is defined by original code; _money param was defined above,
      // _action and _target parameters we defined in main code bellow...
      if ([_killer,_money,_action,_target] call fnc_SC_uniCoins) exitWith {
      //@info: You can pick 'dayz_rollingMessages' and comment 'hintSilent' if your hint layer is occupied by your debug monitor
        hintSilent format ["Zed kill award!\nweapon: [%1]\nReceived: [%2 %3]",_curWep,_money,CurrencyName];
        [format["Zed kill award! Weapon: [%1] Received: [%2 %3]",_curWep,_money,CurrencyName]] call dayz_rollingMessages;
      };
      // Do not put any default code for call here - if you do, you will trigger code action in cases,
      // like zombie is killed close to you by some accident (from experience)
    };
  };

// Now let's create main procedure:
  if (playerZedKillAward) then {
  // @info: define your custom array of weapons here:
    _allowedWps = [ 
      'M110_NVG_EP1',
      'M9_SD_DZ','DMR_DZ',
      'M9_DZ'
    ];
    if ((currentWeapon _killer) in _allowedWps) exitWith {
       // @info: if player used allowed weapon, tell '_fnc_killZedsAward', what to do with money.
       // You can be creative here :))
      ["add","cache"] call _fnc_killZedsAward;
    };
  };

};

// === Done!

===

...that's all, you can use it wherever money are... Have Fun!!
Cheers...

===

Link to comment
Share on other sites

1 minute ago, juandayz said:

@iben why the hell i need a function....to add coins?.hahah @DAmNRelentless @Anhor lets finish here that we start in dblood mod.. hsha joke. Nice iben. And the examples are separates mods lol.

:tongue: Thx buddy... as I said in your thread... let's keep the mod (Epoch) alive and thx to all lifekeepers... you deserves a huge THX for you dedication to mod... thx

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...