Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

Thread: best player map

  1. #11
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by randall View Post
    Because your script is totally wrong. The biggest mistake is the waiting in the 'for' cycle. Try this, it causes the result you'd like to see: (not tested!)
    PHP Code:
    checkStatus()
    {
        
    level.brakdanych "^1BRAK DANYCH";
        
    first = [];
        
    first["player"]    = undefined;
        
    first["name"]    = level.brakdanych;
        
    first["exp"]    = level.brakdanych;
        
    first["rank"]    = level.brakdanych;

        
    players getEntarray("player""classname");
        for (
    0players.sizei++)
        {
            
    player players];

            if (! 
    isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
                continue;

            if (! 
    isDefined(first["player"]) || player.sexp first["exp"])
            {
                
    first["player"] = player;
                
    first["name"] = player.name;
                
    first["exp"] = player.sexp;
                
    first["rank"] = player.poziom;
            }
        }

        for (
    0players.sizei++)
        {
            
    player players];

            
    player setClientCvar("first_player",
                    
    "First Player: Name:" first["name"] +
                    
    " His Exp IS:" first["exp"] +
                    
    " His rank IS:" first["rank"]);
        }

    PHP Code:
    player.sexp first["exp"
    I have only looked at the code casually, but isn't first["exp"] a string (level.brakdanych = "^1BRAK DANYCH")? So, how is the game not throwing an error saying that an int can't be compared to a string?

  2. The Following User Says Thank You to Tally For This Useful Post:

    kung foo man (13th July 2013)

  3. #12
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    113
    Thanks
    10
    Thanked 74 Times in 45 Posts
    Quote Originally Posted by Tally View Post
    PHP Code:
    player.sexp first["exp"
    I have only looked at the code casually, but isn't first["exp"] a string (level.brakdanych = "^1BRAK DANYCH")? So, how is the game not throwing an error saying that an int can't be compared to a string?
    You're right, not the best solution to set different types for a variable, but this is the simplest way. Actually the first condition (! isDefined(first["player"])) is undefined, so the script will not check the second condition, and the first["exp"] will get a numeric value. In the practice it don't be a problem. In theory

  4. #13
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Looking at the code a bit more, I can see that all it does is assign the very first player to the value first["player"] without any conditions at all. So, pretty pointless really. What he needs to do is set a condition for who the first player is (possibly by setting a numerical value for first["exp"]) and attenuate the players on that basis.

    What I would do is compare every player's XP, and attenuate the players on that basis. Pretty much like 1st, 2nd, and 3rd are attenuated placements based on scores in other well known end-of-game scripts.

  5. #14
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    113
    Thanks
    10
    Thanked 74 Times in 45 Posts
    Well, it would the best sort the players by exp, and only get the first 3 elements of the array.

    http://en.wikipedia.org/wiki/Insertion_sort

    Quote Originally Posted by malyczolg View Post
    randall very thanks it works , can u tell me how add the second player?
    This script is only get the best player, if you wanna get the 2nd and 3rd players, then you have to rewrite the all function. See above.
    Last edited by randall; 13th July 2013 at 10:12.

  6. #15
    Private First Class
    Join Date
    Feb 2013
    Posts
    201
    Thanks
    4
    Thanked 10 Times in 7 Posts
    PHP Code:
    secondplayer()
    {
        
    level.brakdanych "^1BRAK DANYCH";
        
    second = [];
        
    second["player"]    = undefined;
        
    second["name"]    = level.brakdanych;
        
    second["exp"]    = level.brakdanych;
        
    second["rank"]    = level.brakdanych;

        
    players getEntarray("player""classname");
        for (
    0players.sizei++)
        {
            
    player players];

            if (! 
    isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
                continue;

            if (! 
    isDefined(second["player"]) || player.sexp second["exp"])
            {
                
    second["player"] = player;
                
    second["name"] = player.name;
                
    second["exp"] = player.sexp;
                
    second["rank"] = player.poziom;
            }
        }

        for (
    0players.sizei++)
        {
            
    player players];

            
    player setClientCvar("second_player",
                    
    "second Player: Name:" second["name"] +
                    
    " His Exp IS:" second["exp"] +
                    
    " His rank IS:" second["rank"]);
        }

    PHP Code:
            if (! isDefined(second["player"]) || player.sexp second["exp"])
            {
                
    second["player"] = player;
                
    second["name"] = player.name;
                
    second["exp"] = player.sexp;
                
    second["rank"] = player.poziom;
            } 
    how get best second player ?

  7. #16
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    113
    Thanks
    10
    Thanked 74 Times in 45 Posts
    If you rename a variable the result still not going to change xd Forget this script, i wrote it before you said you need 2nd and 3rd players too. I copied a link above about the insertion sort, use that to sort the players by exp. After you're ready, you have to only print (or put in cvars) the first 3 elements of the sorted array.

    EDIT: I thought you will never write the script, so:
    PHP Code:
    checkStatus()
    {
        
    level.brakdanych "^1BRAK DANYCH";
        
    places = [];
        
    places[0] = []; // 1st player
        
    places[1] = []; // 2nd player
        
    places[2] = []; // 3rd player

        
    players getEntArray("player""classname");

        
    // take invalid players from the array
        
    array = [];
        for (
    0players.sizei++)
        {
            
    player players];

            if (! 
    isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
                continue;

            array[ array.
    size ] = players];
        }

        
    // sort the 'players' array by exp
        
    array = array_sort_by_exp(array);

        
    // set places
        
    for (0places.sizei++)
        {
            if (
    isDefined(array[ ])) {
                
    places]["player"]    = array[ ];
                
    places]["name"]        = array[ ].name;
                
    places]["exp"]        = array[ ].sexp;
                
    places]["rank"]        = array[ ].poziom;
            } else {
                
    places]["player"]    = undefined;
                
    places]["name"]        = level.brakdanych;
                
    places]["exp"]        = level.brakdanych;
                
    places]["rank"]        = level.brakdanych;
            }
        }

        
    // set cvars for all players
        
    for (0players.sizei++)
        {
            
    player players];

            
    player setClientCvar("first_player",
                    
    "first Player: Name:" places[0]["name"] +
                    
    " His Exp IS:" places[0]["exp"] +
                    
    " His rank IS:" places[0]["rank"]);
            
    player setClientCvar("second_player",
                    
    "second Player: Name:" places[1]["name"] +
                    
    " His Exp IS:" places[1]["exp"] +
                    
    " His rank IS:" places[1]["rank"]);
            
    player setClientCvar("third_player",
                    
    "third Player: Name:" places[2]["name"] +
                    
    " His Exp IS:" places[2]["exp"] +
                    
    " His rank IS:" places[2]["rank"]);
        }
    }

    array_sort_by_exp(array)
    {
        
    temp = array;

        for (
    0temp.size 1i++)
        {
            for (
    1temp.sizej++)
            {
                if (
    temp].sexp temp].sexp)
                {
                    var = 
    temp];
                    
    temp] = temp];
                    
    temp] = var;
                }
            }
        }

        return 
    temp;

    Last edited by randall; 13th July 2013 at 14:37.

  8. The Following User Says Thank You to randall For This Useful Post:

    NemanjA (14th July 2013)

  9. #17
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    getbestplayers(amount)
    {
        
    players getentarray("player""classname");
        if(
    amount players.size)
            
    amount players.size;
        
    result = [];
        for(
    0amounti++)
        {
            
    best i;
            for(
    1players.sizej++)
            {
                if(
    players[j].score players[best].score)
                    
    best j;
            }
            
    tmp players[best];
            
    players[best] = players[i];
            
    players[i] = tmp;
            
    result[result.size] = tmp;
        }
        return 
    result;

    Untested code

  10. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (13th July 2013),NemanjA (14th July 2013)

  11. #18
    Private First Class
    Join Date
    Feb 2013
    Posts
    201
    Thanks
    4
    Thanked 10 Times in 7 Posts
    randal your script almost work ,but script show top3 worst player not the best.
    can u fix it?

  12. #19
    Private
    Join Date
    Jul 2012
    Posts
    76
    Thanks
    9
    Thanked 56 Times in 38 Posts
    Quote Originally Posted by malyczolg View Post
    randal your script almost work ,but script show top3 worst player not the best.
    can u fix it?
    Why don't you try it on your own first? It's not that hard..

  13. #20
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    113
    Thanks
    10
    Thanked 74 Times in 45 Posts
    Quote Originally Posted by malyczolg View Post
    randal your script almost work ,but script show top3 worst player not the best.
    can u fix it?
    Please, use your brains just a little :S Try to understand my script line by line and don't be a "copypaste-modder". A bit help: u need to change only an operator.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •