Raised This Month: $51 Target: $400
 12% 

[INC] Bank


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 02-28-2017 , 16:21   [INC] Bank
Reply With Quote #1

[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[] bankint clientint 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[] bankint 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[] bankint clientint 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_AddCreditsADMFLAG_CHEATS"Add a specific ammount of credits to an accounts");
    
RegAdminCmd("sm_subcredit"CMD_SubCreditsADMFLAG_CHEATS"Substract a specific ammount of credits to an accounts");
    
RegAdminCmd("sm_setcredit"CMD_SetCreditsADMFLAG_CHEATS"Set a specific ammount of credits to an accounts");
    
RegAdminCmd("sm_createbank"CMD_CreateBankADMFLAG_CHEATS"Create a new bank");
    
    
Bank_Create("TestBank");
}

public 
void OnClientPostAdminCheck(int client)
{
    
Bank_EditBalance("TestBank"client10);
}

//Command Callback

public Action CMD_CreateBank(int clientint 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(1banksizeof(bank));
    
    
Bank_Create(bank);
    
    return 
Plugin_Handled;
}

public 
Action CMD_ShowBalance(int clientint args)
{
    if(
args 1)
    {
        
PrintToChat(client"Usage : sm_balance [BANK NAME]");
        return 
Plugin_Handled;
    }
    
    
char bank[40];
    
GetCmdArg(1banksizeof(bank));
    
    
int credits Bank_GetBalance(bankclient);
    
    if(
credits == -1)
        
PrintToChat(client"You are not registred in the bank %s"bank);
    else
        
PrintToChat(client"You have %i credits in bank %s"creditsbank);
    
    return 
Plugin_Handled;
}

public 
Action CMD_AddCredits(int clientint 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(1banksizeof(bank));
    
GetCmdArg(2strTargetsizeof(strTarget));
    
GetCmdArg(3strAmmountsizeof(strAmmount));
    
    
int target FindTarget(clientstrTarget);
    
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(banktargetammount);
    }
    else
    {
        if(
client != 0)
            
PrintToChat(client"Target not found.");
        else
            
PrintToServer("Target not found.");
    }    
    

    return 
Plugin_Handled;
}

public 
Action CMD_SubCredits(int clientint 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(1banksizeof(bank));
    
GetCmdArg(2strTargetsizeof(strTarget));
    
GetCmdArg(3strAmmountsizeof(strAmmount));
    
    
int target FindTarget(clientstrTarget);
    
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(banktargetammount);
    }
    else
    {
        if(
client != 0)
            
PrintToChat(client"Target not found.");
        else
            
PrintToServer("Target not found.");
    }
    
    return 
Plugin_Handled;
}

public 
Action CMD_SetCredits(int clientint 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(1banksizeof(bank));
    
GetCmdArg(2strTargetsizeof(strTarget));
    
GetCmdArg(3strAmmountsizeof(strAmmount));
    
    
int target FindTarget(clientstrTarget);
    
int ammount StringToInt(strAmmount);
    
    
    if(
target != -1)
    {
        
Bank_SetBalance(banktargetammount);
    }
    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
__________________
Want to check my plugins ?

Last edited by Arkarr; 11-16-2020 at 07:52.
Arkarr is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode