Resource:Webstats: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Resource page}}
Webstats provides Interesting and Exciting™ statistics about your game server!
Webstats provides Interesting and Exciting™ statistics about your game server!


The question is, what statistics would you like to see? This isn't so much a list of what will be implemented but more to see what people would want to implement so that the system can be flexible enough to cope with it.
==How to use==
Webstats is accessible via HTTP only. Just start webstats and visit ''<nowiki>http://yourserver:port/</nowiki>'' and click Statistics in the resource browser's side bar.


As it stands the stats are stored every X seconds.
==Scripters==
Scripts can register your own stats with the resource, just do something like the following:


* Player count
<syntaxhighlight lang="lua">
* Bullets fired count
call(getResourceFromName("webstats"), "registerStat", getThisResource(), "getBlipCount", "Blips", "The number of blips")
* Marker/blip/object count
function getBlipCount()
* Vehicle explosions
return #getElementsByType("blip");
end
</syntaxhighlight>


Add your own!
The syntax for calling ''registerStat'' is:
<syntaxhighlight lang="lua">
call(getResourceFromName("webstats"), "registerStat", getThisResource(), "yourFunctionName", "Stat name", "Stat description")
</syntaxhighlight>
 
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.
<syntaxhighlight lang="lua">
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
</syntaxhighlight>
 
[[ru:Resource:Webstats]]

Latest revision as of 20:34, 18 May 2012

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