AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   save connections with nvault (https://forums.alliedmods.net/showthread.php?t=133886)

Afro-Ankan 07-29-2010 18:17

save connections with nvault
 
hello, im trying to make a Connect plugin with "save Connections".


ex: Afro-ankan has connected from sweden [connections: 33]

next time i connect to thesame server:

Afro-ankan has connected from sweden [connections: 34]

need some help plz

RedRobster 07-29-2010 18:31

Re: save connections with nvault
 
PHP Code:

#include <amxmodx>
#include <nvault>

new gConnectVault

public plugin_init()
{
    
gConnectVault nvault_open("ConnectVault")
    if(
gConnectVault == INVALID_HANDLE)
        
set_fail_state("nVault failed to open")
}

public 
client_connect(id)
{
    new 
AuthID[34]
    
get_user_authid(idAuthID33)
    
    new 
tempdata[12]
    
nvault_get(gConnectVaultAuthIDtempdata)
    
    new 
connections str_to_num(tempdata)
    
    
connections++
    
    
num_to_str(connectionstempdata11)
    
    
nvault_set(gConnectVaultAuthIDtempdata)


That should save connections using nVault, but it uses SteamID.

Afro-Ankan 07-29-2010 18:39

Re: save connections with nvault
 
thank you. it works :)

Bugsy 07-29-2010 19:31

Re: save connections with nvault
 
When using nvault_get to retrieve a string, you need to pass the string variable along w\ maxlen value. Passing only 3 parameters will make the function think you are trying to retrieve a float byref. In this instance, it would be best to use nvault_get to retrieve an integer (only pass vault handle and key). Also, make sure to close the vault. There is a tutorial in the code snippets\tuts section.

How nvault_get functions based on # params:
2 parameters - function returns integer value
3 parameters - function sets float byref
4 parameters - function sets string byref for maxlen chars

Untested
PHP Code:

#include <amxmodx>
#include <nvault>

new gConnectVault

public plugin_init()
{
    
gConnectVault nvault_open("ConnectVault")
    
    if(
gConnectVault == INVALID_HANDLE)
        
set_fail_state("nVault failed to open")
}

public 
plugin_end()
{
    
nvault_closegConnectVault );
}

public 
client_putinserverid )
{
    static 
szAuthID34 ] , szName33 ] , szTemp] , iConnections;
    
get_user_authidid szAuthID charsmaxszAuthID ) );
    
get_user_nameid szName charsmaxszName ) );

    
iConnections nvault_getgConnectVault szAuthID );
    
    
num_to_str( ++iConnections szTemp charsmaxszTemp ) );
    
nvault_setgConnectVault szAuthID szTemp );

    
client_printprint_chat "* %s has connected and now has %d connections" szName iConnections );



Devil259 07-29-2010 19:45

Re: save connections with nvault
 
Using client_authorized() is not better than client_putinserver() for the SteamID ?

Afro-Ankan 07-29-2010 19:49

Re: save connections with nvault
 
thanks guys

Bugsy 07-29-2010 20:01

Re: save connections with nvault
 
IIRC, authorized its called prior to putinserver but either way works.

Afro-Ankan 07-29-2010 20:09

Re: save connections with nvault
 
should look like this ?

PHP Code:

/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <nvault>
#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Author"
new gConnections[33]
new 
gConnectVault
public plugin_init()
{
 
gConnectVault nvault_open("ConnectVault")
 if(
gConnectVault == INVALID_HANDLE)
  
set_fail_state("nVault failed to open")
}
public 
client_connect(id)
{
 new 
AuthID[34]
 
get_user_authid(idAuthID33)
 
 new 
tempdata[12]
 
nvault_get(gConnectVaultAuthIDtempdata)
 
 new 
connections str_to_num(tempdata)
 
 
connections++
 
gConnections[id] = connections
 
 num_to_str
(connectionstempdata11)
 
 
nvault_set(gConnectVaultAuthIDtempdata)
 
 new 
name[34]
 
get_user_name(idname33)
 
client_print(0print_chat"%s has connected. [%i Connections]"namegConnections[id])



Bugsy 07-29-2010 20:19

Re: save connections with nvault
 
The plugin I posted is better. Do you need each players connection count elsewhere in the plugin? If not then no need for that global array.

Afro-Ankan 07-29-2010 20:23

Re: save connections with nvault
 
ok. thanks


All times are GMT -4. The time now is 00:18.

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