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

Read data from file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 11:33   Read data from file
Reply With Quote #1

Could someone make a tutorial on how to read data from a file? Or at least just show me how to do it.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 07-23-2010 , 11:39   Re: Read data from file
Reply With Quote #2

Quote:
Originally Posted by nikhilgupta345 View Post
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?
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 11:48   Re: Read data from file
Reply With Quote #3

Yes, like a .ini file or just a plain .txt. file

Thanks
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 07-23-2010 , 11:56   Re: Read data from file
Reply With Quote #4

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.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 12:15   Re: Read data from file
Reply With Quote #5

Ok, Thanks, but how do you navigate to the other folders.. would it be like fopen("addons/amxmodx/configs/plugins.ini") or something?
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 07-23-2010 , 12:32   Re: Read data from file
Reply With Quote #6

Quote:
Originally Posted by nikhilgupta345 View Post
Ok, Thanks, but how do you navigate to the other folders.. would it be like fopen("addons/amxmodx/configs/plugins.ini") or something?
Yes.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 13:02   Re: Read data from file
Reply With Quote #7

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)
}  
}
}
}

Last edited by nikhilgupta345; 07-23-2010 at 13:17.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-23-2010 , 13:21   Re: Read data from file
Reply With Quote #8

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.
__________________

Last edited by Bugsy; 07-23-2010 at 13:24.
Bugsy is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 13:33   Re: Read data from file
Reply With Quote #9

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.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-23-2010 , 13:40   Re: Read data from file
Reply With Quote #10

You need to use %d for integers not %s and you should not define new variables within a loop.
__________________
Bugsy 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:11.


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