Raised This Month: $ Target: $400
 0% 

Retrieve txt file content in console


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ev1scerator
Junior Member
Join Date: Mar 2011
Old 12-18-2013 , 10:47   Retrieve txt file content in console
Reply With Quote #1

Hello guys , i need help with a plugin to retrieve the content of a txt file to the console instead of using motd.

Say for example i have the following plugin :
Code:
#include <amxmodx>
#include <amxmisc>

public say_motd(id)
{
    show_motd(id, "motd.txt", "Message of the Day")
    return PLUGIN_HANDLED
}

public say_admins(id)
{
    new szFileDir[64]
    get_configsdir( szFileDir, 63 )
    format( szFileDir, 63, "%s/admin.txt", szFileDir )
    show_motd(id, szFileDir, "All Admins")
    return PLUGIN_HANDLED
}

public plugin_init()
{
    register_plugin("say /motd", "0.2", "Nightscream")
    register_clcmd("say /motd", "say_motd")
    register_clcmd("say /admins", "say_admins")
}
It displays the content of admin.txt using MOTD.

All is good, but is there a way to write it to console , just as you use rcon motdfile name then rcon motd ??
I need a plugin in the form of one command (ex: amx_retrieve , without any other argument) that will write a certain txt file to my console (even if it has over 100 lines and takes longer).
The txt file that will be displayed is to be specified in the plugin body.


And i have one more question ....can an .ini file be dumped as output to a .txt file ?
Plugin reads .ini file and copies all , creates .txt file and pastes.
Maybe i'm asking too much , i dunno



LE : After some searching , found and tried to create the plugin i wanted from another plugin's code :
Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Blabla"
#define VERSION "2.0"
#define AUTHOR "Evs"

new szFDataBuffer[3000][512], tmpi


public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("amx_evs", "evs")
}

public evs_p(id)
{	
	client_print(id,print_console, "%d) %s", tmpi + 1, szFDataBuffer[tmpi])
	tmpi++
}


public evs(id)
{    
	new szDataDir[128], szData[200]
	client_print(id,print_console,"===========================")
	get_datadir(szDataDir, sizeof (szDataDir) - 1)
	format(szDataDir, sizeof (szDataDir), "%s/hihi.txt", szDataDir)
	
	new i = 0
	tmpi = 0
	
	new file = fopen(szDataDir, "rt")
	while(!feof(file))
	{				
	fgets(file, szData, sizeof(szData) -1)
	///////////////////////////////////////
	
	
	i++
	}
	formatex(szFDataBuffer[i - 1], 512 - 1, szFDataBuffer)

	fclose(file)
	
	set_task(0.01, "evs_p", id, _, _, "a", i)
	
	return 0
}
I get error 048: array dimensions do not match on the red line

Last edited by Ev1scerator; 12-18-2013 at 12:58.
Ev1scerator is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-18-2013 , 14:55   Re: Retrieve txt file content in console
Reply With Quote #2

There's no difference between a .ini file and a .txt other than the assumed contents. Why do you need to copy it? There are functions created in the Code Snippets/Tutorials forum to do this.

Anyways, there were many things wrong with the code that you created, too many for me to write up right now. Here is a quick fix that I did for you. It's untested and with no guarantees.

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

new szFDataBuffer[1000][512]
new iLineCount = 0
new iPrintCount[33]

public plugin_init()
{
	register_plugin("Print File to Console", "0.1", "Hello World")
	register_clcmd("amx_evs", "evs")
}

public plugin_cfg()
{
	new szFilename[128]
	get_datadir(szFilename, charsmax(szFilename))
	format(szFilename, sizeof (szFilename), "%s/hihi.txt", szFilename)
	
	new file = fopen(szFilename, "rt")
	while(!feof(file))
	{
		fgets(file, szFDataBuffer[iLineCount], charsmax(szFDataBuffer[]))
		trim(szFDataBuffer[iLineCount])
		iLineCount++
	}
	fclose(file)
}

public evs(id)
{    
	iPrintCount[id] = 0
	client_print(id, print_console, "===========================")
	set_task(0.1, "evs_print", id, _, _, "a", iLineCount)
	return PLUGIN_CONTINUE
}

public evs_print(id)
{	
	client_print(id, print_console, "%d) %s", iPrintCount[id] + 1, szFDataBuffer[iPrintCount[id]])
	iPrintCount[id]++
}
__________________
fysiks is offline
Ev1scerator
Junior Member
Join Date: Mar 2011
Old 12-19-2013 , 06:29   Re: Retrieve txt file content in console
Reply With Quote #3

@fysiks Haha dude u're a pro as always! It works like a charm

Thanks a lot!
Ev1scerator 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 20:27.


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