SA-MP Forums Archive
[Include] sampfw: currency.inc - Player Currencies - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] sampfw: currency.inc - Player Currencies (/showthread.php?tid=638842)



sampfw - currency.inc | Player Currencies - nG Inverse - 06.08.2017

Player Currency Library


About
This library is part of the San Andreas Multiplayer Framework (sampfw) and allows players to use different currencies in-game. More explanation on the framework coming...

Install
Define any settings (see below) then include the files:
pawn Код:
#include <sampfw\extra\util>
#include <sampfw\account\account>
#include <sampfw\server\currency>
Note that util.inc must always be the first file included in the framework.

Settings
SAMPFW_DEFAULT_CURRENCY
The default currency used by the server

SAMPFW_DBTABLE_CURRENCY
The database table to store currency rates in

SAMPFW_CURRENCY_UPDATE_TIME
The amount of days to pass before updating currency rates

Functions
pawn Код:
sampfw::SetPlayerCurrency(playerid, const currency[])
// Sets a player's currency
pawn Код:
sampfw::GetPlayerCurrency(playerid)
// Returns a player's currency
pawn Код:
sampfw::GetCurrencyName(id)
// Returns a currency's name
pawn Код:
sampfw::GetCurrencyID(const name[])
// Returns a currency's ID
pawn Код:
sampfw::GetConversion(from, to, Float: amount)
// Returns the 'amount' from currency 'from' to currency 'to'
Callbacks
pawn Код:
public OnPlayerCurrencyChange(playerid)
// Called when a player's currency is changed
Example
pawn Код:
#define SAMPFW_DEFAULT_CURRENCY "USD" // Set the server default currency to USD
#define SAMPFW_CURRENCY_UPDATE_TIME 30 // Update currencies in the DB every server restart over 30 days

YCMD:givemoney(playerid, params[], help)
{
    new
        target,
        Float: amount;

    if(sscanf(params, "ui", target, amount))
        return SendClientMessage(playerid, COLOR_USAGE, "Usage: /givemoney <id> <amount>");
   
    GivePlayerMoney(playerid, floatround(-amount));

    amount = sampfw::GetConversion(
        sampfw::GetPlayerCurrency(playerid),
        sampfw::GetPlayerCurrency(targetid),
        amount
    );

    GivePlayerMoney(target, floatround(amount));
    return 1;
}
Dependencies (Currently)
This is a part of San Andreas Multiplayer Framework, and requires all of its dependencies. Check the GitHub for a list (docs/dependencies.txt).


GitHub
https://github.com/bwhitmire55/sampfw


Re: sampfw: currency.inc - Player Currencies - OneDay - 08.08.2017

Why not:

nG Inverse's SA:MP FrameWork

= NSFW!!!!1