AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Logging player problem? (https://forums.alliedmods.net/showthread.php?t=133798)

nikhilgupta345 07-28-2010 22:38

Logging player problem?
 
Hi, I tried making a plugin that logs a player's steamid and name (I've done this before) but this time, I'm trying to make it so that if their name is already in the txt file, don't write it again. This is the code I have:

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Logging"
#define VERSION "1.0"
#define AUTHOR "nikhilgupta345"


public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("steamids.txt")
    register_logevent("round_start", 2, "1=Round_Start")
}

public round_start()
{
   
    new players[32], player, num
    new readfile[256]
    new filewrite=fopen("addons/amxmodx/configs/logs.txt", "wt")
    new fileread=fopen("addons/amxmodx/configs/logs.txt", "rt")
    get_players(players, num)
    for(new i;i<num;i++)
    {
        while(!feof(fileread))
        {
            fgets(fileread, readfile, charsmax(readfile))
        new authid[32], name[32]
        player=players[i]
        get_user_name(player, name, 31)
        get_user_authid(player, authid, 31)
        if(!(containi(readfile, name)) || !(containi(readfile, authid)))
        {
            fprintf(filewrite, "%s-%s", name, authid)
            client_print(0, print_chat, "[Dust2 Pub] %L", LANG_PLAYER, "NAME_LOGGED", name)
        }
    }
        }
   
}

When I join my server and when the round starts, doesn't print anything to cleint, and when I check logs.txt (I made it myself, the plguin didn't make it), nothing is in it :/

fysiks 07-28-2010 22:43

Re: Logging player problem?
 
Here is the best example plugin for something like this.

Good luck.

nikhilgupta345 07-28-2010 22:52

Re: Logging player problem?
 
Hmm, are there any good trie tutorials?

nikhilgupta345 07-28-2010 23:33

Re: Logging player problem?
 
Still not working after trying with trie's :/

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <celltrie>

#define PLUGIN "logging"
#define VERSION "1.0"
#define AUTHOR "Server Owner"

new Trie:gSteamIDTrie
new gszFile[64]
public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("steamids.txt")
    register_logevent("round_start", 2, "1=Round_Start")
}

public round_start()
{
    new info[36]
    new players[32], player, num
    new authid[32], name[32]
    gSteamIDTrie=TrieCreate()
    get_localinfo( "amxx_configsdir", gszFile, 63 )
    copy( gszFile, charsmax(gszFile), "/logs.txt" )
    new file=fopen( gszFile, "rt" )
    while( !feof(file) )
    {
        fgets( file, info, charsmax(info) )
        trim(info)
        TrieSetCell(gSteamIDTrie, info, 1)
    }
    fclose(file)
    get_players(players, num)
    for( new i; i<num; i++ )
    {
        player=players[i]
        get_user_authid( player, authid, charsmax(authid) )
        get_user_name( player, name, 31 )
        if( !TrieKeyExists( gSteamIDTrie, authid ) )
        {
            write_file( gszFile, name )
            write_file( gszFile, authid )
            client_print(0, print_chat, %L, "LOGGED_NAME", name)
        }
       
    }
}

Any ideas?

fysiks 07-29-2010 02:17

Re: Logging player problem?
 
If all you are doing is trying to log the player then I would recommend doing it on client_putinserver().

I would start with Bugsy's example and just modify it to add your SteamID to the list and write to the file (as shown in the AddID() function). Don't do anything with names yet. Get it working then you can add or modify from there.

As far as your most recent code, you need to put quotes around the %L to get it to compile. Again, you need to start simple. Don't do any multilingual stuff until you have the rest of the code working as it should.

nikhilgupta345 07-29-2010 22:57

Re: Logging player problem?
 
Got it working without the lang file :D. Thanks for the help fysiks.
Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <celltrie>

#define PLUGIN "logging"
#define VERSION "1.0"
#define AUTHOR "Server Owner"

new Trie:gSteamIDTrie
new gszFile[64]
public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_logevent("round_start", 2, "1=Round_Start")
}

public round_start()
{
    new info[36]
    new players[32], player, num
    new authid[32], name[32]
    gSteamIDTrie=TrieCreate()
    get_localinfo( "amxx_configsdir", gszFile, 63 )
    new const text[64]="Server Player Log File"
    new const logs[64]="addons/amxmodx/configs/logs.txt"
    if(!file_exists(logs))
    write_file(logs, text)
   
    new file=fopen( logs, "rt" )
    while( !feof(file) )
    {
        fgets( file, info, charsmax(info) )
        trim(info)
        TrieSetCell(gSteamIDTrie, info, 1)
    }
    fclose(file)
    get_players(players, num)
    for( new i; i<num; i++ )
    {
        player=players[i]
        get_user_authid( player, authid, charsmax(authid) )
        get_user_name( player, name, 31 )
        if( !TrieKeyExists( gSteamIDTrie, authid ) )
        {
            write_file( logs, name )
            write_file( logs, authid )
            client_print(0, print_chat, "%s has never played in this server before, please welcome him!", name)
        }
       
    }
}


fysiks 07-29-2010 23:18

Re: Logging player problem?
 
FYI, if you listen to me and use Bugsy's code as a template it would be much much much more optimized. Reading a file several times and looping through players on NewRound is something you do not need to do at all.

nikhilgupta345 07-29-2010 23:32

Re: Logging player problem?
 
Yea, I realize that, gonna fix that now :/

nikhilgupta345 07-29-2010 23:38

Re: Logging player problem?
 
Got a question, if you read the file during plugin_init and a player joins, it'll add his name to the list. But, if he leaves and then joins again without the map changing or soemthing, will his name be added twice?

fysiks 07-29-2010 23:39

Re: Logging player problem?
 
Quote:

Originally Posted by nikhilgupta345 (Post 1255762)
Got a question, if you read the file during plugin_init and a player joins, it'll add his name to the list. But, if he leaves and then joins again without the map changing or soemthing, will his name be added twice?

I see you haven't actually read Bugsy's code. When someone joins and they are not in the list they are added to the trie AND the file.

Hint: It's TrieSetCell() that you skipped.


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

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