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

Custom Names[FOPEN Help]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 02-12-2014 , 07:19   Custom Names[FOPEN Help]
Reply With Quote #1

Hey everyone,

I just wanna create a simple plugin.
This plugin will read the players' steamid and the custom name, and if a player has this steamid, it will set this custom name(the one which read from the file).
The c_names.ini will be like this:
Code:
;"SteamID" "Custom Name"
"STEAM_0:X:YYYYYYYY" "Troller"
So, i have this code by now:
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "oxygen"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

LoadCustomNames() 
{
    new 
file[64];
    
get_configsdir(filecharsmax(file));
    
add(filecharsmax(file), "/c_names.ini")
    
    new 
fopen(file"rt")
    
    if(!
f) return
    
    
// File format:
    // "SteamID" "Custom Name"
    
    
new line[256]
    new 
szFileSteamId[32]
    new 
rank[128]
    
    while(!
feof(f)) 
    {
        
fgets(flinecharsmax(line))
        
trim(line)
        
        if(!
line[0] || line[0] == ';' || (line[0] == '/' && line[1] == '/'))
        {
            continue
        }    
    }
    
fclose(f)

So, i know what to do, but i don't know how to do it.
I wanna store the player's name on client_putinserver, then set the custom name, if it is available, and on client_disconnect set again the old name.

So please help me, cause this my first time working with fopen natives.

With Respect,
Oxygen
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science

Last edited by oxygen935; 02-12-2014 at 10:01.
oxygen935 is offline
Send a message via Skype™ to oxygen935
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 02-12-2014 , 08:58   Re: Custom Names[FOPEN Help]
Reply With Quote #2

Why do you name it simple if you can't do it? I really don't understand what you want to do. Sanity checks inside the While loop are bad written. You should inform yourself more.

PHP Code:
line[0] == '/' && line[1] == '/' 
->

PHP Code:
(line[0] == '/' && line[1] == '/'
Consider that client_infochanged may alter the client's name.

Isn't get_configsdir an AMXMISC function? You forgot to include this file.

http://www.amxmodx.org/doc/index.htm...re%2Fparse.htm
__________________

Last edited by claudiuhks; 02-12-2014 at 09:02.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 02-12-2014 , 10:06   Re: Custom Names[FOPEN Help]
Reply With Quote #3

oh thanks, i'm stupid. Code updated

Lets explain myself more.
we have this line in the c_names.ini --> "STEAM_0:X:YYYYYYYY" "Troller"

when the player with the steamid: STEAM_0:X:YYYYYYYY connect to my server, his name will be saved on a variable and then the plugin will set its name to "Troller". when the player will disconnect from the server, his name will be set to his old one.

so i want some help on how to read the steamid and the name from the c_names.ini
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science

Last edited by oxygen935; 02-12-2014 at 10:07.
oxygen935 is offline
Send a message via Skype™ to oxygen935
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 02-13-2014 , 06:17   Re: Custom Names[FOPEN Help]
Reply With Quote #4

Take a read thru this.

Saving the data read from file in a trie.

Then when ever the name change forward is executed you check the trie.

https://forums.alliedmods.net/showpo...0&postcount=27
__________________
Blizzard_87 is offline
oxygen935
Veteran Member
Join Date: Jun 2012
Location: Athens, Greece
Old 02-13-2014 , 08:49   Re: Custom Names[FOPEN Help]
Reply With Quote #5

Quote:
Originally Posted by Blizzard_87 View Post
Take a read thru this.

Saving the data read from file in a trie.

Then when ever the name change forward is executed you check the trie.

https://forums.alliedmods.net/showpo...0&postcount=27
That helps a lot. Will try it soon.

Thanks for Help Blizzard ;)
__________________
Quote:
Originally Posted by quark View Post
You're a genius
Stopped any pawn work cause of university for computer science
oxygen935 is offline
Send a message via Skype™ to oxygen935
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-13-2014 , 12:16   Re: Custom Names[FOPEN Help]
Reply With Quote #6

To read text in files i'm using this template :

PHP Code:
    new fp fopen(szCfgFile"rt");
    if( 
fp )
    {
        new 
buffer[256], c;
        while( !
feof(fp) )
        {
            
fgets(fpbuffercharsmax(buffer));
            
trim(buffer);
            
buffer[0];
            if( 
&& != '#' && != ';' && !( == '/' && buffer[1] == '/' ) )
            {
            }
        }
        
fclosefp );
        
fp 0;
    } 
For the plugin you want :

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

#pragma semicolon 1

#define PLUGIN ""
#define VERSION "0.0.1"

#define cm(%0)    ( sizeof(%0) - 1 )

new Trie:g_tCustomNames;

new 
g_szCustomName[33][32];

public 
plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" );
}

public 
plugin_cfg()
{
    new 
szCfgFile[64];
    
get_configsdir(szCfgFilecm(szCfgFile));
    
add(szCfgFilecm(szCfgFile), "/c_names.ini");
    new 
fp fopen(szCfgFile"rt");
    if( 
fp )
    {
        new 
buffer[256], c;
        new 
szSteamId[21], szCustomName[32];
        
g_tCustomNames TrieCreate();
        while( !
feof(fp) )
        {
            
fgets(fpbuffercharsmax(buffer));
            
trim(buffer);
            
buffer[0];
            if( 
&& != '#' && != ';' && !( == '/' && buffer[1] == '/' ) )
            {
                
parse(bufferszSteamIdcm(szSteamId), szCustomNamecm(szCustomName));
                
TrieSetString(g_tCustomNamesszSteamIdszCustomName);
            }
        }
        
fclosefp );
        
fp 0;
    }
}

GETPLAYERAUTHID(idbGet false)
{
    static 
szAuthid[33][21];
    if( 
bGet )
    {
        
get_user_authid(idszAuthid[id], charsmax(szAuthid[]));
    }
    return 
szAuthid[id];
}

public 
client_putinserver(id)
{
    
g_szCustomName[id][0] = EOS;
    if( 
TrieGetString(g_tCustomNamesGETPLAYERAUTHID(idtrue), g_szCustomName[id], cm(g_szCustomName[])) )
    {
        
set_user_name(idg_szCustomName[id]);
    }
}

public 
client_infochanged(id)
{
    if( 
g_szCustomName[id][0] && is_user_connected(id) )
    {
        
set_user_name(idg_szCustomName[id]);
    }
}

set_user_name(id, const name[])
{
    
set_user_info(id"name"name);

__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 09:50.


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