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

Help Me with Auto-Creating Bank Account


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Copper
Senior Member
Join Date: Feb 2012
Location: California
Old 06-07-2016 , 03:24   Help Me with Auto-Creating Bank Account
Reply With Quote #1

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
}
Copper is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-07-2016 , 03:30   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #2

Just call that function in client_putinserver()
__________________

Last edited by Napoleon_be; 06-07-2016 at 03:30.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Copper
Senior Member
Join Date: Feb 2012
Location: California
Old 06-07-2016 , 03:44   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
Just call that function in client_putinserver()
how excactly?, I am kinda new to this.
Copper is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-07-2016 , 03:45   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #4

PHP Code:
public client_putinserver(id) {
    
bank_create(id)

something like this.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Copper
Senior Member
Join Date: Feb 2012
Location: California
Old 06-07-2016 , 03:48   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #5

Quote:
Originally Posted by Napoleon_be View Post
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?
Copper is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-07-2016 , 03:51   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #6

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.

__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Copper
Senior Member
Join Date: Feb 2012
Location: California
Old 06-07-2016 , 03:54   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #7

Quote:
Originally Posted by Napoleon_be View Post
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.
Copper is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-07-2016 , 03:59   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #8

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.

__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Copper
Senior Member
Join Date: Feb 2012
Location: California
Old 06-07-2016 , 04:02   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #9

by any chance, can there be two public client_putinserver(id)? its because i found a client_putinserver(id) somewhere in the plugin already.
Attached Files
File Type: sma Get Plugin or Get Source (amx_bank.sma - 435 views - 24.3 KB)

Last edited by Copper; 06-07-2016 at 04:31.
Copper is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-07-2016 , 13:54   Re: Help Me with Auto-Creating Bank Account
Reply With Quote #10

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.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Reply



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 02:51.


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