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

Country stats


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ajvn
Member
Join Date: Dec 2007
Old 02-22-2008 , 04:33   Country stats
Reply With Quote #1

Greetings. Is it hard to make plugin where it can show all dead and spectators top 5 visitors for each country in right bottom corner via HUD every 60 sec, something like this:

Visitors: Count:
1. Denmark 1024
2. Serbia 768
3. French 512
4. Macedonia 400
5. Other 312

Thanks in advance.
ajvn is offline
Strikerr
Member
Join Date: Feb 2008
Location: CZK
Old 12-13-2008 , 12:59   Re: Country stats
Reply With Quote #2

UP
it cool
who can make it?
Strikerr is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-13-2008 , 13:48   Re: Country stats
Reply With Quote #3

PHP Code:
#include <amxmodx>
#include <amxmisc>
//#include <fvault>
#include <geoip>
#include <hamsandwich>

// INTERVAL is in seconds
// NOTE! Must have .0 at the end!
#define INTERVAL 60.0

new const g_vault_name[] = "country_counter";

new 
bool:g_connected[33];
new 
bool:g_alive[33];

new 
g_max_clients;

public 
plugin_init()
{
    
register_plugin("Country Counter""0.1""Exolent");
    
    
RegisterHam(Ham_Spawn"player""FwdPlayerSpawn"1);
    
RegisterHam(Ham_Killed"player""FwdPlayerDeath"1);
    
    
g_max_clients get_maxplayers();
    
    
set_task(INTERVAL"TaskShowCount"___"b");
}

public 
client_putinserver(client)
{
    
g_connected[client] = true;
    
g_alive[client] = false;
    
    new 
ip[64], country[46];
    
get_user_ip(clientipsizeof(ip) - 11);
    
geoip_country(ipcountrysizeof(country) - 1);
    
    new 
count[10];
    
fvault_get_data(g_vault_namecountrycountsizeof(count) - 1);
    
    
num_to_str(str_to_num(count) + 1countsizeof(count) - 1);
    
    
fvault_set_data(g_vault_namecountrycount);
}

public 
client_disconnect(client)
{
    
g_connected[client] = false;
    
g_alive[client] = false;
}

public 
FwdPlayerSpawn(client)
{
    if( 
is_user_alive(client) )
    {
        
g_alive[client] = true;
    }
}

public 
FwdPlayerDeath(client)
{
    
g_alive[client] = false;
}

public 
TaskShowCount()
{
    new 
message[256];
    
FormatCountryMessage(messagesizeof(message) - 1);
    
    if( 
message[0] )
    {
        for( new 
client 1client <= g_max_clientsclient++ )
        {
            if( !
g_connected[client] || g_alive[client] ) continue;
            
            
ShowCountryMessage(clientmessage);
        }
    }
}

FormatCountryMessage(message[], len)
{
    new 
size fvault_size(g_vault_name);
    
    new 
country[46], count[10];
    for( new 
0sizei++ )
    {
        
fvault_get_keyname(g_vault_nameicountrysizeof(country) - 1);
        if( 
equali(country"error") ) continue;
        
        
fvault_get_data(g_vault_namecountrycountsizeof(count) - 1);
        
        
format(messagelen"%s^n%s: %s"messagecountrycount);
    }
}

ShowCountryMessage(client, const message[])
{
    
set_hudmessage(025500.10.700.0INTERVAL 0.10.10.1, -1);
    
show_hudmessage(client"Visitors Per Country:%s"message);
}

#define _vault_dir "addons/amxmodx/data/file_vault"

stock fvault_get_keyname(const vaultname[], const keynumkey[], len)
{
    new 
filename[128];
    
_FormatVaultName(vaultnamefilenamesizeof(filename) - 1);
    
    new 
vault fopen(filename"rt");
    
    new 
_data[64], _other[3];
    
    new 
line = -1;
    
    while( !
feof(vault) )
    {
        
fgets(vault_datasizeof(_data) - 1);
        
        if( ++
line == keynum )
        {
            
parse(_datakeylen_othersizeof(_other) - 1);
            
            
fclose(vault);
            
            return 
1;
        }
    }
    
    
fclose(vault);
    
    return 
0;
}

stock fvault_get_data(const vaultname[], const key[], data[], len)
{
    new 
filename[128];
    
_FormatVaultName(vaultnamefilenamesizeof(filename) - 1);
    
    new 
vault fopen(filename"rt");
    
    new 
_data[512], _key[64];
    
    while( !
feof(vault) )
    {
        
fgets(vault_datasizeof(_data) - 1);
        
parse(_data_keysizeof(_key) - 1datalen);
        
        if( 
equal(_keykey) )
        {
            
fclose(vault);
            
            return 
1;
        }
    }
    
    
fclose(vault);
    
    
copy(datalen"");
    
    return 
0;
}

stock fvault_set_data(const vaultname[], const key[], const data[])
{
    static const 
temp_vault_name[] = "fvault_set_data.txt";
    
    new 
file fopen(temp_vault_name"wt");
    
    new 
filename[128];
    
_FormatVaultName(vaultnamefilenamesizeof(filename) - 1);
    
    new 
vault fopen(filename"rt");
    
    new 
_data[512], _key[64], _other[3];
    
    new 
bool:replaced false;
    
    while( !
feof(vault) )
    {
        
fgets(vault_datasizeof(_data) - 1);
        
parse(_data_keysizeof(_key) - 1_othersizeof(_other) - 1);
        
        if( 
equal(_keykey) && !replaced )
        {
            
fprintf(file"^"%s^" ^"%s^"^n"keydata);
            
            
replaced true;
        }
        else
        {
            
fputs(file_data);
        }
    }
    
    if( !
replaced )
    {
        
fprintf(file"^"%s^" ^"%s^"^n"keydata);
    }
    
    
fclose(file);
    
fclose(vault);
    
    
delete_file(filename);
    
    while( !
rename_file(temp_vault_namefilename1) ) { }
    
    
//delete_file(temp_vault_name);
}

stock fvault_size(const vaultname[])
{
    new 
filename[128];
    
_FormatVaultName(vaultnamefilenamesizeof(filename) - 1);
    
    return 
file_size(filename1) - 1;
}

stock _FormatVaultName(const vaultname[], filename[], len)
{
    if( !
dir_exists(_vault_dir) )
    {
        
mkdir(_vault_dir);
    }
    
    
formatex(filenamelen"%s/%s.txt"_vault_dirvaultname);

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 12-15-2008 at 14:23.
Exolent[jNr] is offline
Vorass24
Junior Member
Join Date: Dec 2008
Old 12-13-2008 , 15:10   Re: Country stats
Reply With Quote #4

Can U give me mor information about your code?
Vorass24 is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 12-13-2008 , 15:46   Re: Country stats
Reply With Quote #5

Quote:
Originally Posted by ajvn View Post
Greetings. Is it hard to make plugin where it can show all dead and spectators top 5 visitors for each country in right bottom corner via HUD every 60 sec
SnoW is offline
Send a message via MSN to SnoW
Strikerr
Member
Join Date: Feb 2008
Location: CZK
Old 12-14-2008 , 04:01   Re: Country stats
Reply With Quote #6

not work for me
error log
Quote:
L 12/14/2008 - 086:59: Start of error session.
L 12/14/2008 - 086:59: Info (map "cs_italy") (file "addons/amxmodx/logs/error_20081214.log")
L 12/14/2008 - 086:59: No search string specified.
L 12/14/2008 - 086:59: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 086:59: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:00: No search string specified.
L 12/14/2008 - 087:00: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:00: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:00: No search string specified.
L 12/14/2008 - 087:00: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:00: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:00: No search string specified.
L 12/14/2008 - 087:00: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:00: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:02: No search string specified.
L 12/14/2008 - 087:02: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:02: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:02: No search string specified.
L 12/14/2008 - 087:02: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:02: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:02: No search string specified.
L 12/14/2008 - 087:02: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:02: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:02: No search string specified.
L 12/14/2008 - 087:02: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:02: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:02: No search string specified.
L 12/14/2008 - 087:02: [AMXX] Run time error 10 (plugin "country.amxx") (native "replace") - debug not enabled!
L 12/14/2008 - 087:02: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 12/14/2008 - 087:02: No search string specified.

Last edited by Strikerr; 12-14-2008 at 04:32.
Strikerr is offline
shadowski
Senior Member
Join Date: Feb 2007
Old 12-14-2008 , 04:13   Re: Country stats
Reply With Quote #7

what version of amxmodx are you using?
shadowski is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 12-14-2008 , 04:18   Re: Country stats
Reply With Quote #8

Strikerr remove your big error log, and enable debug for this plugin
__________________
xPaw is offline
Strikerr
Member
Join Date: Feb 2008
Location: CZK
Old 12-14-2008 , 04:44   Re: Country stats
Reply With Quote #9

Debug
Quote:
L 12/14/2008 - 098:09: Info (map "de_dust") (file "addons/amxmodx/logs/error_20081214.log")
L 12/14/2008 - 098:09: No search string specified.
L 12/14/2008 - 098:09: [AMXX] Displaying debug trace (plugin "country.amxx")
L 12/14/2008 - 098:09: [AMXX] Run time error 10: native error (native "replace")
L 12/14/2008 - 098:09: [AMXX] [0] textW60VJ3.sma::_FormatVaultName (line 230)
L 12/14/2008 - 098:09: [AMXX] [1] textW60VJ3.sma::fvault_get_data (line 137)
L 12/14/2008 - 098:09: [AMXX] [2] textW60VJ3.sma::client_putinserver (line 40)
L 12/14/2008 - 098:09: No search string specified.
L 12/14/2008 - 098:09: [AMXX] Displaying debug trace (plugin "country.amxx")
L 12/14/2008 - 098:09: [AMXX] Run time error 10: native error (native "replace")
L 12/14/2008 - 098:09: [AMXX] [0] textW60VJ3.sma::_FormatVaultName (line 230)
L 12/14/2008 - 098:09: [AMXX] [1] textW60VJ3.sma::fvault_get_data (line 137)
L 12/14/2008 - 098:09: [AMXX] [2] textW60VJ3.sma::client_putinserver (line 40)
L 12/14/2008 - 098:10: No search string specified.
amxx 1.8.1
Strikerr is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-14-2008 , 14:25   Re: Country stats
Reply With Quote #10

Since my vault name doesn't have any invalid characters in it, I just removed that part of _FormatVaultName().
Try it now.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 18:54.


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