AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [INC] Bank (https://forums.alliedmods.net/showthread.php?t=294511)

Arkarr 02-28-2017 16:21

[INC] Bank
 
11 Attachment(s)
[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

ShawnCZek 05-31-2017 14:40

Re: [INC] Bank
 
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)


Mitchell 06-02-2017 12:24

Re: [INC] Bank
 
lol, looks like Arkarr needs to stop ignoring the steamid returning "STEAM_ID_STOP_IGNORING_RETVALS"

Arkarr 06-02-2017 14:28

Re: [INC] Bank
 
Quote:

Originally Posted by Mitchell (Post 2525489)
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.

Mitchell 06-02-2017 14:56

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2525523)
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"

Arkarr 06-02-2017 15:48

Re: [INC] Bank
 
Quote:

Originally Posted by Mitchell (Post 2525529)
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.

ShawnCZek 06-03-2017 10:43

Re: [INC] Bank
 
Nice, now it's working. Thank you very much. :)

ShawnCZek 07-28-2017 09:26

Re: [INC] Bank
 
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.

eyal282 01-05-2018 06:46

Re: [INC] Bank
 
Amount*

Arkarr 01-05-2018 09:50

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2569883)
Amount*

That thing has to be pushed into trash.

eyal282 01-05-2018 09:54

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2569917)
That thing has to be pushed into trash.

Fix it

Arkarr 01-05-2018 13:25

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2569920)
Fix it

I don't feel like. Also, that's rude.

eyal282 01-15-2018 04:11

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2569963)
I don't feel like. Also, that's rude.

Someone doesn't like criticism... ( only this post is rude, last isn't )

Arkarr 01-15-2018 04:32

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2572070)
Someone doesn't like criticism... ( only this post is rude, last isn't )

That was not really a critic, at least, not a constructive one. I felt it was like "do it".
I might have misunderstood, but honestly, I have not interest on working on that thing right now.

iGANGNAM 03-17-2018 05:14

Re: [INC] Bank
 
Quote:

Originally Posted by ShawnCZek (Post 2538308)
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.

Thanks in advance for help.

Have you found fix for this?

Arkarr 03-17-2018 18:47

Re: [INC] Bank
 
Quote:

Originally Posted by iGANGNAM (Post 2583346)
Have you found fix for this?

I never tried to fix it to be perfectly honest.
I'll fix it later tomorrow

ShawnCZek 03-19-2018 14:21

Re: [INC] Bank
 
Quote:

Originally Posted by iGANGNAM (Post 2583346)
Have you found fix for this?

Yes, I have fixed it. I just added a few delete commands into the source and it works perfectly.

shanapu 03-19-2018 14:47

Re: [INC] Bank
 
Quote:

Originally Posted by ShawnCZek (Post 2583671)
Yes, I have fixed it. I just added a few delete commands into the source and it works perfectly.

Nice,... how about you share your fix with the community?

ShawnCZek 03-19-2018 15:12

Re: [INC] Bank
 
Quote:

Originally Posted by shanapu (Post 2583675)
Nice,... how about you share your fix with the community?

When I am able to do it, I wiil do it. But at the moment I have not access to my edited file.

Arkarr 03-20-2018 03:50

Re: [INC] Bank
 
Oh.. thank you ! I'll still fix mine and see what I did wrong.

ShawnCZek 03-20-2018 10:48

Re: [INC] Bank
 
1 Attachment(s)
So I fixed some stuff and I also added function Bank_SetBalanceSteam what is useful if you want to optimize your plugin. And I did it. :)
The new function is described below (adding include soubor only as code).
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

/**
 * 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 bool Bank_EditBalance(const char[] bankint clientint ammountbool forcecreate true)

/**
 * 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 bool Bank_SetBalance(const char[] bankint clientint ammountbool forcecreate true)

/**
 * Set the balance of a client in a specific bank.
 *
 * @param bank             The name of the bank
 * @param steamID        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 bool Bank_SetBalanceSteam(const char[] bank, const char[] steamIDint ammountbool forcecreate true

To fix the error I just added a few simple deletes. And it worked perfectly. The problem is the program was storing data about user over and over again and the plugin had to be shut down.

Arkarr 03-20-2018 15:01

Re: [INC] Bank
 
I'll add it to the OP, good job.

ShawnCZek 03-21-2018 12:21

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2583876)
I'll add it to the OP, good job.

Thank you. And as I wrote - the new function is useful for optimizing. For example I store data about an user when he connects and I edit his credits only in my plugin. And for storing them for the next time I use the database when he disconnects. :)

KoKoDoDo 04-06-2018 12:33

Re: [INC] Bank
 
someone can give me example of what i need to do to Activate this with DB?

eyal282 04-06-2018 14:42

Re: [INC] Bank
 
L 04/06/2018 - 18:15:03: [SM] Exception reported: Invalid database Handle 0 (error: 4)
L 04/06/2018 - 18:15:03: [SM] Blaming: Bank.smx
L 04/06/2018 - 18:15:03: [SM] Call stack trace:
L 04/06/2018 - 18:15:03: [SM] [0] SQL_Query
L 04/06/2018 - 18:15:03: [SM] [1] Line 321, C:\Users\Arkarr\AppData\Roaming\spedit\source pawn\scripts\Bank.sp::GetBankID
L 04/06/2018 - 18:15:03: [SM] [2] Line 348, C:\Users\Arkarr\AppData\Roaming\spedit\source pawn\scripts\Bank.sp::BankExist
L 04/06/2018 - 18:15:03: [SM] [3] Line 88, C:\Users\Arkarr\AppData\Roaming\spedit\source pawn\scripts\Bank.sp::Native_BankCreate
L 04/06/2018 - 18:15:03: [SM] [5] Bank_Create


What to do?

Arkarr 04-06-2018 15:54

Re: [INC] Bank
 
Quote:

Originally Posted by KoKoDoDo (Post 2586382)
someone can give me example of what i need to do to Activate this with DB?

I don't understand your question.
Quote:

Originally Posted by eyal282 (Post 2586418)
L 04/06/2018 - 18:15:03: [SM] Exception reported: Invalid database Handle 0 (error: 4)
L 04/06/2018 - 18:15:03: [SM] Blaming: Bank.smx
L 04/06/2018 - 18:15:03: [SM] Call stack trace:
L 04/06/2018 - 18:15:03: [SM] [0] SQL_Query
L 04/06/2018 - 18:15:03: [SM] [1] Line 321, C:\Users\Arkarr\AppData\Roaming\spedit\source pawn\scripts\Bank.sp::GetBankID
L 04/06/2018 - 18:15:03: [SM] [2] Line 348, C:\Users\Arkarr\AppData\Roaming\spedit\source pawn\scripts\Bank.sp::BankExist
L 04/06/2018 - 18:15:03: [SM] [3] Line 88, C:\Users\Arkarr\AppData\Roaming\spedit\source pawn\scripts\Bank.sp::Native_BankCreate
L 04/06/2018 - 18:15:03: [SM] [5] Bank_Create


What to do?

Fix CVAR so plugin can connect to database.

eyal282 04-06-2018 15:58

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2586431)
I don't understand your question.
Fix CVAR so plugin can connect to database.

What cvar? I don't see any convars in your plugin.

Arkarr 04-06-2018 16:26

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2586432)
What cvar? I don't see any convars in your plugin.

My bad, it's in databae.cfg that you have to insert those infos.

eyal282 04-06-2018 16:39

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2586436)
My bad, it's in databae.cfg that you have to insert those infos.

I've inserted all the data and correctly.

Code:

        "Bank"
            {
                        "driver"            "default"
                        "host"            "127.0.0.1"
                        "database"  "almog_bank"
                "user"  "almog_bank"
                "pass"  "CENSORED"
          }

If I put the wrong password, I get the access denied error obviously so it might prove the issue is not with connecting, anything I missed?

Arkarr 04-07-2018 11:33

Re: [INC] Bank
 
Fixed, I believe.

eyal282 04-07-2018 12:22

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2586559)
Fixed, I believe.

Plugin didn't work after I used changelevel and crash looped it when I tried _restart until I removed Bank.smx ( I didn't compile, I took your )

Arkarr 04-08-2018 04:43

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2586561)
Plugin didn't work after I used changelevel and crash looped it when I tried _restart until I removed Bank.smx ( I didn't compile, I took your )

Herm... What ? I'll take a look at it.

eyal282 04-08-2018 05:45

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2586655)
Herm... What ? I'll take a look at it.

It means that the plugin will crash the server every time it gets up, resulting in a crash loop where no player can even enter the server, bad writing of me.

Arkarr 04-08-2018 07:36

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2586657)
It means that the plugin will crash the server every time it gets up, resulting in a crash loop where no player can even enter the server, bad writing of me.

Try again. I think I fixed it.

eyal282 04-08-2018 09:46

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2586668)
Try again. I think I fixed it.

Still crashing. Maybe it's worth to mention the server is CS:GO?

Arkarr 04-08-2018 09:49

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2586686)
Still crashing. Maybe it's worth to mention the server is CS:GO?

This shouldn't be a problem. Don't you have any logs ? Also, I can't test right now. Maybe tonight.

eyal282 04-08-2018 10:20

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2586688)
This shouldn't be a problem. Don't you have any logs ? Also, I can't test right now. Maybe tonight.

Accelerator or error logs?

For now:

L 04/08/2018 - 14:25:35: [SM] Exception reported: Tried to work with banks but database is not connected yet ! Try again in a few seconds !
L 04/08/2018 - 14:25:35: [SM] Blaming: Bank.smx
L 04/08/2018 - 14:25:35: [SM] Call stack trace:
L 04/08/2018 - 14:25:35: [SM] [0] SetFailState
L 04/08/2018 - 14:25:35: [SM] [1] Line 94, C:\Users\Nicolas\Desktop\Bank.sp::CheckConnec tion
L 04/08/2018 - 14:25:35: [SM] [2] Line 101, C:\Users\Nicolas\Desktop\Bank.sp::Native_Bank Create
L 04/08/2018 - 14:25:35: [SM] [4] Bank_Create

Accelerator is broken, error is something about version rather just let you use the error logs or wait until your night.

Arkarr 04-08-2018 12:54

Re: [INC] Bank
 
Quote:

Originally Posted by eyal282 (Post 2586698)
Accelerator or error logs?

For now:

L 04/08/2018 - 14:25:35: [SM] Exception reported: Tried to work with banks but database is not connected yet ! Try again in a few seconds !
L 04/08/2018 - 14:25:35: [SM] Blaming: Bank.smx
L 04/08/2018 - 14:25:35: [SM] Call stack trace:
L 04/08/2018 - 14:25:35: [SM] [0] SetFailState
L 04/08/2018 - 14:25:35: [SM] [1] Line 94, C:\Users\Nicolas\Desktop\Bank.sp::CheckConnec tion
L 04/08/2018 - 14:25:35: [SM] [2] Line 101, C:\Users\Nicolas\Desktop\Bank.sp::Native_Bank Create
L 04/08/2018 - 14:25:35: [SM] [4] Bank_Create

Accelerator is broken, error is something about version rather just let you use the error logs or wait until your night.

Oh. So it works.
That's what I thought. Another plugin is using Bank, but it doesn't check if the database is yet connected or not ! So, it crash. You want to fix your other plugin. Mine is fine.

eyal282 04-08-2018 13:37

Re: [INC] Bank
 
Quote:

Originally Posted by Arkarr (Post 2586740)
Oh. So it works.
That's what I thought. Another plugin is using Bank, but it doesn't check if the database is yet connected or not ! So, it crash. You want to fix your other plugin. Mine is fine.

How do I check if the database is connected or not? Can you create a nativefor that in the include?

Should I use the forward you removed "Bank_DatabaseReady" and treat it as "OnPluginStart"?

Just tell me if I'm doing it right.

Bank.sp:

Code:


#include <sourcemod>
#include <sdktools>
#include <bank>

#pragma newdecls required

//Plugin Info
#define PLUGIN_TAG                        "[Bank]"
#define PLUGIN_NAME                        "[ANY] Bank"
#define PLUGIN_AUTHOR                "Arkarr"
#define PLUGIN_VERSION                "1.0"
#define PLUGIN_DESCRIPTION        "A simple bank system where you can store money."
//Database
#define QUERY_INIT_DB_TCLIENTS                "CREATE TABLE IF NOT EXISTS `clients` (`clientID` int NOT NULL AUTO_INCREMENT, `steamid` varchar(45) NOT NULL, `credits` int NOT NULL, `bankID` int NOT NULL, PRIMARY KEY (`clientID`))"
#define QUERY_INIT_DB_TBANKS                "CREATE TABLE IF NOT EXISTS `banks` (`bankID` int NOT NULL AUTO_INCREMENT,  `name` varchar(50) NOT NULL, PRIMARY KEY (`bankID`))"
#define QUERY_CREATE_BANK                        "INSERT INTO `banks` (name) VALUES ('%s')"
#define QUERY_SELECT_BANKS                        "SELECT * FROM `banks`"
#define QUERY_SELECT_CLIENT_BANK        "SELECT * FROM `clients` WHERE steamid='%s' AND bankID=%i"
#define QUERY_ADD_CLIENT_TO_BANK        "INSERT INTO `clients` (steamid, credits, bankID) VALUES ('%s', '0', %i)"
#define QUERY_UPDATE_CLIENT_CREDITS        "UPDATE `clients` SET credits='%i' WHERE steamid='%s' AND bankID=%i"

Handle DATABASE_Banks;
//Handle FORWARD_DatabaseReady;

public Plugin myinfo =
{
        name = PLUGIN_NAME,
        author = PLUGIN_AUTHOR,
        description = PLUGIN_DESCRIPTION,
        version = PLUGIN_VERSION,
        url = "http://www.sourcemod.net"
};

 
public void OnPluginStart()
{
  //FORWARD_DatabaseReady = CreateGlobalForward("Bank_DatabaseReady", ET_Event)
}

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)

          CreateNative("Bank_Create", Native_BankCreate);
        CreateNative("Bank_GetBalance", Native_BankGetBalance);
        CreateNative("Bank_SetBalance", Native_BankSetBalance);
        CreateNative("Bank_SetBalanceSteam", Native_BankSetBalanceSteam);
        CreateNative("Bank_EditBalance", Native_BankEditBalance);
       
        RegPluginLibrary("Bank");
 
        SQL_TConnect(DBConResult, "Bank");
 
        return APLRes_Success;
}

//Database init

public void DBConResult(Handle owner, Handle hndl, const char[] error, any data)
{
        if (hndl == INVALID_HANDLE)
        {
                SetFailState(error);
        }
        else
        {
                DATABASE_Banks = hndl;
               
                char buffer[300];
                if (!SQL_FastQuery(DATABASE_Banks, QUERY_INIT_DB_TCLIENTS) || !SQL_FastQuery(DATABASE_Banks, QUERY_INIT_DB_TBANKS))
                {
                        SQL_GetError(DATABASE_Banks, buffer, sizeof(buffer));
                        SetFailState(buffer);
                }
                /*else
                {
                        Call_StartForward(FORWARD_DatabaseReady);
                  }*/
        }
}

//Natives

public int Native_BankCreate(Handle plugin, int numParams)
{
        char buffer[300];
        char strBankName[128];
        GetNativeString(1, strBankName, sizeof(strBankName));
               
        if(BankExist(strBankName))
        {
                Format(buffer, sizeof(buffer), "Bank %s already exist !", strBankName);
                PrintErrorMessage(buffer);
               
                return false;
        }
       
        Format(buffer, sizeof(buffer), QUERY_CREATE_BANK, strBankName);
        if (!SQL_FastQuery(DATABASE_Banks, buffer))
        {
                SQL_GetError(DATABASE_Banks, buffer, sizeof(buffer));
                PrintErrorMessage(buffer);
               
                return false;
        }
       
        return true;
}

public int Native_BankEditBalance(Handle plugin, int numParams)
{
        char steamID[50];
        char buffer[200];
        char strBankName[128];
       
        GetNativeString(1, strBankName, sizeof(strBankName));
        int client = GetNativeCell(2);
        int ammount = GetNativeCell(3);
        bool create = GetNativeCell(4);
       
        int bankID = GetBankID(strBankName)
        if(bankID == -1)
        {
                Format(buffer, sizeof(buffer), "Bank %s doesn't exist !", strBankName);
                PrintErrorMessage(buffer);
                return false;
        }
       
        GetClientAuthId(client, AuthId_SteamID64, steamID, sizeof(steamID));
        Handle TRIE_Client = ClientFromBank(client, strBankName);
       
        int clientID;
        GetTrieValue(TRIE_Client, "ID", clientID);
        if(clientID == -1 || clientID == 0)
        {
                if(!create)
                {
                        Format(buffer, sizeof(buffer), "User not in bank %s !", strBankName);
                        PrintErrorMessage(buffer);
                        return false;
                }
                else
                {
                        Format(buffer, sizeof(buffer), QUERY_ADD_CLIENT_TO_BANK, steamID, bankID);
                        if (!SQL_FastQuery(DATABASE_Banks, buffer))
                        {
                                SQL_GetError(DATABASE_Banks, buffer, sizeof(buffer));
                                PrintErrorMessage(buffer);
                               
                                return false;
                        }
                }
        }
       
        int credits;
        GetTrieValue(TRIE_Client, "credits", credits);
        credits += ammount;
        delete TRIE_Client;
       
        Format(buffer, sizeof(buffer), QUERY_UPDATE_CLIENT_CREDITS, credits, steamID, bankID);
        if (!SQL_FastQuery(DATABASE_Banks, buffer))
        {
                SQL_GetError(DATABASE_Banks, buffer, sizeof(buffer));
                PrintErrorMessage(buffer);
               
                return false;
        }
       
        return true;
}

public int Native_BankGetBalance(Handle plugin, int numParams)
{
        char strBankName[128];
       
        GetNativeString(1, strBankName, sizeof(strBankName));
        int client = GetNativeCell(2);
       
        Handle clientInfos = ClientFromBank(client, strBankName);
       
        if(clientInfos == INVALID_HANDLE)
        {
                return -1;
        }
        else
        {
                int credits;
                GetTrieValue(clientInfos, "credits", credits);
                delete clientInfos;
                return credits;
        }
}

public int Native_BankSetBalance(Handle plugin, int numParams)
{
        char steamID[50];
        char buffer[200];
        char strBankName[128];
       
        GetNativeString(1, strBankName, sizeof(strBankName));
        int client = GetNativeCell(2);
        int ammount = GetNativeCell(3);
        bool create = GetNativeCell(4);
       
        int bankID = GetBankID(strBankName)
        if(bankID == -1)
        {
                Format(buffer, sizeof(buffer), "Bank %s doesn't exist !", strBankName);
                PrintErrorMessage(buffer);
                return false;
        }
       
        GetClientAuthId(client, AuthId_SteamID64, steamID, sizeof(steamID));
        Handle TRIE_Client = ClientFromBank(client, strBankName);
       
        int clientID;
        GetTrieValue(TRIE_Client, "ID", clientID);
        delete TRIE_Client;
        if(clientID == -1 || clientID == 0)
        {
                if(!create)
                {
                        Format(buffer, sizeof(buffer), "User not in bank %s !", strBankName);
                        PrintErrorMessage(buffer);
                        return false;
                }
                else
                {
                        Format(buffer, sizeof(buffer), QUERY_ADD_CLIENT_TO_BANK, steamID, bankID);
                        if (!SQL_FastQuery(DATABASE_Banks, buffer))
                        {
                                SQL_GetError(DATABASE_Banks, buffer, sizeof(buffer));
                                PrintErrorMessage(buffer);
                               
                                return false;
                        }
                }
        }
       
        Format(buffer, sizeof(buffer), QUERY_UPDATE_CLIENT_CREDITS, ammount, steamID, bankID);
        if (!SQL_FastQuery(DATABASE_Banks, buffer))
        {
                SQL_GetError(DATABASE_Banks, buffer, sizeof(buffer));
                PrintErrorMessage(buffer);
               
                return false;
        }
       
        return true;
}

public int Native_BankSetBalanceSteam(Handle plugin, int numParams)
{
        char steamID[50];
        char buffer[200];
        char strBankName[128];
       
        GetNativeString(1, strBankName, sizeof(strBankName));
        GetNativeString(2, steamID, sizeof(steamID));
        int ammount = GetNativeCell(3);
       
        int bankID = GetBankID(strBankName)
        if(bankID == -1)
        {
                Format(buffer, sizeof(buffer), "Bank %s doesn't exist !", strBankName);
                PrintErrorMessage(buffer);
                return false;
        }
       
        Format(buffer, sizeof(buffer), QUERY_UPDATE_CLIENT_CREDITS, ammount, steamID, bankID);
        if (!SQL_FastQuery(DATABASE_Banks, buffer))
        {
                SQL_GetError(DATABASE_Banks, buffer, sizeof(buffer));
                PrintErrorMessage(buffer);
               
                return false;
        }
       
        return true;
}

//Helper function

stock Handle ClientFromBank(int client, const char[] strBankName)
{
        char dbquery[100];
        char steamID[50];
       
        Handle TRIE_Client = CreateTrie();
       
        GetClientAuthId(client, AuthId_SteamID64, steamID, sizeof(steamID));
        Format(dbquery, sizeof(dbquery), QUERY_SELECT_CLIENT_BANK, steamID, GetBankID(strBankName));

        DBResultSet query = SQL_Query(DATABASE_Banks, dbquery);
        if (query == null)
        {
                char error[255];
                SQL_GetError(DATABASE_Banks, error, sizeof(error));
                SetFailState(error);
               
                return INVALID_HANDLE;
        }
        else
        {
                SetTrieValue(TRIE_Client, "credits", -1);
                while (SQL_FetchRow(query))
                {
                        SetTrieValue(TRIE_Client, "ID", SQL_FetchInt(query, 0));
                        SetTrieString(TRIE_Client, "steamid", steamID);
                        SetTrieValue(TRIE_Client, "credits", SQL_FetchInt(query, 2), true);
                        SetTrieValue(TRIE_Client, "bankID", SQL_FetchInt(query, 3));
                }
               
                delete query;
        }
       
        return TRIE_Client;
}

stock int GetBankID(const char[] strBankName)
{
        int bankID = -1;
        DBResultSet query = SQL_Query(DATABASE_Banks, QUERY_SELECT_BANKS);
        if (query == null)
        {
                char error[255];
                SQL_GetError(DATABASE_Banks, error, sizeof(error));
                SetFailState(error);
               
                return false;
        }
        else
        {
                char bankName[45];
                while (SQL_FetchRow(query))
                {
                        SQL_FetchString(query, 1, bankName, sizeof(bankName));
                        if(StrEqual(strBankName, bankName))
                                bankID = SQL_FetchInt(query, 0);
                }
               
                delete query;
        }
       
        return bankID;
}

stock bool BankExist(const char[] strBankName)
{
        return GetBankID(strBankName) > 0 ? true : false;
}

stock void PrintErrorMessage(const char[] msg)
{
        PrintToServer("%s - ERROR - %s", PLUGIN_TAG, msg);
}

The plugin:

Code:


#include <sourcemod>
#include <sdkhooks>

///////////////////////////////////////////////////////////
////////////////////////NATIVES////////////////////////////
///////////////////////////////////////////////////////////

/*
    Include file for Bank.sp
    Provide simple functions to manage a player's bank.
   
    Created by Arkarr (Alliedmodders) EDITED/FIXED BY ShawnCZek
*/

/**
 * 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 bool Bank_EditBalance(const char[] bank, int client, int ammount, bool forcecreate = true)

/**
 * 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 bool Bank_SetBalance(const char[] bank, int client, int ammount, bool forcecreate = true)

/**
 * Set the balance of a client in a specific bank.
 *
 * @param bank            The name of the bank
 * @param steamID        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 bool Bank_SetBalanceSteam(const char[] bank, const char[] steamID, int ammount, bool forcecreate = true)

native bool Bank_IsConnected();

///////////////////////////////////////////////////////////
////////////////////////END NATIVES////////////////////////
///////////////////////////////////////////////////////////

public Plugin:myinfo = {
        name = "Credits",
        author = "Eyal282 ( FuckTheSchool )",
        description = "Credits",
        version = "1.0",
        url = "https://forums.alliedmods.net/showthread.php?t=304043"
};

new bool:Hooked[MAXPLAYERS+1];

new const String:cBankName[] = "Credits";
new const String:hpBankName[] = "Health";
new const String:regenBankName[] = "Regen";
new const String:damageBankName[] = "Damage";

new HealthMaxLevel = 10;
new RegenMaxLevel = 10;
new DamageMaxLevel = 10;

new HealthPerLevel = 10;
new RegenPerLevel = 2;
new Float:DamagePerLevel = 1.1;

new HealthCost = 500;
new RegenCost = 500;
new DamageCost = 500;


new Handle:hcv_CreditsKill = INVALID_HANDLE;
new Handle:hcv_CreditsHS = INVALID_HANDLE;

new Handle:hRegenTimer[MAXPLAYERS+1] = INVALID_HANDLE;
public Bank_DatabaseReady()
{
        Bank_Create("Credits");
        RegConsoleCmd("sm_credits", Command_Credits);
        HookEvent("player_death", Event_PlayerDeath);
        HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
       
        hcv_CreditsKill = CreateConVar("surf_credits_kill", "1", "Amount of credits you get per kill");
        hcv_CreditsHS = CreateConVar("surf_credits_hs", "2", "Amount of credits you get per headshot kill");
       
        RegConsoleCmd("sm_shop", Command_Shop);
        RegAdminCmd("sm_getcredits", Command_LOL, ADMFLAG_ROOT);
       
        PrintToChatAll("Bank database is ready, skills are available and killing will now give credits");
}

public OnMapStart()
{
        for(new i=0;i < MAXPLAYERS+1;i++)
        {
                hRegenTimer[i] = INVALID_HANDLE;
        }
}

public Action:Event_PlayerSpawn(Handle:hEvent, String:Name[], bool:dontBroadcast)
{
        new UserId = GetEventInt(hEvent, "userid");
        new client = GetClientOfUserId(UserId);
       
        if(!IsValidPlayer(client))
                return;
       
        if(hRegenTimer[client] != INVALID_HANDLE)
        {
                CloseHandle(hRegenTimer[client]);
                hRegenTimer[client] = INVALID_HANDLE;
        }
        hRegenTimer[client] = CreateTimer(5.0, Regenerate, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}


public OnClientConnected(client)
{
        Hooked[client] = false;
}
public OnClientPostAdminCheck(client)
{
        if(IsClientInGame(client) && !IsFakeClient(client))
        {
                SDKHook(client, SDKHook_OnTakeDamage, Event_Hurt);
                Hooked[client] = true;
        }
}

public OnClientDisconnect(client)
{
        if(Hooked[client])
                SDKUnhook(client, SDKHook_OnTakeDamage, Event_Hurt);
}

public Action:Event_Hurt(victim, &attacker, &inflictor, &Float:damage, &damagetype, &weapon, Float:damageForce[3], Float:damagePosition[3], damagecustom)
{
        if(victim > MaxClients || victim < 1)
                return Plugin_Continue;
               
        else if(attacker > MaxClients || attacker < 1)
                return Plugin_Continue;
               
        else if(damage == 0.0)
                return Plugin_Continue;
       
        damage *= Pow(DamagePerLevel, float(GetClientDamageSkill(attacker)));
        return Plugin_Changed;
}
public Action:Regenerate(Handle:hTimer, client)
{
        if(!IsValidPlayer(client))
        {
                hRegenTimer[client] = INVALID_HANDLE;
                return Plugin_Stop;
        }
       
        new CurHealth = GetEntProp(client, Prop_Send, "m_iHealth");
        new HealthToAdd = (HealthPerLevel * GetClientRegenSkill(client));
        new HPSkill = GetClientHPSkill(client);
        new TotalHealth;
       
        if(CurHealth + HealthToAdd >= 100 + ( HealthPerLevel * HPSkill ))
                TotalHealth = ( HealthPerLevel * HPSkill );
       
        else
                TotalHealth = CurHealth + HealthToAdd;
        SetEntityHealth(client, TotalHealth);
        return Plugin_Continue;
}       
public Action:Command_LOL(client, args)
{
        AddClientCredits(client, 100);
        return Plugin_Handled;
}

public Action:Command_Shop(client, args)
{
        new String:TempFormat[200];
        new Handle:hMenu = CreateMenu(Shop_MenuHandler);
       
        new HPSkill = GetClientHPSkill(client);
        new RegenSkill = GetClientRegenSkill(client);
        new DamageSkill = GetClientDamageSkill(client);
        Format(TempFormat, sizeof(TempFormat), "Health: [%i/%i] [%i HP] [%ic]", HPSkill, HealthMaxLevel, HPSkill * HealthPerLevel, HPSkill * HealthCost);
        AddMenuItem(hMenu, "", TempFormat);
       
        Format(TempFormat, sizeof(TempFormat), "HP Regen: [%i/%i] [%i/5sec] [%ic]", RegenSkill, RegenMaxLevel, RegenSkill * RegenPerLevel, RegenSkill * RegenCost);
        AddMenuItem(hMenu, "", TempFormat);
       
        Format(TempFormat, sizeof(TempFormat), "Damage: [%i/%i] [%.2fx] [%ic]", DamageSkill, DamageMaxLevel, DamageSkill * DamagePerLevel, DamageSkill * DamageCost);
        AddMenuItem(hMenu, "", TempFormat);
       
        SetMenuTitle(hMenu, "Choose your power:");
        DisplayMenu(hMenu, client, MENU_TIME_FOREVER);
       
        return Plugin_Handled;
}

public Shop_MenuHandler(Handle:hMenu, MenuAction:action, client, item)
{
        if(action == MenuAction_End)
                CloseHandle(hMenu);
       
        else if(action == MenuAction_Select)
        {
                switch(item)
                {
                        case 0:
                        {
                                new HPSkill = GetClientHPSkill(client);
                                new cost = HPSkill * HealthCost;
                                new credits = GetClientCredits(client);
                               
                                if(HPSkill == HealthMaxLevel)
                                {
                                        PrintToChat(client, "\x04Error:\x01 You reached the\x03 max level\x01 for this skill!");
                                }
                                else if(credits < cost)
                                {
                                        PrintToChat(client, "\x04Error:\x01 You need\x03 %i\x01 more credits to buy this skill!", cost - credits);
                                }
                                AddClientHPSkill(client, 1);
                                AddClientCredits(client, (-1 * cost));
                        }
                        case 1:
                        {
                                new RegenSkill = GetClientRegenSkill(client);
                                new cost = RegenSkill * RegenCost;
                                new credits = GetClientCredits(client);
                               
                                if(RegenSkill == RegenMaxLevel)
                                {
                                        PrintToChat(client, "\x04Error:\x01 You reached the\x03 max level\x01 for this skill!");
                                }
                                else if(credits < cost)
                                {
                                        PrintToChat(client, "\x04Error:\x01 You need\x03 %i\x01 more credits to buy this skill!", cost - credits);
                                }
                                AddClientRegenSkill(client, 1);
                                AddClientCredits(client, (-1 * cost));
                        }
                        case 2:
                        {
                                new DamageSkill = GetClientDamageSkill(client);
                                new cost = DamageSkill * DamageCost;
                                new credits = GetClientCredits(client);
                               
                                if(DamageSkill == DamageMaxLevel)
                                {
                                        PrintToChat(client, "\x04Error:\x01 You reached the\x03 max level\x01 for this skill!");
                                }
                                else if(credits < cost)
                                {
                                        PrintToChat(client, "\x04Error:\x01 You need\x03 %i\x01 more credits to buy this skill!", cost - credits);
                                }
                                AddClientDamageSkill(client, 1);
                                AddClientCredits(client, (-1 * cost));
                        }
                }
        }       
       
        hMenu = INVALID_HANDLE;
}

public Action:Event_PlayerDeath(Handle:hEvent, String:Name[], bool:dontBroadcast)
{
        new victim = GetClientOfUserId(GetEventInt(hEvent, "userid"));
       
        if(!IsValidPlayer(victim))
                return;
       
        new attacker = GetClientOfUserId(GetEventInt(hEvent, "attacker"));
       
        new bool:headshot = GetEventBool(hEvent, "headshot");
       
        if(headshot)
                AddClientCredits(attacker, GetConVarInt(hcv_CreditsHS));
               
        else
                AddClientCredits(attacker, GetConVarInt(hcv_CreditsKill));
       
       
}

public Action:Command_Credits(client, args)
{
        PrintToChat(client, "\x01You have\x03 %i\x01 credits.", GetClientCredits(client));
        return Plugin_Handled;
}

stock AddClientCredits(client, amount)
{
        Bank_EditBalance(cBankName, client, amount);
}

stock SetClientCredits(client, amount)
{
        Bank_SetBalance(cBankName, client, amount);
}

stock GetClientCredits(client)
{
        new amount = Bank_GetBalance(cBankName, client);
       
        if(amount == -1)
                amount = 0;
       
        return amount;
}

stock GetClientHPSkill(client)
{
        new amount = Bank_GetBalance(hpBankName, client);
       
        if(amount == -1)
                amount = 0;
       
        return amount;
}

stock AddClientHPSkill(client, amount)
{
        Bank_EditBalance(hpBankName, client, amount);
}

stock GetClientRegenSkill(client)
{
        new amount = Bank_GetBalance(regenBankName, client);
       
        if(amount == -1)
                amount = 0;
       
        return amount;
}

stock AddClientRegenSkill(client, amount)
{
        Bank_EditBalance(regenBankName, client, amount);
}

stock GetClientDamageSkill(client)
{
        new amount = Bank_GetBalance(damageBankName, client);
       
        if(amount == -1)
                amount = 0;
       
        return amount;
}

stock AddClientDamageSkill(client, amount)
{
        Bank_EditBalance(damageBankName, client, amount);
}


stock bool:IsValidPlayer(client)
{
        if(client <= 0)
                return false;
               
        else if(client > MaxClients)
                return false;
               
        return IsClientInGame(client);
}


Arkarr 04-08-2018 14:40

Re: [INC] Bank
 
I added something, now when the database is ready, this code will fire :
PHP Code:

public void Bank_DatabaseReady()
{
    
//Database connected and ready
        //Do your stuff that require bank after this has been fired.




All times are GMT -4. The time now is 14:57.

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