[INC] Bank
Sooo... I was a bit annoyed when I had to create a bank/point/money system each time I wanted to create a money system or just storing points (well, anything that can be counted). And also 'cause I wanted to try the inc and native stuff wich I never did before.
Basically, you just create banks where you can store points for each player. Simple stuff, really.
Surprisingly, it gained a bit of audience and therefore, I made it work a little bit better. Sadly, I don't have a huge test-data collection, so I can only estimate and do so much with optimisation. If anyone is kind enough to report issue, I'll force myself to fix them as soon as possible.
Include file (for scripters) :
Most up-to-date version can be found on github, here :
https://github.com/Arkarr/SM-Bank/bl...clude/bank.inc
PHP Code:
/*
Include file for Bank.sp
Provide simple functions to manage a player's bank.
Created by Arkarr (Alliedmodders)
*/
#if defined _bank_included
#endinput
#endif
#define _bank_included
/*********************************************************
* Called when the banks are ready to be manipulated
*
* @NoReturn
*********************************************************/
forward void Bank_DatabaseReady();
/*********************************************************
* Called when a freshly created bank as been created.
*
* @param bankName The name of the bank. I don't provide bank ID here to prevent plugin from grabbing the wrong ID.
*
* @NoReturn
*********************************************************/
forward void Bank_Created(const char[] bankName);
/**
* Create a new bank. Can't create bank with same name at once.
*
* @param bankName The name of the bank
* @return True on sucess, false otherwise.
*/
native bool Bank_Create(const char[] bankName)
/**
* Add or substract a certain ammount of credits of a player's balance.
*
* @param bank The name of the bank
* @param client The client to add/substract to.
* @param ammount The ammount to add/substract.
* @param forcecreate Create the user if not found in the bank.
* @return True on sucess, false otherwise.
*/
native void Bank_EditBalance(const char[] bank, int client, int ammount)
/**
* Get the balance of a client in a specific bank.
*
* @param bank The name of the bank
* @param client The client to get the balance of.
* @return The ammount of credits. -1 if no account found.
*/
native int Bank_GetBalance(const char[] bank, int client)
/**
* Set the balance of a client in a specific bank.
*
* @param bank The name of the bank
* @param client The client to set the balance of.
* @param ammount The ammount to set the balance of the player. That wasn't english.
* @param forcecreate Create the user if not found in the bank.
* @return True on sucess, false otherwise.
*/
native void Bank_SetBalance(const char[] bank, int client, int ammount)
In order to test the functionally of the plugin, you can use the test plugin I wrote, it doesn't do much.
Simply allows you to create a bank with the command
sm_createbank and manipulate credits using sm_addcredits, sm_subcredit and sm_setcreddit
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <bank>
//Plugin Info
#define PLUGIN_TAG "[Bank]"
#define PLUGIN_NAME "Bank - test plugin"
#define PLUGIN_AUTHOR "Arkarr"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_DESCRIPTION "A simple plugin to test the bank plugin."
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = "http://www.sourcemod.net"
};
public void OnPluginStart()
{
RegConsoleCmd("sm_balance", CMD_ShowBalance, "Display your current ammount of credits in a specific bank");
RegAdminCmd("sm_addcredit", CMD_AddCredits, ADMFLAG_CHEATS, "Add a specific ammount of credits to an accounts");
RegAdminCmd("sm_subcredit", CMD_SubCredits, ADMFLAG_CHEATS, "Substract a specific ammount of credits to an accounts");
RegAdminCmd("sm_setcredit", CMD_SetCredits, ADMFLAG_CHEATS, "Set a specific ammount of credits to an accounts");
RegAdminCmd("sm_createbank", CMD_CreateBank, ADMFLAG_CHEATS, "Create a new bank");
Bank_Create("TestBank");
}
public void OnClientPostAdminCheck(int client)
{
Bank_EditBalance("TestBank", client, 10);
}
//Command Callback
public Action CMD_CreateBank(int client, int args)
{
if(args < 1)
{
if(client != 0)
PrintToChat(client, "Usage : sm_balance [BANK NAME]");
else
PrintToServer("Usage : sm_balance [BANK NAME]");
return Plugin_Handled;
}
char bank[40];
GetCmdArg(1, bank, sizeof(bank));
Bank_Create(bank);
return Plugin_Handled;
}
public Action CMD_ShowBalance(int client, int args)
{
if(args < 1)
{
PrintToChat(client, "Usage : sm_balance [BANK NAME]");
return Plugin_Handled;
}
char bank[40];
GetCmdArg(1, bank, sizeof(bank));
int credits = Bank_GetBalance(bank, client);
if(credits == -1)
PrintToChat(client, "You are not registred in the bank %s", bank);
else
PrintToChat(client, "You have %i credits in bank %s", credits, bank);
return Plugin_Handled;
}
public Action CMD_AddCredits(int client, int args)
{
if(args < 3)
{
if(client != 0)
PrintToChat(client, "Usage : sm_balance [BANK NAME] [TARGET] [AMMOUNT]");
else
PrintToServer("Usage : sm_balance [BANK NAME] [TARGET] [AMMOUNT]");
return Plugin_Handled;
}
char bank[40];
char strTarget[40];
char strAmmount[40];
GetCmdArg(1, bank, sizeof(bank));
GetCmdArg(2, strTarget, sizeof(strTarget));
GetCmdArg(3, strAmmount, sizeof(strAmmount));
int target = FindTarget(client, strTarget);
int ammount = StringToInt(strAmmount);
if(ammount < 1)
{
if(client != 0)
PrintToChat(client, "You need to put at least more than 1 unit !");
else
PrintToServer("You need to put at least more than 1 unit !");
return Plugin_Handled;
}
if(target != -1)
{
Bank_EditBalance(bank, target, ammount);
}
else
{
if(client != 0)
PrintToChat(client, "Target not found.");
else
PrintToServer("Target not found.");
}
return Plugin_Handled;
}
public Action CMD_SubCredits(int client, int args)
{
if(args < 3)
{
if(client != 0)
PrintToChat(client, "Usage : sm_balance [BANK NAME] [TARGET] [AMMOUNT]");
else
PrintToServer("Usage : sm_balance [BANK NAME] [TARGET] [AMMOUNT]");
return Plugin_Handled;
}
char bank[40];
char strTarget[40];
char strAmmount[40];
GetCmdArg(1, bank, sizeof(bank));
GetCmdArg(2, strTarget, sizeof(strTarget));
GetCmdArg(3, strAmmount, sizeof(strAmmount));
int target = FindTarget(client, strTarget);
int ammount = StringToInt(strAmmount);
if(ammount > 0)
{
if(client != 0)
PrintToChat(client, "You need to put at least less than 0 unit !");
else
PrintToServer("You need to put at least less than 0 unit !");
return Plugin_Handled;
}
if(target != -1)
{
Bank_EditBalance(bank, target, ammount);
}
else
{
if(client != 0)
PrintToChat(client, "Target not found.");
else
PrintToServer("Target not found.");
}
return Plugin_Handled;
}
public Action CMD_SetCredits(int client, int args)
{
if(args < 3)
{
if(client != 0)
PrintToChat(client, "Usage : sm_setcredit [BANK NAME] [TARGET] [AMMOUNT]");
else
PrintToServer("Usage : sm_setcredit [BANK NAME] [TARGET] [AMMOUNT]");
return Plugin_Handled;
}
char bank[40];
char strTarget[40];
char strAmmount[40];
GetCmdArg(1, bank, sizeof(bank));
GetCmdArg(2, strTarget, sizeof(strTarget));
GetCmdArg(3, strAmmount, sizeof(strAmmount));
int target = FindTarget(client, strTarget);
int ammount = StringToInt(strAmmount);
if(target != -1)
{
Bank_SetBalance(bank, target, ammount);
}
else
{
if(client != 0)
PrintToChat(client, "Target not found.");
else
PrintToServer("Target not found.");
}
return Plugin_Handled;
}
Installation
In order to make the plugin work, simply drag and drop the smx in the plugins folder of sourcemod and configure database.cfg like this :
PHP Code:
"Bank"
{
"driver" "default"
"host" "YOUR HOST"
"database" "YOUR DB NAME"
"user" "YOUR HOST USERNAME"
"pass" "YOUR HOST PASSWORD"
}
And you are good to go !
All files can be found on Github here :
https://github.com/Arkarr/SM-Bank
__________________