Results 1 to 9 of 9

Thread: Save Stats !!

  1. #1
    Private EnergY's Avatar
    Join Date
    Jul 2012
    Posts
    34
    Thanks
    32
    Thanked 2 Times in 2 Posts

    Save Stats !!

    Hey all

    Now I learned how modder and i Have make the mod look (thOuMta Have help me)
    Click image for larger version. 

Name:	shot0002.jpg 
Views:	128 
Size:	279.3 KB 
ID:	214

    Now i need help for make the script for save the stats (rank,total kill , money ) ...

    Who can help me


    Greeting EnergY
    Xfire: romain88120 and energyfun !!

  2. #2
    Private EnergY's Avatar
    Join Date
    Jul 2012
    Posts
    34
    Thanks
    32
    Thanked 2 Times in 2 Posts
    I have 1 Server for test me mod in 1.0
    Xfire: romain88120 and energyfun !!

  3. #3
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    This has been discussed before, but in case you missed it or don't know how to use the "search" function, here is a script I wrote to cater for a client's kills and saving them to persistent data files:

    PHP Code:
    init()
    {
        
    level thread onPlayerConnect();
        
    level thread onGameEnd();
    }

    onPlayerConnect()
    {
        for( ;; )
        {
            
    level waittill"connected"player );
            
            
    // initialize the player kills flag
            
    if( player getPlayerKills() )
                
    player.pers["kills"] = player.kills;
            else
                
    player.pers["kills"] = 0;
        }
    }

    onGameEnd()
    {
        for( ;; )
        {
            
    level waittill"intermission" );
            
            
    players getentarray"player""classname" );
            for(
    0players.sizei++)
            {
                
    player players[i];
                
    player thread saveKillsplayer.pers["kills"] ); 
            }
        }
    }

    onPlayerScore()
    {
        
    // update the player kills flag
        
    self.pers["kills"]++;
        
    self thread demon\_playerhud::UpdateHud();
    }

    saveKillskills )
    {
        
    filename sanitizeNameself.name ) + ".txt";
        
    filehandle openfilefilename"append" );
        
        if( 
    filehandle != -)
        {
            
    fprintlnfilehandlekills );
            
    closefilefilehandle );
        }
    }

    getPlayerKills()
    {
        
    filename sanitizeNameself.name ) + ".txt";
        
    file OpenFilefilename"read" );
        
        if( 
    file == -)
            return( 
    false );
        
        for( ;; )
        {
            
    elems freadlnfile );
            
            if( 
    elems == -)
                break;
                
            if( 
    elems == )
                continue;
        
            
    line "";
            for( 
    pos 0pos elemspos++ )
            {
                
    line line fgetargfilepos );
                if( 
    pos elems )
                    
    line line ",";
            }
                
            array = 
    strtokline"," );
            
    self.kills int( array[0] );
        }
        
        
    CloseFilefile );
        
        
    file OpenFilefilename"write" );
        
    CloseFilefile );
        
        return( 
    true );
    }

    sanitizeNamestr )
    {
        if( !
    isDefinedstr ) || str == "" ) return "";

        
    validchars "!()+,-.0123456789;=@AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_{}~";

        
    tmpname monotonestr );
        
    string "";
        
    prevchr "";
        for( 
    0tmpname.sizei++ )
        {
            
    chr tmpname[i];
            if( 
    chr == "." )
            {
                if( !
    string.size ) continue; // avoid leading dots
                
    if( chr == prevchr ) continue; // avoid double dots
            
    }
            else if( 
    chr == "[" chr "{";
            else if( 
    chr == "]" chr "}";

            
    prevchr chr;
            for( 
    0validchars.sizej++ )
            {
                if( 
    chr == validchars[j] )
                {
                    
    string += chr;
                    break;
                }
            }
        }

        if( 
    string == "" string "noname";
        
        return 
    string;

    That saves data at the end of either a round or a map.

  4. The Following 2 Users Say Thank You to Tally For This Useful Post:

    EnergY (10th April 2013),kung foo man (10th April 2013)

  5. #4
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Better save them on GUID than on playername since not everybody plays with the same name every time

  6. The Following 2 Users Say Thank You to Ni3ls For This Useful Post:

    EnergY (11th April 2013),kung foo man (11th April 2013)

  7. #5
    Private First Class Earliboy's Avatar
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    130
    Thanks
    5
    Thanked 88 Times in 61 Posts
    That doesnt makes sense at all (Your script tally, why should u save stats on a name?)
    Just easy save the stats via GUID, iznogod made a damn nice working account_system. I'm using some parts of it and its working perfect.
    No ... No ... this is not possible .......

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

    EnergY (11th April 2013)

  9. #6
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by Earliboy View Post
    That doesnt makes sense at all (Your script tally, why should u save stats on a name?)
    Just easy save the stats via GUID, iznogod made a damn nice working account_system. I'm using some parts of it and its working perfect.
    What is wrong with you people? Why can you not get your head round the fact that on a modding forum, when someone posts a script it is meant to be an example? Not a finished, ready to use article. The code I posted gives the bare bones of a system to save values to a file. Yet, you have taken the least important aspect of it and rounded on it as if that reduces the value of the real "meat" in the code - the code to save values to a file. The point is, you can REPLACE how you flag the value - be that a player's name or a GUID - yet the principle is still valid.

    I sometimes despair at the level of intelligence shown on some modding forums.

  10. The Following 3 Users Say Thank You to Tally For This Useful Post:

    EnergY (11th April 2013),EvoloZz (11th April 2013),kung foo man (11th April 2013)

  11. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    I agree with tally, although his code seems inefficient on the following part:
    PHP Code:
            line ""
            for( 
    pos 0pos elemspos++ ) 
            { 
                
    line line fgetargfilepos ); 
                if( 
    pos elems 
                    
    line line ","
            } 
                 
            array = 
    strtokline"," ); 
    You first get all elements, store them in a string, separated by , and then strtok that string on that very same ,

    You can do that directly by:
    PHP Code:
        array = [];
        for(
    pos 0pos elemspos++)
            array[
    pos] = fgetarg(filepos); 
    -some guy who actually read the code

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

    EnergY (11th April 2013),kung foo man (11th April 2013)

  13. #8
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Also, your code seems to take a way too complicated approach (which might be the result of it being incorporated in the demonmod, for compatibility with other parts-sake).
    Here is a quick n dirty version i just wrote:

    PHP Code:
            
    waitforconnect
    ()
    {
        while(
    true)
        {
            
    level waittill("connecting"player);
            
    player getkills();
        }
    }

    getkills()
    {
        
    file player getguid() + ".txt";
        
    fid openfile(fileread);
        if(
    fid != -1)
        {
            if(
    freadln(fid) > 0)
                
    self.kills int(fgetarg(file0));
            else
                
    self.kills 0;
            
    closefile(fid);
        }
        else
            
    self.kills 0;
    }

    onkill() //call on attacker
    {
        
    self.kills++;
        
    file player getguid() + ".txt";
        
    fid openfile(filewrite);
        
    fprintln(fidself.kills);
        
    closefile(fid);


  14. The Following User Says Thank You to IzNoGoD For This Useful Post:

    EnergY (11th April 2013)

  15. #9
    Private EnergY's Avatar
    Join Date
    Jul 2012
    Posts
    34
    Thanks
    32
    Thanked 2 Times in 2 Posts
    Thanks All
    Xfire: romain88120 and energyfun !!

Posting Permissions

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