Introduction Instructions Templates Database
Run Calculation Display Mandatory Optional Player Data Message Centre Logfile Substitutions Developer Help
Go f1 Score Weights Real Names Template Variable Config Clan Config Avatar Editing Message Centre Game Type Debug Settings Help
Exit Skill Weights Images Output Config Alias Editing Real Name Editing Message Centre Formats Map Export Template About
Award Editing Server Config Drop List Editing Personal Picture Class
Website Config Banned Speech Editing Clan Role Team
External Database Xfire Weapon
Website Ammo
Miscellaneous 1 Weapon And Ammo
Miscellaneous 2 Location
Action

Templates

StatsGen produces all of it's outputs by processing templates. Templates are essentially HTML files with embedded Code that StatsGen uses to perform actions.

StatsGen code is embedded in $$ symbols, e.g. the following piece of template

<HTML>
<H1>
This is a simple piece of HTML with a StatsGen Template Code embedded
$$player.name$$
See above
</H1>
</HTML>



The default templates are extracted upon installation and placed in the templates folder. They are called full.template and quick.template.By examining these files you will see many of the capabilities and syntax of the template code.

Templates are like a small programming language, you can assign variables, perform functions, and make program flow decisions.

Templates: Variables

Variables are alphanumeric (letters and numbers) tags that hold values. You assign variables values by putting the = character after them. After the = character you can place a literals (value surrounded by " characters), functions or other variables.
e.g.

$$variable1="statsgen"$$
$$variable2=colouredtext2html("^1s^7tats^1g^7en")$$
$$variable3=variable1$$

Sometimes you may wish to embed variables or function results into other StatsGen template code. You do this by surrounding the embedded values with %% characters.
e.g.

$$index="2"$$
$$variable%%index%%="StatsGen%%index%%$$"

This is the equivalent of

$$variable2="StatsGen2"$$

Records retrieved from the database (see the loop command later) can have their fields retrieved by separating the record variable and the field name with a . (dot) character.
e.g.

$$variable1=player.name$$

This sets the variable1 value to the field name of the database record player.
You can also use the column index instead of the field name.
e.g.

$$variable1=player.1$$

This sets the variable1 value to the first field of the database record player.


Writing out the contents of variables or functions is achieved by just specifying their name.
e.g.

$$variable1$$

This writes out the contents of variable1 to the currently open output file.

Templates: Program Flow

StatsGen has two program flow capabilities, if, else, endif and the loop, endloop commands.


if, else and endif


gives you the ability to make decisions based upon variable contents so that you only execute certain sections of templates under specific conditions.

The code is structured as follows.
if (condition)
positive condition code
endif


or

if (condition)
positive condition code
else
negative condition code
endif


condition is in the following form.
variable1 operator variable2
There are 6 operators
EQUALS True if variable1 same as variable2
!EQUALS True if variable1 different from variable2
OR True if variable1 or variable2 are TRUE
AND True if variable1 and variable2 are TRUE
< True if variable1 less than variable2
> True if variable1 greater than variable2
Example

<HTML>
<H1>
$$if (player.name EQUALS "nazarine")$$
This player is Nazarine, worst COD player in the world
$$else$$
Well at least you are not Nazarine
$$endif$$
</H1>
</HTML>

A note on comparisons:
When comparing 2 variables together StatsGen does it's best to determine if the 2 variables are numbers or text. If they are both numbers then it compares them mathematically (2.0 < 10.0) otherwise it compares them alphabetically ("shaun" > "nazarine")

DO NOT forget to close if commands with an associated endif otherwise StatsGen will give you odd results

loop, endloop

Now we are getting to the interesting bits. When StatsGen processes the logfiles it stores the results in a database. The loop command allows you to search that database using SQL statements and step through each record retrieved one at a time.

loop row as <recordvariable> index as <indexvariable> <SQL>

endloop

The SQL is any SELECT statement that SQLITE3 can understand.

Each record retrieved is stored in the recordvariable for later interrogation. The indexvariable gets the current record count (starting at 1) for the loop.

Loops are terminated by endloop.

Forgetting to terminate a loop with endloop could cause unforseen results and make StatsGen run out of resources.

Using a combination of SQL and all the information stored in the database many unique and interesting web pages can be produced, from the very simple to the very complex.

Example

$$openfile playerlist.html$$
<HTML>
<H1>Player List</H1>
$$loop row as player index as playernumber select * from players order by name$$
Player $$playernumber$$ is called $$player.name$$<br>
$$endloop$$
</HTML>
$$closefile$$

Templates: Procedures


Procedures just execute commands but unlike functions, return no values.
Command Format Description Example
include include <templatefile> This tells StatsGen to include another template file at this point in the main template, this is useful for using common pieces of code in multiple places

NOTE: The include statements are executed before ANY other template code and therefore cannot use the results of variables.
<HTML>
<H1> Below are all the maps processed on this server
</H1>
$$include mainpagemaps.html$$
</HTML>
openfile openfile <outputfilename> This tells StatsGen to start writing a new file for output, without at least one file open StatsGen produces no output.
You must remember to close an open file after you have finished with it otherwise StatsGen may run out of resources.
$$openfile "index.html"$$
<HTML>
<H1> Below are all the maps processed on this server
</H1>
$$include mainpagemaps.html$$
</HTML>
$$closefile$$
appendfile appendfile <outputfilename> Same as openfile except if the output file already exists it is just added to rather than started again. $$appendfile "index.html"$$
<HTML>
<H1> Below are all the maps processed on this server
</H1>
$$include mainpagemaps.html$$
</HTML>
$$closefile$$
closefile closefile closes the last opened file, freeing resources. $$openfile "index.html"$$
<HTML>
<H1> Below are all the maps processed on this server
</H1>
$$include mainpagemaps.html$$
</HTML>
$$closefile$$
updatestatus updatestatus(<statustext>) Processing templates can take a long time, it is sometimes useful to give some feedback as to what is going on, the updatestatus command does this by eching back on the status line whatever you put in the statustext <HTML>
<H1> Below are all the maps processed on this server
</H1>
$$updatestatus("Updating Maps")$$
$$include mainpagemaps.html$$
</HTML>
messagecentre messagecentre(key,
variable1
[,variable2]
...
[,variablen]
StatsGen has the ability to send messages to the game server about who is the top at an individual stat (or bottom if you prefer) during processing of templates you need to record these values, this is done via the messagecentre function. Typically the variables are player name followed by score and these get translated to the $1$ and $2$ values in the message centre configuration screens. $$MessageCentre(
"AWARD%%awarddef.name%%",
awardpoints.playername,
awardpoints.awardscore)$$

Templates: Functions / Variables


Functions return a value, typically used as part of writing out the contents of a file or as part of another StatsGen function / command


Function/Variable Format Description Example
colouredtext2html() colouredtext2html(variable) This turns variables into HTML text substituting any ^1, ^2 embedded colour codes with the appropriate HTML font statements to produce coloured webpage output. $$name="^1Naza^7rine"$$
$$colouredtext2html(name)$$
hash() hash(variable) This produces a hashed version of the variable, this is typically used to produce safe filenames from player names etc. $$filename=hash(player.name)$$
$$openfile %%filename%%.html$$
$$colouredtext2html(player.name)$$
$$closefile$$
formatfloat() formatfloat(format,value) this takes a floating point number (fractional number e.g. 3.4) and formats it as you specify. This is done in the standard printf method of embedding a single %f somewhere in the format.
YOU MUST EMBED one and only one %f somewhere in the format or StatsGen WILL CRASH
player score to accurate to 2 decimal places $$formatfloat("%.2f",player.score)$$
formatinteger() formatinteger(format,value) this takes an integer number (whole number e.g. 3) and formats it as you specify. This is done in the standard printf method of embedding a single %d somewhere in the format.
YOU MUST EMBED one and only one %d somewhere in the format or StatsGen WILL CRASH
player score with 7 leading zeros $$formatinteger("%07d",player.score)$$
case() case(sourcevariable,value1,result1
[,value2,result2]
.. [,valuen,resultn])
This takes a variable and returns a different result based upon it's value. You supply a list of paired values and results and if the variable matches a value then the result is returned. $$Case(round_scr_friendlyfire,
"0", "Off",
"1", "On",
"2","Reflective",
"3","Shared")$$
readtemplateconfig() readtemplateconfig(key)
or
readtemplateconfig(key,defaultvalue)
This reads a template configuration variable with or without a default value, It is a good idea to read some values from the template configuration so that your templates are not fixed in format and can be configured by the user of the template. $$listsize=readtemplateconfig("MAXLISTSIZE","500")$$
readconfig() readconfig(key)
or
readconfig(key,defaultvalue)
This reads values from the general config files with or without a default value $$minroundstoplay=readconfig("/General/minroundstoregister")$$
formatdate() formatdate(format,variable) this takes a date in StatsGen and allows you to format the date as you wish. The formatting is as for the standard C strftime() function. $$FormatDate(
"%A %d %B %Y %H:%M:%S",
ReadStatistic("starttime"))$$
formatduration() formatduration(format,variable) This takes a duration in StatsGen and formats it for output.
The following format codes are possible.
%H number of hours
%M number of minutes
%S number of seconds
%I number of milliseconds
%D number of days
%E number of weeks
$$formatduration("%M:%S",
round.duration)$$
uppercase() uppercase(variable) This returns the uppercase equivalent of the variable value $$uppername=uppercase(player.name)$$
lowercase() lowercase(variable) This returns the lowecase equivalent of the variable value $$lowername=lowecase(player.name)$$
readstatistic() readstatistic(variable) This lets you read some of the information about how StatsGen ran. Currently the only one allowed is the time that StatsGen started processing. $$FormatDate(
"%A %d %B %Y %H:%M:%S",
ReadStatistic("starttime"))$$