Raised This Month: $ Target: $400
 0% 

Read text from .cfg file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 05-07-2014 , 07:00   Read text from .cfg file
Reply With Quote #1

How can I make a function to read text from a .cfg file?

EXAMPLE
The plugin must use a file called 'steamids.cfg'
And what I would like to know, how and what function will read the .cfg and put into "if(equal(steamid,.." func

PHP Code:
public bomb_planted(id)
{
    new 
name[33]
    
get_user_name(idname32)

    new 
steamid[33]
    
get_user_authid(idsteamid33)

    new 
players[32], pnum
    get_players
(playerspnum"ceh""TERRORIST")
    for(new 
TT 0TT pnumTT++)
    {
        if(
equal(steamid"READ ALL STEAM IDS FROM A .CFG FILE"))
        {    
            
ColorChat(players[TT], GREEN"%s ^1bla bla"name)
        }
         else
        
ColorChat(players[TT], GREEN"%s ^1bla bla"name)
    }    

So all stemids that are in the cfg file will be used
CHE4TER is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-07-2014 , 07:21   Re: Read text from .cfg file
Reply With Quote #2

take a read of this and see if you understand...
https://forums.alliedmods.net/showpo...0&postcount=27

use what you need to make your plugin work.
__________________
Blizzard_87 is offline
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 05-07-2014 , 07:29   Re: Read text from .cfg file
Reply With Quote #3

PHP Code:
new g_SteamID[256]


public 
plugin_init()
{
    new 
SteamIDs[128]
    
get_configsdir(SteamIDs127)
    
format(SteamIDs,127,"%s/SteamIDs.cfg"SteamIDs)
        
    new 
pFile fopen(SteamIDs"r")
    if(
pFile) { while(fgets(pFileg_SteamID255))
    {}
    }
    
fclose(pFile)


PHP Code:
public bomb_planted(id)
{
    new 
name[33]
    
get_user_name(idname32)

    new 
steamid[33]
    
get_user_authid(idsteamid33)

    new 
players[32], pnum
    get_players
(playerspnum"ceh""TERRORIST")
    for(new 
TT 0TT pnumTT++)
    {
        if(
contain(g_SteamIDsteamid) != -1)
        {    
            
ColorChat(players[TT], GREEN"%s ^1bla bla"name)
        }
         else
        
// Show message to team
        
ColorChat(players[TT], GREEN"%s ^1bla bla"name)
    }    

I have this, and isn't working
CHE4TER is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-07-2014 , 07:36   Re: Read text from .cfg file
Reply With Quote #4

of course because your not saving the steamID's properly in here.
Code:
new g_SteamID[256] public plugin_init() {     new SteamIDs[128]     get_configsdir(SteamIDs, 127)     format(SteamIDs,127,"%s/SteamIDs.cfg", SteamIDs)               new pFile = fopen(SteamIDs, "r")     if(pFile) { while(fgets(pFile, g_SteamID, 255))     {}     }     fclose(pFile) }

RE read that link i posted and use that whole code and see how it works... then you might understand how to use it for yourself.
__________________
Blizzard_87 is offline
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 05-07-2014 , 07:44   Re: Read text from .cfg file
Reply With Quote #5

The link you posted is about what I need, but the code uses "enum", and for every steamid I need duplicate the colorchat message. I just need that message usable for all steamids in the config
CHE4TER is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 05-07-2014 , 08:00   Re: Read text from .cfg file
Reply With Quote #6

I Guess !!
PHP Code:
public Check(id)
{
    new 
iCfgDir[32], iFile[192],szID[32]
    
    
get_user_authid(id,szID,charsmax(szID))
    
    
get_configsdir(iCfgDircharsmax(iCfgDir));
    
formatex(iFilecharsmax(iFile), "%s/Steam.cfg"iCfgDir);
    
    if(!
file_exists(iFile)) {
        
server_print("[Test] File Introuvable"iFile);
        
write_file(iFile" ", -1);
    }
    
    else {        
        
server_print("[Test] Steam.cfg Charger."iFile);
        if(
equal(szID,iFile))
        {
            
        }
    }

Freezo Begin is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 05-07-2014 , 08:21   Re: Read text from .cfg file
Reply With Quote #7

Can you fix for me this ! @Blizzard_87 :/ Please

Code:
#include <amxmodx> #include <amxmisc> new config[81],line,text[32],nm,SteamidBlock[410][32],i public plugin_init() {     register_plugin("Steam Id Blocker","1.0","frezo") } public plugin_cfg() {     get_configsdir(config,81)     format(config,80,"%s/SteamId.ini",config)         if(file_exists(config)) {         for(line=0;read_file(config,line,text,sizeof(text)-1,nm);line++) {             write_file(config,"",-1)         }     } } public client_putinserver(id) {     new Steam[32]     get_user_authid(id, Steam, sizeof(Steam)-1)     for(i=0;i<line+1;i++) {         if(containi(Steam,SteamidBlock[i]))             server_cmd("kick #%d This Steam Id Is Blocked", get_user_userid(id))     }     }

Last edited by Freezo Begin; 05-07-2014 at 08:22.
Freezo Begin is offline
CHE4TER
Member
Join Date: Jul 2013
Location: Portugal
Old 05-07-2014 , 15:52   Re: Read text from .cfg file
Reply With Quote #8

Anyone do this?
What is the correctly way to do it?
Create steamids.cfg
Read all steamid stored in the file
Use that steamids in the colorchat func
CHE4TER is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-07-2014 , 16:49   Re: Read text from .cfg file
Reply With Quote #9

Quote:
Originally Posted by CHE4TER View Post
Anyone do this?
What is the correctly way to do it?
Create steamids.cfg
Read all steamid stored in the file
Use that steamids in the colorchat func
I can do it for you. I just wanted you to try first. It's more enjoyable to figure out things on your own. Just with little bits of help here and there. Try what i said in about post about using that plugin and see how it works. And post your result here. If you still can't figure it out ill post the majority of the code let you fill in blanks.
__________________
Blizzard_87 is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 05-07-2014 , 17:28   Re: Read text from .cfg file
Reply With Quote #10

We need your help here and don't tell us to figure by self !!
if you know how . post the code to learn !!




I hope you understand .
i will grateful for your help .
Freezo Begin is offline
Reply


Thread Tools
Display Modes

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:38.


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