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

How do you read something from a file. Ini?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CsIosefin
Senior Member
Join Date: Aug 2009
Old 05-02-2010 , 17:46   How do you read something from a file. Ini?
Reply With Quote #1

Code:
#include <amxmodx>

public plugin_init()
{
    register_plugin("Auto-Messages", "1.0", "Team")
    
    register_dictionary("addons/amxmodx/configs/messages.ini")
    set_task(7.5, "Hud", _, _, _, "b")
    set_task(15.0, "Chat", _, _, _, "b")
}

public Chat(id, level, cid)
{
    client_print(0, print_chat, "%s", "Messages")
}
public Hud(id, level, cid)
{
    set_hudmessage(random(255), random(255), random(255), -1.0, 0.08, random_num(0, 2), 0.02, 6.0, 0.01, 0.1, 2)
    show_hudmessage(0, "%s", "Messages")
}
I want to do a self-messages, he read what was in messages.ini? How can I, as it did not even know it's never so interested ...
Messages.ini file is in addons / amxmodx / configs /
CsIosefin is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-02-2010 , 18:04   Re: How do you read something from a file. Ini?
Reply With Quote #2

maybe this can help you out:

http://forums.alliedmods.net/showthread.php?t=46218
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
CsIosefin
Senior Member
Join Date: Aug 2009
Old 05-03-2010 , 12:48   Re: How do you read something from a file. Ini?
Reply With Quote #3

Hmmm .... I want something simpler, I want to read from a file. Cars and display the plugin, so all ... is such a plugin then? From there I will try to source to see a way ...
CsIosefin is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-03-2010 , 12:52   Re: How do you read something from a file. Ini?
Reply With Quote #4

i myself am no expert at reading files, writing to them is no problem though, some more experienced coders will help you out.
Just be patience
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 05-03-2010 , 13:40   Re: How do you read something from a file. Ini?
Reply With Quote #5

reading from file is easy:
PHP Code:
#include <amxmodx>
#include <amxmisc>


public func(){
    new 
path[128], fhcache[128]
    
get_configsdir(path127)
    
format(path127"%s%s"path"/myfile.ini")
    
//with this it will try to open file: amxmodx/configs/myfile.ini

    
if(!file_exists(path)){ //check if file exists
        
log_amx("Error: file does not exist (%s)."path)
        return
    }

    
fh fopen(path"rt"//open text ("t") file for reading ("r")
    
if(!fh){ //check if we got proper file handle
        
log_amx("Error: Could not open file (%s)."path)
        return
    }

    new 
example_counter
    
while(!feof(fh)){ //loop until file handle points at the end of file
        
fgets(fhcache127//read next line from file and store it in "cache"

        //example count lines and print them in server console using log_amx:
        
example_counter++
        
log_amx("loaded line number %d: %s"example_countercache)

    }

    
fclose(fh)  //close file

__________________
Impossible is Nothing
Sylwester is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-03-2010 , 13:55   Re: How do you read something from a file. Ini?
Reply With Quote #6

http://forums.alliedmods.net/showpos...7&postcount=13
__________________
Bugsy is offline
CsIosefin
Senior Member
Join Date: Aug 2009
Old 05-04-2010 , 10:16   Re: How do you read something from a file. Ini?
Reply With Quote #7

This method is unique? Why so much stuff that I want to remove something from a text file, that's all ... nothing else, but if so, better leave directly. Sma ...
CsIosefin is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 05-04-2010 , 10:22   Re: How do you read something from a file. Ini?
Reply With Quote #8

there is so much stuff because many things has to be done to remove something.

Quote:
1. see if file exists
2. Read file
3. look for something
4. if something exists, remove it otherwise do nothing.
5. close the file
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2010 , 17:34   Re: How do you read something from a file. Ini?
Reply With Quote #9

Quote:
Originally Posted by CsIosefin View Post
Why so much stuff that I want to remove something from a text file, that's all
Because that's the way it is. It's different for different uses. You will never find a "one command does it all for you".
__________________
fysiks is offline
CsIosefin
Senior Member
Join Date: Aug 2009
Old 05-05-2010 , 12:54   Re: How do you read something from a file. Ini?
Reply With Quote #10

Should look like this? Or should include, depending? I think it's so pretty ... or at least, I do not give any erroare, I did not test him.
One question, if well, one must put the text in another? I do not want to read everything, but line by line ...
Code:
#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
    register_plugin("Auto-Messages", "1.0", "Team")

    set_task(7.5, "Hud", _, _, _, "b")
    set_task(15.0, "Chat", _, _, _, "b")
}

public func()
{
	new path[128], fh, cache[128]
	get_configsdir(path, 127)
	format(path, 127, "%s%s", path, "/messages.ini")

	if(!file_exists(path))
	{
	log_amx("Error: file does not exist (%s).", path)
	return
	}

	fh = fopen(path, "rt")
	if(!fh)
	{
	log_amx("Error: Could not open file (%s).", path)
	return
	}

	new example_counter
	while(!feof(fh))
	{
	fgets(fh, cache, 127)
	example_counter++
	log_amx("loaded line number %d: %s", example_counter, cache)
	}

	fclose(fh)
}

public Chat(id)
{
	client_print(0, print_chat, "%s", "path")
}
public Hud(id)
{
	set_hudmessage(random(255), random(255), random(255), -1.0, 0.08, random_num(0, 2), 0.02, 6.0, 0.01, 0.1, 2)
	show_hudmessage(0, "%s", "path")
}
CsIosefin 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 03:25.


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