AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help Me with Auto-Creating Bank Account (https://forums.alliedmods.net/showthread.php?t=283624)

Copper 06-07-2016 03:24

Help Me with Auto-Creating Bank Account
 
Hello Alliedmodders,

I am currently trying to edit this so that a bank account gets created as soon as a new player joins the server. At the moment, a player needs to type bank_create in order for a bank account to get created but sometimes new players don't know about the bank system so I could use some help with this.

Thank You

Code:

public bank_create(id)
{
        new client = 0
        if(read_argc() > 1)
                client = 1
        if(!check_use(id,client)) return PLUGIN_HANDLED
        new curmoney,neededmoney, amount
        neededmoney = get_cvar_num("bank_default_opening")
        curmoney = cs_get_user_money(id)
        if(curmoney >= neededmoney)
        {
                amount = neededmoney
                curmoney -= neededmoney
        }
        else
        {
                amount = curmoney
                curmoney = 0
        }
        #if SQLON
                new sid[35]
                if(get_cvar_num("bank_use_ip"))
                        get_user_ip(id,sid,34,1)
                else
                        get_user_authid(id,sid,34)
                result = dbi_query(dbc,"SELECT * FROM bank WHERE sid = '%s'",sid)
                if(result != RESULT_NONE)
                {
                        if(client)
                                client_print(id,print_chat,"You already have a bank account!")
                        else
                                console_print(id,"You already have a bank account!")
                        return PLUGIN_HANDLED
                }
                dbi_free_result(result)
                result = dbi_query(dbc,"INSERT INTO bank VALUES ( '%s' , '%d')",sid,amount)
                dbi_free_result(result)
        #else
                new sid[35],key[51]
                if(get_cvar_num("bank_use_ip"))
                        get_user_ip(id,sid,34,1)
                else
                        get_user_authid(id,sid,34)
                format(key,50,"%s_account",sid)
                if(vaultdata_exists(key))
                {
                        if(client)
                                client_print(id,print_chat,"You already have a bank account!")
                        else
                                console_print(id,"You already have a bank account!")
                        return PLUGIN_HANDLED
                }
                new saveamstr[21]
                num_to_str(amount,saveamstr,20)
                set_vaultdata(key,saveamstr)
        #endif                       
        cs_set_user_money(id,curmoney)
        if(client)
                client_print(id,print_chat,"Bank account created successfully. Your account has $%d in it.",amount)
        else
                console_print(id,"Bank account created successfully. Your account has $%d in it.",amount)
        return PLUGIN_HANDLED
}


Napoleon_be 06-07-2016 03:30

Re: Help Me with Auto-Creating Bank Account
 
Just call that function in client_putinserver()

Copper 06-07-2016 03:44

Re: Help Me with Auto-Creating Bank Account
 
Quote:

Originally Posted by Napoleon_be (Post 2425430)
Just call that function in client_putinserver()

how excactly?, I am kinda new to this.

Napoleon_be 06-07-2016 03:45

Re: Help Me with Auto-Creating Bank Account
 
PHP Code:

public client_putinserver(id) {
    
bank_create(id)


something like this.

Copper 06-07-2016 03:48

Re: Help Me with Auto-Creating Bank Account
 
Quote:

Originally Posted by Napoleon_be (Post 2425433)
PHP Code:

public client_putinserver(id) {
    
bank_create(id)


something like this.

just by adding client_putinserver(id), it will auto create a bank account for a new player?

Napoleon_be 06-07-2016 03:51

Re: Help Me with Auto-Creating Bank Account
 
client_putinserver catches when a player actually got into the server after connecting.

client_connect(id) is called first, but this doesn't mean that the player already got into the server cause he can get an error, got the chance to click "cancel", etc. etc...

anything put into this function, will be called as soon as the player gets into the server.
PHP Code:

public client_putinserver(id) {
    
client_print(0print_chat"A player has connected to the server"// This will print out to all the players that a player has connected.



Copper 06-07-2016 03:54

Re: Help Me with Auto-Creating Bank Account
 
Quote:

Originally Posted by Napoleon_be (Post 2425437)
client_putinserver catches when a player actually got into the server after connecting.

client_connect(id) is called first, but this doesn't mean that the player already got into the server cause he can get an error, got the chance to click "cancel", etc. etc...

anything put into this function, will be called as soon as the player gets into the server.
PHP Code:

public client_putinserver(id) {
    
client_print(0print_chat"A player has connected to the server"// This will print out to all the players that a player has connected.



okay now i see, thank you so much.

Napoleon_be 06-07-2016 03:59

Re: Help Me with Auto-Creating Bank Account
 
Just some more info that could be usefull for you.

PHP Code:

public client_putinserver(id) {
    
bank_create(id// Create a new bank for the player that has connected to the server.
    
client_print(idprint_chat"A bank is being created for you"// Will print out to the player that has connected that a bank is being created for him.



Copper 06-07-2016 04:02

Re: Help Me with Auto-Creating Bank Account
 
1 Attachment(s)
by any chance, can there be two public client_putinserver(id)? its because i found a client_putinserver(id) somewhere in the plugin already.

Napoleon_be 06-07-2016 13:54

Re: Help Me with Auto-Creating Bank Account
 
Yes it is possible that the function is already declared in your code. what you can do is simply call the "bank_create(id)" function in your client_putinserver(id) function. something like this:

PHP Code:

public client_putinserver(id)
{
    
bank_create(id// Added this into your code
    
interest[id] = 0
    canuse
[id] = false
    
switch(get_cvar_num("bank_restrict"))
    {
        case 
0:
        {
            
canuse[id] = true
        
}
        case 
1:
        {
            if(
access(id,ADMIN_CHAT))
                
canuse[id] = true
            
else
                
canuse[id] = false
        
}
        case 
2:
        {
            
canuse[id] = false
            
new sid[35]
            if(
get_cvar_num("bank_use_ip"))
                
get_user_ip(id,sid,34,1)
            else
                
get_user_authid(id,sid,34)
            
#if SQLON    
                
result dbi_query(dbc,"SELECT * FROM bankusers WHERE sid = '%s'",sid)
                if(
result == RESULT_NONE)
                    
canuse[id] = false
                
else
                    
canuse[id] = true
                dbi_free_result
(result)
            
#else
                
new retstr[35],a,i
                
while(read_file(allowfilepath,i,retstr,34,a))
                {
                    if(
equali(sid,retstr))
                        
canuse[id] = true
                    i
++
                }
            
#endif
        
}
    }


Just keep in mind that you can't declare 2 or more functions with the same name, all the names have to be unique and only declared once.


All times are GMT -4. The time now is 23:35.

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