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

Read, write, compare cfg file


Post New Thread Reply   
 
Thread Tools Display Modes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 03-21-2010 , 19:43   Re: Read, write, compare cfg file
Reply With Quote #11

Quote:
Originally Posted by drekes View Post
ow, you mean learning how they work?
Yeah, just learn the way the data is retrieved from the actual command and what you can do with it.


Quote:
Originally Posted by drekes View Post
btw: can i add you guys in the credits in case this ever gets realised?
Sure.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 03-21-2010 , 20:06   Re: Read, write, compare cfg file
Reply With Quote #12

Quote:
Originally Posted by wrecked_ View Post
Look at the beginning tutorials on the website (1 has a concmd, I think it's the amx_hp one),
I searched every page of the scripting help section but can't find it. although i'm sure i've saw it when i started scripting
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-21-2010 , 23:33   Re: Read, write, compare cfg file
Reply With Quote #13

This will store all steamids entered with amx_addid command in an ini file (playeridfile.ini) found in your amxmodx\data directory. The plugin reads from this file when it loads so you can enter them manually with notepad and then do a mapchange\restart to make it take effect. The plugin does not check the validity of a steamid so make sure it is entered correctly. When a user connects, a chat message will print to all saying whether or not the user was found on the steamid list (just for demonstration).

Console command: amx_addid "STEAM_0:0:12345"
Admin access needed for amx_addid command is AMX_BAN

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <celltrie>

new Trie:g_tSteamIDs;
new 
g_szFile64 ];

public 
plugin_init() 
{
    new 
szData35 ];
    
    
g_tSteamIDs TrieCreate();
    
    
copyg_szFileget_localinfo"amxx_datadir" g_szFile charsmaxg_szFile ) ) ] , charsmaxg_szFile ) , "/playeridfile.ini" );
    
    new 
fopeng_szFile "rt" );
    
    while( !
feof) )
    {
        
fgetsszData charsmaxszData ) );
     
        
trimszData );
        
        if( !
szData[0] || szData[0] == ';' || szData[0] == '/' && szData[1] == '/' 
            continue;
            
        
TrieSetCellg_tSteamIDs szData );
    }
    
    
fclose);
    
    
register_concmd"amx_addid" "AddID" ADMIN_BAN "<SteamID> - Add SteamID to list" );
}

public 
client_putinserverid )
{
    new 
szName33 ] , szSteamID35 ];
    
    
get_user_nameid szName charsmaxszName ) );
    
get_user_authidid szSteamID charsmaxszSteamID ) );

    if ( 
TrieKeyExistsg_tSteamIDs szSteamID ) )
    {
        
client_printprint_chat "* %s has connected and was found on the list!" szName );
    }
    else
    {
        
client_printprint_chat "* %s has connected and was NOT found on the list!" szName );
    }
}

public 
AddIDid level cid )
{
    if ( !
cmd_accessid level cid ) )
        return 
PLUGIN_HANDLED;
        
    new 
szSteamID35 ];

    if ( 
read_argvszSteamID charsmaxszSteamID ) ) )
    {
        if ( !
TrieKeyExistsg_tSteamIDs szSteamID ) )
        {
            
TrieSetCellg_tSteamIDs szSteamID );
            
write_fileg_szFile szSteamID );
            
console_printid "* Added SteamID ^"%s^" to list." szSteamID );
        }
        else
        {
            
console_printid "* SteamID ^"%s^" already exists in list." szSteamID );
        }
    }
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 03-22-2010 at 00:00.
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-21-2010 , 23:57   Re: Read, write, compare cfg file
Reply With Quote #14

Quote:
Originally Posted by Bugsy View Post
Console command: amx_addid "STEAM_0:0:12345"
Must use quotes around a SteamID.

Quote:
Originally Posted by drekes View Post
I searched every page of the scripting help section but can't find it. although i'm sure i've saw it when i started scripting
He is refering to the wiki here.
__________________
fysiks is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 03-22-2010 , 05:23   Re: Read, write, compare cfg file
Reply With Quote #15

Thanks bugsy

@ fysiks
Do i have to add the quotes when i add him through console or do i have to change the script?

@wrecked_
I found the amx_hp tutorial thanks to fysiks
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 03-22-2010 , 06:24   Re: Read, write, compare cfg file
Reply With Quote #16

Can i make bugsy's addid that you use playername instead of steamid?

i tryed it , will it work or is it wrong?
PHP Code:
{
    if(!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED
        
    
new Arg1[24]
    new 
szSteamID[35];
    
    
read_argv(1Arg123)

    new 
player cmd_target(idArg11)
    
    if (!
player)
    {
        
console_print(id"player %s could not be found!"Arg1)
        return 
PLUGIN_HANDLED
    

            
    else 
    {
        
get_user_authid(playerszSteamID[34],  charsmax(szSteamID))
    }
    
    
// Check steamid list.
    
if (!TrieKeyExists(g_tSteamIDsszSteamID))
    {
        
TrieSetCell(g_tSteamIDsszSteamID1);
        
write_file(g_szFileszSteamID);
        
console_print(id"* Added SteamID ^"%s^" to list."szSteamID);
    }
        
    else
    {
        
console_print(id"* SteamID ^"%s^" already exists in list."szSteamID);
    }
    return 
PLUGIN_HANDLED;

__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 03-22-2010 at 06:31.
drekes is offline
Send a message via MSN to drekes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-22-2010 , 17:51   Re: Read, write, compare cfg file
Reply With Quote #17

When you put a SteamID in the file you do not use quotes. When you put a SteamID in with a command in the console you must use quotes.

As for your code, the only thing that I see that would make it not work is that you index the szSteamID; remove the index (and brackets) and I think it might work.

Tip: cmd_target already tells you if there target could not be found so there is no reason to do it again as you have.

Here is my version if you are interested:


PHP Code:
public AddIDid level cid )
{
    if ( !
cmd_accessid level cid ) )
        return 
PLUGIN_HANDLED;

    new 
szArg[35];
    
read_argvszArg charsmaxszArg ) );
    new 
iPlayer cmd_target(idszArgCMDTARGET_ALLOW_SELF CMDTARGET_NO_BOTS);

    if ( 
iPlayer )
    {
        new 
szSteamID35 ];
        
get_user_authid(iPlayerszSteamIDcharsmax(szSteamID));
        if ( !
TrieKeyExistsg_tSteamIDs szSteamID ) )
        {
            
TrieSetCellg_tSteamIDs szSteamID );
            
write_fileg_szFile szSteamID );
            
console_printid "* Added SteamID ^"%s^" to list." szSteamID );
        }
        else
        {
            
console_printid "* SteamID ^"%s^" already exists in list." szSteamID );
        }
    }

    return 
PLUGIN_HANDLED;

__________________
fysiks is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 03-22-2010 , 17:58   Re: Read, write, compare cfg file
Reply With Quote #18

tnx fysiks, thanks for your notepad ++ highlighting to, it rules.

And can i read the file again once it is updated, like when i add an id? if i do it like this
PHP Code:
public plugin_init()
{
    
readfile()
    
//stuff
}

public 
readfile()
{
        new 
szData[35];
   
    
g_tSteamIDs TrieCreate();
    
    
copyg_szFileget_localinfo("amxx_datadir"g_szFilecharsmax(g_szFile))], charsmax(g_szFile), "/ct-banlist.ini");
    
    new 
fopen(g_szFile"rt");
    
    while(!
feof(f))
    {
        
fgetsszData charsmaxszData ) );
     
        
trimszData );
        
        if(!
szData[0] || szData[0] == ';' || szData[0] == '/' && szData[1] == '/'
        continue;
            
        
TrieSetCell(g_tSteamIDsszData1);
    }
    
    
fclose(f);

__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 03-22-2010 at 18:06.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-22-2010 , 19:20   Re: Read, write, compare cfg file
Reply With Quote #19

Are there any other plugins reading from writing to the file? If not then there is no reason to reload the file during runtime.
__________________

Last edited by Bugsy; 03-22-2010 at 19:55.
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-22-2010 , 19:30   Re: Read, write, compare cfg file
Reply With Quote #20

Quote:
Originally Posted by Bugsy View Post
Are there any other plugins reading from writing to the file? If not then there is no reason to reload the file during runtime.
__________________
fysiks 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 07:49.


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