Resource:Webstats: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 8: Line 8:


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
call(getThisResource(), "registerStat", getThisResource(), "getBlipCount", "Blips", "The number of blips")
call(getResourceFromName("webstats"), "registerStat", getThisResource(), "getBlipCount", "Blips", "The number of blips")
function getBlipCount()
function getBlipCount()
return #getElementsByType("blip");
return #getElementsByType("blip");
Line 16: Line 16:
The syntax for calling ''registerStat'' is:
The syntax for calling ''registerStat'' is:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
call(getThisResource(), "registerStat", getThisResource(), "yourFunctionName", "Stat name", "Stat description")
call(getResourceFromName("webstats"), "registerStat", getThisResource(), "yourFunctionName", "Stat name", "Stat description")
</syntaxhighlight>
</syntaxhighlight>


Line 23: Line 23:
Another example. This example counts the amount of damage done between each call to getDamageCount.
Another example. This example counts the amount of damage done between each call to getDamageCount.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
call(getThisResource(), "registerStat", getThisResource(), "getDamageCount", "Damage Given", "The amount of damage players have taken")
call(getResourceFromName("webstats"), "registerStat", getThisResource(), "getDamageCount", "Damage Given", "The amount of damage players have taken")
damagecount = 0
damagecount = 0
addEventHandler ( "onPlayerDamage",  getRootElement(),  
addEventHandler ( "onPlayerDamage",  getRootElement(),  

Revision as of 19:02, 19 December 2007

Webstats provides Interesting and Exciting™ statistics about your game server!

How to use

Webstats is accessible via HTTP only. Just start webstats and visit http://yourserver:port/ and click Statistics in the resource browser's side bar.

Scripters

Scripts can register your own stats with the resource, just do something like the following:

call(getResourceFromName("webstats"), "registerStat", getThisResource(), "getBlipCount", "Blips", "The number of blips")
function getBlipCount()
	return #getElementsByType("blip");
end

The syntax for calling registerStat is:

call(getResourceFromName("webstats"), "registerStat", getThisResource(), "yourFunctionName", "Stat name", "Stat description")

The function specified will be called every time the stats are updated (by default once a minute). You should return an number value.

Another example. This example counts the amount of damage done between each call to getDamageCount.

call(getResourceFromName("webstats"), "registerStat", getThisResource(), "getDamageCount", "Damage Given", "The amount of damage players have taken")
damagecount = 0
addEventHandler ( "onPlayerDamage",  getRootElement(), 
	function( attacker, attackerweapon, bodypart, loss )
		damagecount = damagecount + loss
	end
)

function getDamageCount()
	local ret = damagecount;
	damagecount = 0;
	return ret;
end