AlliedModders

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

nikhilgupta345 07-23-2010 11:33

Read data from file
 
Could someone make a tutorial on how to read data from a file? Or at least just show me how to do it.

ot_207 07-23-2010 11:39

Re: Read data from file
 
Quote:

Originally Posted by nikhilgupta345 (Post 1249119)
Could someone make a tutorial on how to read data from a file? Or at least just show me how to do it.

What type of file? A text file?

nikhilgupta345 07-23-2010 11:48

Re: Read data from file
 
Yes, like a .ini file or just a plain .txt. file

Thanks :D

ot_207 07-23-2010 11:56

Re: Read data from file
 
PHP Code:

stock print_file()
{
    
// Open a file, path starts from cstrike folder
    
new fp fopen("server.cfg"), buffer[100]
    
    
// Foef means is it end of file?
    
while (!foef(fp))
    {
        
// Get the line
        
fgets(fpbuffercharsmax(buffer)
        
// Print it in the server console
        
server_print("FILE CONTENT: %s"buffer)
    }
    
    
// Close file handle
    
fclose(fp)


I have not tested it. Wrote it here.
Also check the funcwiki for more function details.

nikhilgupta345 07-23-2010 12:15

Re: Read data from file
 
Ok, Thanks, but how do you navigate to the other folders.. would it be like fopen("addons/amxmodx/configs/plugins.ini") or something?

ot_207 07-23-2010 12:32

Re: Read data from file
 
Quote:

Originally Posted by nikhilgupta345 (Post 1249157)
Ok, Thanks, but how do you navigate to the other folders.. would it be like fopen("addons/amxmodx/configs/plugins.ini") or something?

Yes.

nikhilgupta345 07-23-2010 13:02

Re: Read data from file
 
What parameters would you change in the fgets, to change which line is read. Also, when I tried using feof, it says "undefined symbol: feof".

I'm trying to make a plugin where on round start, if someone's steamid is in the steamids.ini file, they will get kicked. I know, basically a ban, just trying to learn basics.

here's code

Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "AutoSteamID Kicker"
#define VERSION "1.0"
#define AUTHOR "H3avY Ra1n"

public plugin_init() {
    //Register Plugin
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_logevent("round_start", 2, "1=Round_Start")
}

public round_start()
{
    if(file_exists("addons/amxmodx/configs/steamids.ini"))
    {
    new fp = fopen("addons/amxmodx/configs/steamids.ini", "a"), buffer[100]

   
 
    fgets(fp, buffer, charsmax(buffer)) 

    new players[32], player, num
    get_players(players, num)
   
    for(new i;i<num;i++)
    {
        player=players[i]
    new userid=get_user_userid(player)
    new authid[32]
    get_user_authid(player, authid, 19)
   
    if(equali(buffer, authid))
    {
        server_cmd("kick #%s", userid)
   
    // Close file handle
        fclose(fp)

}
}
}


Bugsy 07-23-2010 13:21

Re: Read data from file
 
There is code that does exactly what youre trying to do in my aimbot detect plugin. Also, it would be more resourceful to check players as they connect. If you prefer to recheck every player at round start you should cache the steam id at client putinserver.

nikhilgupta345 07-23-2010 13:33

Re: Read data from file
 
well that code above doesn't work in my server, any clues? I put my steamid in the text file, and i don't get kicked on round start.

Bugsy 07-23-2010 13:40

Re: Read data from file
 
You need to use %d for integers not %s and you should not define new variables within a loop.


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

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