AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Writing to file? (https://forums.alliedmods.net/showthread.php?t=133314)

nikhilgupta345 07-24-2010 02:37

Writing to file?
 
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)
}


Kreation 07-24-2010 03:48

Re: Writing to file?
 
Remove one of the '%s' from fprintf.

nikhilgupta345 07-24-2010 08:42

Re: Writing to file?
 
Thanks works perfect now. Don't know how I didn't see that

xPaw 07-24-2010 08:44

Re: Writing to file?
 
You don't need trim() there by the way

nikhilgupta345 07-24-2010 08:45

Re: Writing to file?
 
I thought trim removes the spaces in the array? Or do the blanks not get written in the file?

Bugsy 07-24-2010 08:52

Re: Writing to file?
 
Quote:

Originally Posted by nikhilgupta345 (Post 1249998)
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.

nikhilgupta345 07-24-2010 08:59

Re: Writing to file?
 
Oh. Thanks both of u


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

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