Raised This Month: $ Target: $400
 0% 

Hooking the first connection of a player


Post New Thread Reply   
 
Thread Tools Display Modes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-31-2010 , 16:08   Re: Hooking the first connection of a player
Reply With Quote #11

It would be better to delay the messages with about 5 seconds.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-03-2011 , 12:05   Re: Hooking the first connection of a player
Reply With Quote #12

Quote:
Originally Posted by ConnorMcLeod View Post
You don't need to format the nvault key, steamid is enough if the vault is unique.
Done + print_chat changed to set_task. Still shows weird + the server crashes at the first mapchange the plugin is running, then I can't start the server at all.
bibu is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-03-2011 , 12:28   Re: Hooking the first connection of a player
Reply With Quote #13

If you can't start server, it's because you save an empty vault key.

Like : nvaut_set( vault, "" , szvalue )

Add something to steamid prevent this error but is the a real solution.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-03-2011 , 13:32   Re: Hooking the first connection of a player
Reply With Quote #14

Quote:
prevent this error but is the a real solution.
what?

PHP Code:
#include <amxmodx>
#include <nvault>

new g_Vault;               //Global var to hold our vault handle
new g_szAuthID[33][35];    //Global array to store auth ids of players
new g_pExpireDays;         //CVar pointer for expiredays cvar

public plugin_cfg()
{
    
//Open our vault and have g_Vault store the handle.
    
g_Vault nvault_open"first_connection" );

    
//Make the plugin error if vault did not successfully open
    
if ( g_Vault == INVALID_HANDLE )
        
set_fail_state"Error opening nVault!" );

    
//This will remove all entries in the vault that are 5+ (or cvar+) days old at server-start
    //or map-change
    
nvault_pruneg_Vault get_systime() - ( 86400 get_pcvar_numg_pExpireDays ) ) );
}

public 
plugin_end()
{
    
//Close the vault when the plugin ends (map change\server shutdown\restart)
    
nvault_closeg_Vault );
}

public 
client_authorized(id)
{
    if(
is_user_bot(id))
    {
        return 
PLUGIN_HANDLED
    
}
    
//Get the connecting users authid and store it in our global string array so it
    //will not need to be retrieved every time we want to do an nvault transaction.
    
get_user_authidid g_szAuthID[id] , charsmaxg_szAuthID[] ) );
    
    return 
PLUGIN_CONTINUE
}

public 
client_putinserver(id)
{
    if(
is_user_bot(id))
    {
        return 
PLUGIN_HANDLED
    
}
    new 
szKey[40];
    
//formatex( szKey , charsmax( szKey ) , "%sCONNECT" , g_szAuthID[id] );
    
    
new iConnect nvault_getg_Vault szKey );
    
    if ( 
iConnect )
    {
        
set_task5.0"much"id );
    }
    else
    {
        
set_task5.0"first"id );
    }
    return 
PLUGIN_CONTINUE
}

public 
much(id)
{
    if(
is_user_connected(id))
    {
        
client_printid print_chat "[First Connect] This is your more times to connecting to our server. =)" );
    }
}

public 
first(id)
{
    if(
is_user_connected(id))
    {
        new 
szKey[40];
        
        
client_printid print_chat "[First Connect] This is your first time to connecting to our server. =)" );
        
nvault_setg_Vault szKey "1" );
    }
}

public 
first_connection(id)
{
    new 
szKey[40];
    
//formatex( szKey , charsmax( szKey ) , "%sCONNECT" , g_szAuthID[id] );
    
    
new iConnect nvault_getg_Vault szKey );
    
    if ( 
iConnect )
    {
        
client_printid print_chat "[First Connect] This is your more times to connecting to our server. =)" );
    }
    else
    {
        
client_printid print_chat "[First Connect] This is your first time to connecting to our server. =)" );
    }

bibu is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-03-2011 , 13:45   Re: Hooking the first connection of a player
Reply With Quote #15

Code:
public first(id) {     if(is_user_connected(id))     {         new szKey[40];                 client_print( id , print_chat , "[First Connect] This is your first time to connecting to our server. =)" );         nvault_set( g_Vault , szKey , "1" );     } }

You are writing an empty key, it's like :
Code:
       nvault_set( g_Vault , "" , "1" );

That's why you can't start your server then.


You can use those functions if you want :
PHP Code:
SetUserFirstConnectionPassedid )
{
    
CheckVaultOpen()
    new 
szSteamId[32]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    
nvault_setg_VaultszSteamId"1" )
}

IsUserFirstConnectionid )
{
    
CheckVaultOpen()
    new 
szSteamId[32]
    
get_user_authid(idszSteamIdcharsmax(szSteamId))
    return !
nvault_getg_VaultszSteamId )
}

CheckVaultOpen()
{
    if( !
g_Vault )
    {
        
g_Vault nvault_open("first_connection")
    }
}

CloseVault()
{
    
nvault_close(g_Vault)
    
g_Vault 0

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 01-03-2011 at 13:52.
ConnorMcLeod is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-04-2011 , 15:20   Re: Hooking the first connection of a player
Reply With Quote #16

Thanks for this connor, it works great now, is this a good way to set it at disconnect, cause the whole time if they're on the server, the key should be still 0.

PHP Code:
public client_disconnectid )
{
    if(!
g_isbotid ])
    {
        if (
is_user_first_connect[id])
        {
            
SetUserFirstConnectionPassedid )
        }
        
is_user_first_connect[id] = false
    
}
    
    
g_isconnectedid ] = false
    g_isbot
id ] = false

bibu is offline
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 01:59.


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