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

Read data from file


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

So I edited the file to make it kick with an integer %i, and I put the variables in front of the for loop. So the new code is this, but it still doesn't work :/

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)
    new userid
    new authid[32]
    for(new i;i<num;i++)
    {
        player=players[i]
    userid=get_user_userid(player)
    get_user_authid(player, authid, 31)
    
    if(equali(buffer, authid))
    {
        server_cmd("kick #%i", userid)
    
    // Close file handle
        fclose(fp)
}  
}
}
}
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 , 16:25   Re: Read data from file
Reply With Quote #12

Try using trim() on buffer after fgets(). And you can use "rt" flags with fopen instead of "a"
__________________
Bugsy is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 18:03   Re: Read data from file
Reply With Quote #13

What exactly does "rt" do?

nvrm, figured it out.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 19:40   Re: Read data from file
Reply With Quote #14

How do I make it so that it reads more than 1 line with fgets? Because I was trying to see if it would, and it didn't. It was working with my steamid in the first line, but in the second line it didn't. Do i have to use like read_file?
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 , 19:55   Re: Read data from file
Reply With Quote #15

read_file reads one line at a time too, or is that not what you meant.
__________________
Bugsy is offline
Peoples Army
SourceMod Donor
Join Date: Mar 2007
Old 07-23-2010 , 19:56   Re: Read data from file
Reply With Quote #16

PHP Code:


fopen 
Opens and returns a file handle on success
fclose Closes a file handle
feof Checks for end of file
fprintf Writes to a file
fgets Reads text from a file
fseek Seek to a position in a file
ftell Get the current position of a file
fread/fread_blocks/fread_raw Read binary data from a file
fwrite/fwrite_blocks/fwrite_raw Write binary data to a file
__________________
Peoples Army is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 20:04   Re: Read data from file
Reply With Quote #17

Like how do u make fgets read different lines.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Peoples Army
SourceMod Donor
Join Date: Mar 2007
Old 07-23-2010 , 20:09   Re: Read data from file
Reply With Quote #18

I think it's becuase it's stopping at the new line character try this


PHP Code:



An example of reading a file with the 
new system


#include <file>
 
stock CopyTextFile(const infile[], const outfile[])
{
   new 
infp fopen(infile"rt")    //read text
   
new outfp fopen(outfile"wt")  //write text
 
   
if (!infp || !outfp)
      return 
0
 
   
new buffer[2048]
   while (!
feof(infp))
   {
      
fgets(infpbuffer2047)
      
fprintf(outfp"%s"buffer)
   }
   
fclose(infp)
   
fclose(outfp)
}

Note that fgets includes a newline if one is reachedA quick way to strip newlines is


new 
len strlen(string)
if (
string[len-1] == '^n')
   
string[--len] = 

It was on here

http://wiki.amxmodx.org/AMX_Mod_X_1....ipting_Changes
__________________
Peoples Army is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-23-2010 , 20:15   Re: Read data from file
Reply With Quote #19

Hmm, does the "string[--len]=1" at the bottom make the ^n=0?
Also, if I do that, would it read both of the lines as one string? Because I want them to be separate steamids.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-23-2010 , 20:27   Re: Read data from file
Reply With Quote #20

Did you even read ot_207's post?

Quote:
Originally Posted by ot_207 View Post
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 (!feof(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.
Don't use this code (use trim()):

Quote:
Originally Posted by Peoples Army View Post
PHP Code:
Note that fgets includes a newline if one is reachedA quick way to strip newlines is


new 
len strlen(string)
if (
string[len-1] == '^n')
   
string[--len] = 
Quote:
Originally Posted by Bugsy View Post
If you prefer to recheck every player at round start you should cache the steam id at client putinserver.
I don't see how this makes sense at all. SteamID remains unchanged.
__________________

Last edited by fysiks; 07-23-2010 at 20:42.
fysiks 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 06:45.


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