This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

File Writing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
s0upnazi
Member
Join Date: Mar 2006
Old 07-23-2006 , 01:30   File Writing
Reply With Quote #1

I'm making a plugin that records what maps are played and I get my code to compile, but it doesn't function in-game. The only thing I get is loose indentation which I doubt is my problem.

Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
	register_plugin("Favorite Maps", "1.0", "s0upnazi")
	register_cvar("amx_favorites", "1")
	register_concmd("amx_favmaps", "cmd_favs", ADMIN_KICK)
}

public plugin_end()
{
	new on
	
	on = get_cvar_num("amx_favorites")
	
	if(on == 0)
	return PLUGIN_HANDLED
	
	if(on == 1)
	{
		new szMapName[64];
		new themap = get_mapname(szMapName, 63)		
		new exists
		
		exists = file_exists("configs/fm/favoritemaps.txt")
		
		if(exists == 0)
		return PLUGIN_HANDLED
		
		format(szMapName, 63, "%s", themap)
		write_file("configs/fm/favoritemaps.txt", "themap", -1)
	}		
	return PLUGIN_HANDLED
}

public cmd_favs(id, level, cid)
{
	if(!cmd_access(id, level, cid, 1))
	{
            new read[1000000] 
	    new garbage
                 
		read_file("configs/fm/favoritemaps.txt", 0, read, 999999, garbage)
		console_print(id, read )
	}
	return PLUGIN_HANDLED
}
Thanks if anybody can help me, or provide a snappy comeback as to how I'm stupid ala Hawk552
s0upnazi is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-23-2006 , 13:08   Re: File Writing
Reply With Quote #2

Hi, you're stupid for a number of reasons, but I'm not going to go over them.

This is untested, does not use pointer cvars and does not use the new file system, but should work:

Code:
#include <amxmodx> #include <amxmisc> new g_File[] = "/favoritemaps.txt" public plugin_init() {     register_plugin("Favorite Maps", "1.0", "s0upnazi")     register_cvar("amx_favorites", "1")     register_concmd("amx_favmaps", "cmd_favs", ADMIN_KICK) } public plugin_end() {     if(!get_cvar_num("amx_favorites"))         return         new szMapName[64],ConfigsDir[64]         get_configsdir(ConfigsDir,63)     add(ConfigsDir,63,g_File)         get_mapname(szMapName, 63)     write_file(g_File,szMapName) } public cmd_favs(id, level, cid) {     if(!cmd_access(id, level, cid, 1))         return PLUGIN_HANDLED             static ConfigsDir[64]     if(!ConfigsDir[0])     {         get_configsdir(ConfigsDir,63)         add(ConfigsDir,63,g_File)     }         show_motd(id,ConfigsDir,"Favorite Maps")         return PLUGIN_HANDLED }
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-23-2006 , 13:15   Re: File Writing
Reply With Quote #3

Quote:
Originally Posted by RapHero2000
omg i love hawk, hey can u tell me what the sz stands for ? ive seen it in a menu making tutoriol and i dont know what it does. and he used it here also .
z = null terminated
s = string
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-23-2006 , 14:00   Re: File Writing
Reply With Quote #4

Quote:
Originally Posted by RapHero2000
can you exlain the usage pelase?? ive seen it infront of text and i dont know why thanks hawk
hungarian notation is kinda retarded in general for Pawn, since everything is really just a cell (integer). There is no real data type "string" in Pawn, but basically because a string is an array of chars terminated by a 0, we use s for string and z for null terminated.

Just don't get into hungarian notation, it's retarded for anything other than global or vector.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
s0upnazi
Member
Join Date: Mar 2006
Old 07-23-2006 , 16:08   Re: File Writing
Reply With Quote #5

Thanks Hawk, I wasn't sure on the configsdir function so I decided to do it without using it but thanks for putting it in there and giving me an example of correct usage
s0upnazi 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 02:47.


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