Raised This Month: $ Target: $400
 0% 

how to read and store only what I need


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Menethil
Senior Member
Join Date: Aug 2011
Old 01-13-2013 , 02:27   how to read and store only what I need
Reply With Quote #1

Suposing I have this txt file

Code:
* Sub-Title 1 *
- Text line 1
- Text line 2
- Text line 3
- etc.


* Sub-Title 2 *
- Text line x
- Text line y
- Text line z

* Sub-Title 3*
- and so on..
And I need to get & store only the line's from a Sub-Title...
Best example I can Give is if
PHP Code:
 (get_mapname(///) == Sub-Title X ) {
// to set a task wich random prints to clients some particular map rules
// and ofcourse the rulles will be that Text lines from each sub-title(map)

Ty -.-"
Menethil is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-13-2013 , 06:00   Re: how to read and store only what I need
Reply With Quote #2

You can store rules for different maps in separate files.
__________________
Impossible is Nothing
Sylwester is offline
Menethil
Senior Member
Join Date: Aug 2011
Old 01-13-2013 , 06:10   Re: how to read and store only what I need
Reply With Quote #3

Quote:
Originally Posted by Sylwester View Post
You can store rules for different maps in separate files.
PHP Code:
#include <amxmodx>
#include <amxmisc>


public plugin_init(){
    
register_plugin("Test","1.0","We think about it")
}

public 
plugin_cfg() {
    new 
mapname[64];
    
get_mapname(mapname,63)

   
// Here I dont know how to do it -.-"
    
new curent_map_file[] = (%s_rules.txtmapname)

    if (!
file_exists(curent_map_file)) {
        
write_file(curent_map_file"; Text your map rules below")
        
console_print(0"%s file not found. Creating new"curent_map_file)
    }
    
}

public 
client_authorized id set_task(1.0"showrules",id,tmp,1)

public 
showrules (pid[]) {
    new 
id pid[0]
    
    if ( 
get_user_team(id) != && get_user_team(id) != ) {
        if (
id) {
            new 
tmp[1]
            
tmp[0] = id
            set_task
(2.0"showrules",id,tmp,1)  // not yet in server
        
}
        return 
PLUGIN_HANDLED
    
}    

    new 
tmp[1]
    
tmp[0] = id
    
    
    set_task
(3.0"printrules"idtmp1)  // not yet in server
    
    
return PLUGIN_HANDLED
}

public 
printrules(pid[])
{
    new 
id pid[0]
    if (
file_exists(curent_map_file))
        {
        
        
console_print(0"[user] printing rules for user %d"id)
        
        for(
i=0read_file(curent_map_fileitext127num); i++) {
            if (
num && text[0] != ';') {
                
client_print(0,print_chat,"%s"text)    
            }
        }
        }
    
    return 
PLUGIN_HANDLED

And also how could I print rules each one by one, randomly.
I guess this will print the whole text at once

Last edited by Menethil; 01-13-2013 at 06:51.
Menethil is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-13-2013 , 15:09   Re: how to read and store only what I need
Reply With Quote #4

Wow, that is some bad coding.
  • Code:
    formatex(curent_map_file, charsmax(curent_map_file), "%s_rules.ini", mapname)
  • Code:
    set_task(1.0, "mytask", id)
    
    public mytask(id)
    {
    	// stuff
    }
  • The client is in the server when client_putinserver() is called. There is no reason to create an inefficient loop.
  • You should not be reading from the file every time printrules() is executed. You need to read the file in plugin_cfg() into an array of strings and then you can print one of those strings when printrules() is executed.
__________________
fysiks is offline
Menethil
Senior Member
Join Date: Aug 2011
Old 01-14-2013 , 08:20   Re: how to read and store only what I need
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
Wow, that is some bad coding.
  • Code:
    formatex(curent_map_file, charsmax(curent_map_file), "%s_rules.ini", mapname)
  • Code:
    set_task(1.0, "mytask", id)
    
    public mytask(id)
    {
        // stuff
    }
  • The client is in the server when client_putinserver() is called. There is no reason to create an inefficient loop.
  • You should not be reading from the file every time printrules() is executed. You need to read the file in plugin_cfg() into an array of strings and then you can print one of those strings when printrules() is executed.
Thank you, my above code is similar to some that I found to do my needings, and I ripped some parts, cus I had no clue about reading/storing/and printing data from a separate file.
Now I got it, thanks
Menethil 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 13:42.


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