AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Read text from .cfg file (https://forums.alliedmods.net/showthread.php?t=240001)

CHE4TER 05-07-2014 07:00

Read text from .cfg file
 
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

Blizzard_87 05-07-2014 07:21

Re: Read text from .cfg file
 
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.

CHE4TER 05-07-2014 07:29

Re: Read text from .cfg file
 
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

Blizzard_87 05-07-2014 07:36

Re: Read text from .cfg file
 
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.

CHE4TER 05-07-2014 07:44

Re: Read text from .cfg file
 
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

Freezo Begin 05-07-2014 08:00

Re: Read text from .cfg file
 
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 05-07-2014 08:21

Re: Read text from .cfg file
 
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))     }     }

CHE4TER 05-07-2014 15:52

Re: Read text from .cfg file
 
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

Blizzard_87 05-07-2014 16:49

Re: Read text from .cfg file
 
Quote:

Originally Posted by CHE4TER (Post 2134948)
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.

Freezo Begin 05-07-2014 17:28

Re: Read text from .cfg file
 
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 .


All times are GMT -4. The time now is 09:38.

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