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)

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.


All times are GMT -4. The time now is 19:08.

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