1

Topic: Clan war stats function

I was bored today, so I decided to make a function that accepted an array as a parameter and outputs a table and statistics. I am lazy, so I will not provide the full documentation. It's included in the php file. I don't see any bugs, but there might be some (fortunately, my php skills are better than my c++ skills big_smile). Feel free to report bugs and suggest new features. With no space between the lines, the function is 40 lines long, while the whole demo is 68 lines long. I added some whitespace for readability, so feel free to remove it.
Features:
*Heavily commented code
*Lightweight function is 40 lines long w/o whitespace or 1.7 kb
*Whole example file is 68 lines w/o whitespace or 2.3kb
*Depends on no external files/libraries
*Indented code
*Returns valid html
*Supports custom class for the table
*Supports custom table name
*Calculates total wars fought, how many of each outcome there were, and percentages of each outcome.
*Licensed under the CC-BY-NC-SA (url provided in the file) to allow extensions.
Download this and rename it to "clan.php" to use it.

if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);

2

Re: Clan war stats function

Maybe you should say something about what to use this on, and how?

I had a quick look at the code, and didn't find any obvious errors (not that I really looked for them ether).

Good work.

Used to be very active waay back

3

Re: Clan war stats function

hm, i looked a little over the code, but i think for getting the stuff in exactly such an array needs the same time like programming something like that for the own data-structure.

4

Re: Clan war stats function

A good solution would be to make a minimal patch which outputs a message ( dbg_msg() ) with a predefined tag u can grep for. Something like this:

/src/game/server/gs_game.cpp
void gameobject::do_team_score_wincheck()
{
    if(game_over_tick == -1 && !warmup)
    {
        // check score win condition
        if((config.sv_scorelimit > 0 && (teamscore[0] >= config.sv_scorelimit || teamscore[1] >= config.sv_scorelimit)) ||
            (config.sv_timelimit > 0 && (server_tick()-round_start_tick) >= config.sv_timelimit*server_tickspeed()*60))
        {
            if(teamscore[0] != teamscore[1]) {
                endround();
                dbg_msg("win", "%s team has won the round with %d:%d\n", (teamscore[0] > teamscore[1] ? "red" : "blue"), teamscore[0], teamscore[1]); 
            }
            else
                sudden_death = 1;
        }
    }
}

Then you could filter and pipe the servers output to ur script like this

./teeworlds_srv -f blabla.cfg | grep "\[win\]" | php urscript.php

Where ur script reads from stdin and parses the lines. Fcorse this is a lil offtopic but anyway good job.

We will meet again when the flowers spread their glorious scent of victory and the birds sing us the melody of justice...

5 (edited by Roanoke 2008-07-08 17:57:23)

Re: Clan war stats function

@scosu:What would be a better way to provide input? It doesn't really seem to hard to put it in such an array.
@torch:That's a good idea, however, it would require a database to be any good. This function was primarily meant for use in a website, like you want a page with your clanwar stats. Of course, you could use a database here too.

if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);

6

Re: Clan war stats function

i don't know. But as a programmer it is faster for you, if you make such little functions on your own, because you have to work in the code a little to understand what is required and can integrate your own stuff better. As a normal user, you can't do anything with this function, it produces only a table structure and needs an array and a complete html-site for integration.

perhaps you can make something bigger. And think about the people who should use it. think about what they want. users need simple and fast to install programs and programmer need a clear description of what something does.
that's my opinion. and of course i know that the docs are the worst things to do^^

7

Re: Clan war stats function

Hm, I might make it get stuff from a database or parse a string of text formatted in a certain way. Or both big_smile

if($poster["intelligence"] == $intelligence["idiot"])
        deny_post($poster);