Raised This Month: $23 Target: $400
 5% 

[INC] Bank


Post New Thread Reply   
 
Thread Tools Display Modes
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

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. Take a look :

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
And now for the test plugin :

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         "2.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_testcrash"CMD_TestCrashADMFLAG_CHEATS"Try to crash Bank");
}

public 
Action CMD_TestCrash(int clientint args)
{
    if(
args 1)
    {
        
PrintToChat(client"Usage : sm_testcrash [BANK NAME]");
        return 
Plugin_Handled;
    }
    
    
char bankName[40];
    
GetCmdArg(1bankNamesizeof(bankName));
    
    
Bank_Create(bankName);
    
Bank_EditBalance(bankNameclient100);
    
    
    
int credits Bank_GetBalance(bankNameclient);
       
PrintToChat(client"You have %i credits in bank %s"creditsbankName);

    return 
Plugin_Handled;
}

public 
void Bank_DatabaseReady()
{
    
PrintToServer("********* DB READY *********");
    
Bank_Create("TestBank");
}

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

//Command Callback

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)
    {
        
PrintToChat(client"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)
    {
        
PrintToChat(client"You need to put at least more than 1 unit !");
        return 
Plugin_Handled;    
    }
    
    if(
target != -1)
        
Bank_EditBalance(bankclientammount);
    else
        
PrintToChat(client"Target not found.");
    
    return 
Plugin_Handled;
}

public 
Action CMD_SubCredits(int clientint args)
{
    if(
args 3)
    {
        
PrintToChat(client"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)
    {
        
PrintToChat(client"You need to put at least less than 0 unit !");
        return 
Plugin_Handled;    
    }
    
    if(
target != -1)
        
Bank_EditBalance(bankclientammount);
    else
        
PrintToChat(client"Target not found.");
    
    return 
Plugin_Handled;
}

public 
Action CMD_SetCredits(int clientint args)
{
    if(
args 3)
    {
        
PrintToChat(client"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(
target != -1)
        
Bank_SetBalance(bankclientammount);
    else
        
PrintToChat(client"Target not found.");
    
    return 
Plugin_Handled;

Also, this plugin require only ONE entry in the database.cfg file :
PHP Code:
    "Bank"
    
{
        
"driver"            "default"
        "host"            "YOUR HOST"
        "database"            "YOUR DB NAME"
        "user"            "YOUR HOST USERNAME"
        "pass"            "YOUR HOST PASSWORD"
    

Attached Files
File Type: sp Get Plugin or Get Source (Bank_test.sp - 258 views - 3.6 KB)
File Type: smx Bank_test.smx (6.1 KB, 100 views)
File Type: inc bank.inc (2.2 KB, 12 views)
File Type: sp Get Plugin or Get Source (Bank.sp - 16 views - 11.6 KB)
File Type: smx Bank.smx (8.0 KB, 10 views)
__________________

Last edited by Arkarr; 05-15-2020 at 10:10.
Arkarr is offline
ShawnCZek
Member
Join Date: Mar 2017
Location: Czech Republic
Old 05-31-2017 , 14:40   Re: [INC] Bank
Reply With Quote #2

I have some problems, can you fix them, please?

Code:
L 05/31/2017 - 20:20:04: [SM] Exception reported: Unknown column 'STEAM_ID_STOP_IGNORING_RETVALS' in 'where clause'
L 05/31/2017 - 20:20:04: [SM] Blaming: Bank.smx
L 05/31/2017 - 20:20:04: [SM] Call stack trace:
L 05/31/2017 - 20:20:04: [SM]   [0] SetFailState
L 05/31/2017 - 20:20:04: [SM]   [1] Line 263, Bank.sp::ClientFromBank
L 05/31/2017 - 20:20:04: [SM]   [2] Line 175, Bank.sp::Native_BankGetBalance
L 05/31/2017 - 20:20:04: [SM]   [4] Bank_GetBalance
L 05/31/2017 - 20:20:04: [SM]   [5] Line 38, Shop.sp::OnClientPostAdminCheck
L 05/31/2017 - 20:20:04: [SM]   [7] NotifyPostAdminCheck
L 05/31/2017 - 20:20:04: [SM]   [8] Line 339, /home/builds/sourcemod/linux-1.8/build/plugins/admin-sql-threaded.sp::OnReceiveUser
L 05/31/2017 - 20:23:58: [SM] Exception reported: Invalid database Handle 0 (error: 4)
L 05/31/2017 - 20:23:58: [SM] Blaming: Bank.smx
L 05/31/2017 - 20:23:58: [SM] Call stack trace:
L 05/31/2017 - 20:23:58: [SM]   [0] SQL_Query
L 05/31/2017 - 20:23:58: [SM]   [1] Line 287, Bank.sp::GetBankID
L 05/31/2017 - 20:23:58: [SM]   [2] Line 314, Bank.sp::BankExist
L 05/31/2017 - 20:23:58: [SM]   [3] Line 87, Bank.sp::Native_BankCreate
L 05/31/2017 - 20:23:58: [SM]   [5] Bank_Create
L 05/31/2017 - 20:23:58: [SM]   [6] Line 32, Shop.sp::OnPluginStart
L 05/31/2017 - 20:23:58: [SM] Unable to load plugin "Shop.smx": Error detected in plugin startup (see error logs)
ShawnCZek is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-02-2017 , 12:24   Re: [INC] Bank
Reply With Quote #3

lol, looks like Arkarr needs to stop ignoring the steamid returning "STEAM_ID_STOP_IGNORING_RETVALS"
__________________
Mitchell is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-02-2017 , 14:28   Re: [INC] Bank
Reply With Quote #4

Quote:
Originally Posted by Mitchell View Post
lol, looks like Arkarr needs to stop ignoring the steamid returning "STEAM_ID_STOP_IGNORING_RETVALS"
Nope. It's not my fault.

@ShawnCZek
You need to pass a valid steamID in the function Native_BankGetBalance() ! You are trying to pass "STEAM_ID_STOP_IGNORING_RETVALS" wich create this error.
__________________

Last edited by Arkarr; 06-02-2017 at 14:33.
Arkarr is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-02-2017 , 14:56   Re: [INC] Bank
Reply With Quote #5

Quote:
Originally Posted by Arkarr View Post
Nope. It's not my fault.

@ShawnCZek
You need to pass a valid steamID in the function Native_BankGetBalance() ! You are trying to pass "STEAM_ID_STOP_IGNORING_RETVALS" wich create this error.
Actually you could have gotten a completely different type of error if your query was quoted.
#define QUERY_SELECT_CLIENT_BANK "SELECT * FROM `clients` WHERE steamid=%s AND bankID=%i"
should be
#define QUERY_SELECT_CLIENT_BANK "SELECT * FROM `clients` WHERE steamid='%s' AND bankID=%i"
__________________
Mitchell is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 06-02-2017 , 15:48   Re: [INC] Bank
Reply With Quote #6

Quote:
Originally Posted by Mitchell View Post
Actually you could have gotten a completely different type of error if your query was quoted.
#define QUERY_SELECT_CLIENT_BANK "SELECT * FROM `clients` WHERE steamid=%s AND bankID=%i"
should be
#define QUERY_SELECT_CLIENT_BANK "SELECT * FROM `clients` WHERE steamid='%s' AND bankID=%i"
My mistake. Thanks.
__________________
Arkarr is offline
ShawnCZek
Member
Join Date: Mar 2017
Location: Czech Republic
Old 06-03-2017 , 10:43   Re: [INC] Bank
Reply With Quote #7

Nice, now it's working. Thank you very much.

Last edited by ShawnCZek; 06-22-2017 at 10:17.
ShawnCZek is offline
ShawnCZek
Member
Join Date: Mar 2017
Location: Czech Republic
Old 07-28-2017 , 09:26   Re: [INC] Bank
Reply With Quote #8

Last time I had again some problems with this plugin and they are linked to your plugin.
Many users use my plugin which uses your plugin. But sometimes the plugin run down because of memory leak. Here are the errors.
Quote:
L 07/28/2017 - 15:17:42: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "Bank.smx")
L 07/28/2017 - 15:17:42: [SM] Unloading plugin to free 15263 handles.
L 07/28/2017 - 15:17:42: [SM] Contact the author(s) of this plugin to correct this error.
L 07/28/2017 - 15:17:42: --------------------------------------------------------------------------
L 07/28/2017 - 15:17:42: Type IDatabase | Count 1
L 07/28/2017 - 15:17:42: Type Trie | Count 15262
L 07/28/2017 - 15:17:42: -- Approximately 5311176 bytes of memory are in use by (15263) Handles.
Thanks in advance for help.
ShawnCZek is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-05-2018 , 06:46   Re: [INC] Bank
Reply With Quote #9

Amount*
eyal282 is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 01-05-2018 , 09:50   Re: [INC] Bank
Reply With Quote #10

Quote:
Originally Posted by eyal282 View Post
Amount*
That thing has to be pushed into trash.
__________________
Arkarr is offline
Reply


Thread Tools
Display Modes

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 07:58.


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