AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Finding a name in the .ini (https://forums.alliedmods.net/showthread.php?t=232498)

Baws 12-31-2013 13:11

Finding a name in the .ini
 
I tried to do this but didn't work. With what i need help is to type /search and search for the word in the .ini list. Look what i did, but it didn't work:

PHP Code:




ConnorMcLeod 12-31-2013 13:56

Re: Finding a name in the .ini
 
I've already (i think) told you it is a bad idea to search in a file during game time, it is better to cache the file content into variables (arrays, dynamic arrays) and to search in there.

Baws 12-31-2013 14:43

Re: Finding a name in the .ini
 
How?

This?: https://forums.alliedmods.net/showpo...59&postcount=4

Backstabnoob 12-31-2013 15:33

Re: Finding a name in the .ini
 
On plugin_init or somewhere else read the whole .ini file and save each line into a dynamic array with ArrayPushString, then iterate through the array when someone writes /search and compare the line with your search string.

Baws 12-31-2013 15:42

Re: Finding a name in the .ini
 
Exemple? Please?

fysiks 12-31-2013 17:48

Re: Finding a name in the .ini
 
There are tons of plugins that cache files. You can see my Bot Apology plugin for an example that uses arrays. If you use simple arrays (which will have hardcoded lengths) You then simply loop through each one and use equal[i]() or contain[i]() on each string.

Baws 12-31-2013 18:14

Re: Finding a name in the .ini
 
Ok done, now if i want to see if the word is there, how to check it? how to do that V ?

PHP Code:

    else if(equali(say_args"/search"))
    {    
        if(!
songname or word not found)
                return
        else if(
songname or word found)
        {
        
inistialize(); here is where we read the line
        SearchSong menu here its a menu
the menu is where all the matches arelike there is 10 eminem songs and i type /search eminem in the menu i see all eminem songsyou get it


fysiks 12-31-2013 19:24

Re: Finding a name in the .ini
 
Quote:

Originally Posted by fysiks (Post 2079159)
You then simply loop through each one and use equal[i]() or contain[i]() on each string.


Baws 12-31-2013 19:39

Re: Finding a name in the .ini
 
Hard to understand really, i'm not that good. I'm a beginner. Example :/ ?

Baws 12-31-2013 19:56

Re: Finding a name in the .ini
 
But like for the menu i just do this?

PHP Code:

if(equali(say_args"/search"))
{
SearchSong(id)



public 
SearchSong(id)
{
    new 
menu menu_create("\ySeached for:\r""searchsong_handler")
    for( new 
1<= songcounti++ )
    {
        new 
num[3];
        
num_to_str(inum2);
        
menu_additem(menug_media_names[i], num);
    }
    
    
menu_display(idmenu);

    return 
PLUGIN_HANDLED;
}

public 
searchsong_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], name[64]; 
    new 
accesscallback
    
menu_item_getinfo(menuitemaccessdatacharsmax(data), namecharsmax(name), callback);

    
songlistfile[id] = item
    
    play_media
(iditem);
    
    return 
PLUGIN_HANDLED;




All times are GMT -4. The time now is 10:09.

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