Page 1 of 1

[Mod] Stats [stats]

PostPosted: Mon Dec 30, 2013 01:36
by PilzAdam
Hello everyone!
This mod adds player stats. By default it logs the number of digged and placed nodes, the number of deaths and the played time for each player. It also has an API to make it easy for other mods to add new stats (see below). The stats can be printed with the /stats <playername> command.
This is a side-product of a game that I work on currently.

Depends:
Nothing.

License:
GPL

GitHub:
https://github.com/PilzAdam/stats

Download:
https://github.com/PilzAdam/stats/archive/master.zip

The API:
To add new stats to your mod you first need to add a softdepend on stats (that means your mod will still work without the stats mod!):
Add this to your depends.txt:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
stats?


Then you can use the following methods in your mod, when the stats variable is not nil:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
if stats then
    -- Register the stat, so its printed in the /stats command
    stats.register_stat({
        name = "my_new_stat",
        description = function(value)
            return " - My feature was used " .. value .. " times by the player"
        end,
    })
   
    -- To increase the stat (e.g. when the player digs a node):
    -- player can be either the object, or the playername as string
    stats.increase_stat(player, "my_new_stat", 1)
   
    -- or to set it to a different value:
    stats.set_stat(player, "my_new_stat", 1337)
   
    -- and to read a stat use:
    stats.get_stat(player, "my_new_stat")
end


Server owners:
If you run this mod on your server, and you really care about performance, then you can change the value in line 151 to something higher (like 10 or so), to remove some load from the server. This shouldnt change too much, just added it in case you run a server on a Rasberry PI with 100 players.

Mods that support the stats mod:
Your mod could be here! Post in this topic if you have added support to it.

PostPosted: Mon Dec 30, 2013 08:05
by Krock
I don't have a compatible mod for this yet but I like this.

Something I've found in your codes...
[spoiler=Blah blah]
At line 157 is the timer set to 0. In the next step, it gets added by dtime... am I wrong or is "timer" totally useless in this case?
[/spoiler]

PostPosted: Mon Dec 30, 2013 08:23
by genealanes
hey Philzadam,
can you test my mod?

PostPosted: Mon Dec 30, 2013 08:33
by Linxx
this could give give rpg elements to a server...awesome :3

PostPosted: Mon Dec 30, 2013 08:51
by Pitriss
Krock wrote:I don't have a compatible mod for this yet but I like this.

Something I've found in your codes...
[spoiler=Blah blah]
At line 157 is the timer set to 0. In the next step, it gets added by dtime... am I wrong or is "timer" totally useless in this case?
[/spoiler]


No this seting timer to zero just enforce next cycle of code above.. (increasing stats), timer2 triggers saving of those stats.

PostPosted: Mon Dec 30, 2013 16:09
by PilzAdam
Krock wrote:I don't have a compatible mod for this yet but I like this.

Something I've found in your codes...
[spoiler=Blah blah]
At line 157 is the timer set to 0. In the next step, it gets added by dtime... am I wrong or is "timer" totally useless in this case?
[/spoiler]

PilzAdam wrote:Server owners:
If you run this mod on your server, and you really care about performance, then you can change the value in line 151 to something higher (like 10 or so), to remove some load from the server. This shouldnt change too much, just added it in case you run a server on a Rasberry PI with 100 players.

If you change the 0 to 10, then the timer gets useful, because the played time is only updated every 10 seconds then.

PostPosted: Mon Dec 30, 2013 16:41
by twoelk
Could this be used to find out how many people use which client version?

It might be interesting how many use the latest stable, bleeding edge dev, some old outdated version or even the ratio of windows-apple-linux-other os.

PostPosted: Mon Dec 30, 2013 17:39
by rubenwardy
Nice. I will add this to capture the flag :P

PostPosted: Mon Dec 30, 2013 17:49
by PilzAdam
twoelk wrote:Could this be used to find out how many people use which client version?

It might be interesting how many use the latest stable, bleeding edge dev, some old outdated version or even the ratio of windows-apple-linux-other os.

No, there is no way to do that (except maybe checking protocl versions, but you cant do that in Lua).

PostPosted: Tue Dec 31, 2013 02:14
by Sokomine
Stats sound good. It would be fun to know how many blocks of one type one did dig up on a particular server. And how many blocks of which type where used for actual building. Maybe some ideas from the specialities mod could be merged in somehow. A nice graphical presentation of the statistic will be important in order for players to like it. Such a menu could be made accessible from inventory_plus.

PostPosted: Wed Jan 01, 2014 02:41
by VanessaE
Well here's the first bit of feedback - it crashed ;-)

(twice, actually, same place both times)

No clue why this happened (I wasn't online at the time):

terminate called after throwing an instance of 'ServerError'
what(): ....minetest/worlds/Survival_World/worldmods/stats/init.lua:53: attempt to index local 'player' (a nil value)
stack traceback:
....minetest/worlds/Survival_World/worldmods/stats/init.lua:53: in function 'increase_stat'
....minetest/worlds/Survival_World/worldmods/stats/init.lua:168: in function 'callback'
/usr/local/share/minetest/builtin/falling.lua:96: in function </usr/local/share/minetest/builtin/falling.lua:50>
/home/minetest/Scripts/minetestserver-survival.sh: line 22: 9497 Aborted /usr/local/bin/minetestserver --worldname Survival_World --config /home/minetest/.minetest/minetest-server-survival.conf --gameid vanessae_game --port 30001 --disable-unittests --logfile '/home/minetest/.minetest/debug-survival.txt'

PostPosted: Wed Jan 01, 2014 20:45
by PilzAdam
VanessaE wrote:Well here's the first bit of feedback - it crashed ;-)

(twice, actually, same place both times)

No clue why this happened (I wasn't online at the time):

terminate called after throwing an instance of 'ServerError'
what(): ....minetest/worlds/Survival_World/worldmods/stats/init.lua:53: attempt to index local 'player' (a nil value)
stack traceback:
....minetest/worlds/Survival_World/worldmods/stats/init.lua:53: in function 'increase_stat'
....minetest/worlds/Survival_World/worldmods/stats/init.lua:168: in function 'callback'
/usr/local/share/minetest/builtin/falling.lua:96: in function </usr/local/share/minetest/builtin/falling.lua:50>
/home/minetest/Scripts/minetestserver-survival.sh: line 22: 9497 Aborted /usr/local/bin/minetestserver --worldname Survival_World --config /home/minetest/.minetest/minetest-server-survival.conf --gameid vanessae_game --port 30001 --disable-unittests --logfile '/home/minetest/.minetest/debug-survival.txt'

Fixed.

PostPosted: Wed Jan 01, 2014 20:46
by pandaro
hello PilzAdam.
Looking at your mod I thought it might be nice to add other statistics. I was easily able to create a mod that manages the amount of map explored by a player. It is based on the "minetest.register_on_generated ()". you can see the source code here. Feel free to edit it and put it inside of your mod "statistics" if you find it suitable.

PostPosted: Wed Jan 01, 2014 21:38
by PilzAdam
pandaro wrote:hello PilzAdam.
Looking at your mod I thought it might be nice to add other statistics. I was easily able to create a mod that manages the amount of map explored by a player. It is based on the "minetest.register_on_generated ()". you can see the source code here. Feel free to edit it and put it inside of your mod "statistics" if you find it suitable.

I dont want to bloat the mod too much, so it would be better if you release your mod as a standalone version that depends on stats (see API at first post).

PostPosted: Mon Jan 06, 2014 18:09
by PilzAdam
Update!
It also logs the number of crafted items now.

PostPosted: Mon Jan 06, 2014 18:51
by Krock
PilzAdam wrote:Update!
It also logs the number of crafted items now.

Hand crafted or with autocrafter too? (dumb question)

PostPosted: Mon Jan 06, 2014 19:55
by PilzAdam
Krock wrote:
PilzAdam wrote:Update!
It also logs the number of crafted items now.

Hand crafted or with autocrafter too? (dumb question)

I dont know how the autocrafter works.

PostPosted: Mon Jan 06, 2014 23:25
by keyxmakerx
11:37:21: INFO[main]: Server: Deinitializing scripting
11:37:21: ERROR[main]: ERROR: An unhandled exception occurred: /root/minetest/bin/../mods/stats/init.lua:53: attempt to index local 'player' (a nil value)
11:37:21: ERROR[main]: stack traceback:
11:37:21: ERROR[main]: /root/minetest/bin/../mods/stats/init.lua:53: in function 'increase_stat'
11:37:21: ERROR[main]: /root/minetest/bin/../mods/stats/init.lua:168: in function 'callback'
11:37:21: ERROR[main]: /root/minetest/bin/../builtin/falling.lua:96: in function </root/minetest/bin/../builtin/falling.lua:50>

In thread 7f1486b9e780:
/root/minetest/src/main.cpp:1860: int main(int, char**): Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 7f147bfff700:
#0 virtual void* CurlFetchThread::Thread()
DEBUG STACK FOR THREAD 7f1486b9e780:
#0 int main(int, char**)
(Leftover data: #1 Dedicated server branch)
(Leftover data: #2 virtual void ServerMap::save(ModifiedState))
(Leftover data: #3 virtual void Database_SQLite3::saveBlock(MapBlock*))
root@Minetest:~/minetest/bin#

PostPosted: Tue Jan 07, 2014 10:33
by Pitriss
OMG running MT under root? *runs away*

PostPosted: Tue Jan 07, 2014 16:38
by PilzAdam
keyxmakerx wrote:11:37:21: INFO[main]: Server: Deinitializing scripting
11:37:21: ERROR[main]: ERROR: An unhandled exception occurred: /root/minetest/bin/../mods/stats/init.lua:53: attempt to index local 'player' (a nil value)
11:37:21: ERROR[main]: stack traceback:
11:37:21: ERROR[main]: /root/minetest/bin/../mods/stats/init.lua:53: in function 'increase_stat'
11:37:21: ERROR[main]: /root/minetest/bin/../mods/stats/init.lua:168: in function 'callback'
11:37:21: ERROR[main]: /root/minetest/bin/../builtin/falling.lua:96: in function </root/minetest/bin/../builtin/falling.lua:50>

In thread 7f1486b9e780:
/root/minetest/src/main.cpp:1860: int main(int, char**): Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 7f147bfff700:
#0 virtual void* CurlFetchThread::Thread()
DEBUG STACK FOR THREAD 7f1486b9e780:
#0 int main(int, char**)
(Leftover data: #1 Dedicated server branch)
(Leftover data: #2 virtual void ServerMap::save(ModifiedState))
(Leftover data: #3 virtual void Database_SQLite3::saveBlock(MapBlock*))
root@Minetest:~/minetest/bin#

This was already fixed a week ago, update.