AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Simply: needing 2 things into vars and dont get it! (https://forums.alliedmods.net/showthread.php?t=125773)

XCoder 05-02-2010 06:51

Simply: needing 2 things into vars and dont get it!
 
Hello Guys,

I'll hope someone of the AMXMODX Heros can help me.

Following, i'm learning amxmodx and at the moment i'm trying to get 2 vars out of a txt file, (mymaps.txt)

Following is inside:
Code:

mario_air                "\minplayers\5\maxplayers\32\"
mario_land                "\minplayers\4\maxplayers\32\"
mario_world                "\minplayers\8\maxplayers\32\"
mario_xmas                "\minplayers\4\maxplayers\32\"

My Problem is now that i need the the two numbers:
"\minplayers\5\maxplayers\32\"

The Code-Part for it: (mapchooser like)
Code:

new fp=fopen(filename,"r");
       
        while (!feof(fp))
        {
                buff[0]='^0';
               
                fgets(fp, buff, charsof(buff));
               
                parse(buff, szText, charsof(szText));
               
               
               
                if (szText[0] != ';' &&
                        ValidMap(szText) &&
                        !equali(szText, g_lastMap) &&
                        !equali(szText, currentMap))
                {
                        ArrayPushString(g_mapName, szText);
                        ++g_mapNums;
                }
               
        }
       
        fclose(fp);

The ValidMap() is at the moment the standard of mapchooser.amxx

Code:

stock bool:ValidMap(mapname[])
{
        if ( is_map_valid(mapname) )
        {
                return true;
        }
        // If the is_map_valid check failed, check the end of the string
        new len = strlen(mapname) - 4;
       
        // The mapname was too short to possibly house the .bsp extension
        if (len < 0)
        {
                return false;
        }
       
        // HERE SHOULD MY ADDING GOES.....
        if (-------------------)
        {
                return false;
        }
       
        if ( equali(mapname[len], ".bsp") )
        {
                // If the ending was .bsp, then cut it off.
                // the string is byref'ed, so this copies back to the loaded text.
                mapname[len] = '^0';
               
                // recheck
                if ( is_map_valid(mapname) )
                {
                        return true;
                }
        }
       
        return false;
}

Above i comment the Part where the code should go.
mapname[len] contains the whole part of the line i hope, so how i can get these two numbers out of mapname[len]?

I realy hope someone can helps me out!

(Sorry for my broken english, ill do my best)

//// ADDED:
Aye..., may i should say what i want to "if" too...
The first Number (minplayers) should go with if(get_playersnum() >= minplayers && maxplayers >= get_playersnum())...
Like this!


Greetings

Sylwester 05-02-2010 07:25

Re: Simply: needing 2 things into vars and dont get it!
 
That won't work even if you get those numbers from file and use them there, because settings are loaded only one time on plugin_init and at that time amount players connected to server equals 0.

Trying to load settings before each voting won't work either, because function that is supposed to clear array is somehow screwed (or at least it didn't work for me and voting after map extending was bugged because of it).

I'm right now working on exactly same thing and I have already rewritten most of the code and added more features.

XCoder 05-02-2010 07:43

Re: Simply: needing 2 things into vars and dont get it!
 
Uhm...
I think u dont understand me or my english is rly bad :D

I know that with round start nothing happens!
And these Numbers in de Map File are "static".

The checking with the if comes at the "END OF MAP" and then inside the script the actual player amount will be calculated.

So i just need to know how to figure the both numbers out...
i tryd this but looks bad and not finish with this bold line

Code:

new sandmen, minplayers=0, maxplayers=0;

if((sandmen = contain(mapname, "\maxplayers\")) != -12)
        {
                  copy(minplayers, sandmen -1, mapname);

...........
}


Sylwester 05-02-2010 08:10

Re: Simply: needing 2 things into vars and dont get it!
 
Did you add checking at the "END OF MAP" yourself? Because original version does it at the beginning of the map.

I added checking for min and max players in a lot simpler way (just need to add "#min max" in maps file and maps in following lines will only be used iif ( min <= players amount <= max )):
PHP Code:

    new szText[32], szTmp[32]
    new 
currentMap[32]
    new 
min=0max=get_maxplayers(), pnum=0
    
new buff[256];

    for(new 
i=1i<=maxi++)
        if((
is_user_connecting(i) || is_user_connected(i)) && !is_user_hltv(i) && !is_user_bot(i))
            
pnum++


    
get_mapname(currentMap31)

    new 
fp=fopen(filename,"r");
    
ArrayClear(g_mapName);
    while (!
feof(fp))
    {
        
buff[0]='^0';
        
szText[0]='^0';
        
szTmp[0]='^0';
        
        
fgets(fpbuffcharsof(buff));

        
parse(buffszTextcharsof(szText), szTmpcharsof(szTmp));
        if(
szText[0] == '#')
        {
            
min str_to_num(szText[1])
            
max str_to_num(szTmp)
            continue
        }
        if(
min>pnum || max<pnum)
            continue

        if (
szText[0] != ';' &&
            
ValidMap(szText) &&
            !
equali(szTextg_lastMap) &&
            !
equali(szTextcurrentMap))
        {
            
ArrayPushString(g_mapNameszText);
            ++
g_mapNums;
        }
        
    } 

example maps file:
Code:

#1 15
dod_anzio
dod_avalanche
#3 4
dod_forest
dod_glider
dod_jagd
dod_kalt
#0 3
dod_vicenza
dod_zalec


XCoder 05-02-2010 08:18

Re: Simply: needing 2 things into vars and dont get it!
 
nice that u wanna tell me some other ways, but please i must use it with this formation like i posted!

"\minplayers\5\maxplayers\32\"

(bec. on some maps there are some more vars after these both, but i only need this both at the moment)

Code:

if((sandmen = contain(mapname, "\maxplayers\")) != -12)
        {
                copy(minplayers, sandmen -12, mapname);
                .................

before the \max.. is the number i need, and after players\ is the number i need fpr maxplayers var.
if you can help me how i can get this, you will finish my problems! (for the moment ;))

///ADDD
And if i look at your code i notice that u try to make something totaly other :D
But okay, thats not the problem, i think you know the answere for my little problem if you understand what i try to find out ;)

thanks a lot

Sylwester 05-02-2010 08:49

Re: Simply: needing 2 things into vars and dont get it!
 
try this:
Code:

    new minplayers, maxplayers, szTmp[32], szUseless[32], pos
    pos = containi(mapname, "minplayers")
    if(pos > -1){
        strtok(mapname[pos], szUseless, 31, szTmp, 31, '\')
        strtok(szTmp, szTmp, 31, szUseless, 31, '\')
        minplayers = str_to_num(szTmp)
    }

    pos = containi(mapname, "maxplayers")
    if(pos > -1){
        strtok(mapname[pos], szUseless, 31, szTmp, 31, '\')
        strtok(szTmp, szTmp, 31, szUseless, 31, '\')
        maxplayers = str_to_num(szTmp)
    }


XCoder 05-02-2010 09:16

Re: Simply: needing 2 things into vars and dont get it!
 
Thanks a lot.
I will try it out and give a feedback about it soon.
At the moment there are to many players on the server.

XCoder 05-02-2010 16:08

Re: Simply: needing 2 things into vars and dont get it!
 
I solved the Problems and your Hints works great!
Also the first one i'm using now.

But i have many new things to walk trough :p
Thanks a lot...

Greetings

XCoder 05-04-2010 08:44

Re: Simply: needing 2 things into vars and dont get it!
 
Okay, i created a new thread for it with the complete code.
now its finish but some things are strange and at all its hardcoded...

http://forums.alliedmods.net/showthread.php?p=1170139

this thread could be closed... thx

greetings


All times are GMT -4. The time now is 03:49.

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