Raised This Month: $ Target: $400
 0% 

Writing to file?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-24-2010 , 02:37   Writing to file?
Reply With Quote #1

Ok, so I'm trying to make a plugin that, when a client joins your server, it gets his steamid, name, and ip, and writes it to a file. When I join the server, nothing gets written to the file.
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "AutoSteamID and IP Log"
#define VERSION "1.0"
#define AUTHOR "H3avY Ra1n"


public plugin_init() {
    //Register Plugin
    register_plugin(PLUGIN, VERSION, AUTHOR)
}

public client_putinserver(id)
{
    new authid[32]
    new name[32]
    new ip[32]
    get_user_authid(id, authid, 31)
    get_user_ip(id, ip, 31)
    new fp = fopen("addons/amxmodx/configs/logging.txt", "wt")
    get_user_name(id, name, 31)
    trim(authid)
    trim(ip)
    trim(name)
    fprintf(fp, "%s-%s-%s-%s", name, authid,ip)
    fclose(fp)
}
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 07-24-2010 , 03:48   Re: Writing to file?
Reply With Quote #2

Remove one of the '%s' from fprintf.
__________________
Hi.
Kreation is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-24-2010 , 08:42   Re: Writing to file?
Reply With Quote #3

Thanks works perfect now. Don't know how I didn't see that
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 07-24-2010 , 08:44   Re: Writing to file?
Reply With Quote #4

You don't need trim() there by the way
__________________
xPaw is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-24-2010 , 08:45   Re: Writing to file?
Reply With Quote #5

I thought trim removes the spaces in the array? Or do the blanks not get written in the 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-24-2010 , 08:52   Re: Writing to file?
Reply With Quote #6

Quote:
Originally Posted by nikhilgupta345 View Post
I thought trim removes the spaces in the array? Or do the blanks not get written in the file?
An array is not filled with spaces, it is filled with null characters. When you read name,authid,ip,etc, the array is filled with the data followed by null characters which do not need to be trimmed. Search the web for null terminated strings for more info.
__________________

Last edited by Bugsy; 07-24-2010 at 09:03.
Bugsy is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 07-24-2010 , 08:59   Re: Writing to file?
Reply With Quote #7

Oh. Thanks both of u
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
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 00:06.


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