[Mod] Stats [stats]

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

[Mod] Stats [stats]

by PilzAdam » Mon Dec 30, 2013 01:36

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:
Code: Select all
stats?


Then you can use the following methods in your mod, when the stats variable is not nil:
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.
Last edited by PilzAdam on Mon Dec 30, 2013 01:40, edited 1 time in total.
 

User avatar
Krock
Developer
 
Posts: 4144
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

by Krock » Mon Dec 30, 2013 08:05

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]
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

genealanes
New member
 
Posts: 1
Joined: Mon Dec 30, 2013 08:14

by genealanes » Mon Dec 30, 2013 08:23

hey Philzadam,
can you test my mod?
 

User avatar
Linxx
Member
 
Posts: 406
Joined: Wed May 16, 2012 00:37

by Linxx » Mon Dec 30, 2013 08:33

this could give give rpg elements to a server...awesome :3
Last edited by Linxx on Mon Dec 30, 2013 08:33, edited 1 time in total.
 

User avatar
Pitriss
Member
 
Posts: 253
Joined: Mon Aug 05, 2013 17:09
Location: Czech republic, Bohumin
GitHub: Pitriss
IRC: pitriss
In-game: pitriss

by Pitriss » Mon Dec 30, 2013 08:51

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.
I reject your reality and substitute my own. (A. Savage, Mythbusters)
I'm not modding and/or playing minetest anymore. All my mods were released under WTFPL. You can fix/modify them yourself. Don't ask me for support. Thanks.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Mon Dec 30, 2013 16:09

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.
 

twoelk
Member
 
Posts: 1257
Joined: Fri Apr 19, 2013 16:19
Location: northern Germany
GitHub: twoelk
IRC: twoelk
In-game: twoelk

by twoelk » Mon Dec 30, 2013 16:41

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.
 

User avatar
rubenwardy
Moderator
 
Posts: 5541
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Mon Dec 30, 2013 17:39

Nice. I will add this to capture the flag :P
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Mon Dec 30, 2013 17:49

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).
 

Sokomine
Member
 
Posts: 3616
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine

by Sokomine » Tue Dec 31, 2013 02:14

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.
A list of my mods can be found here.
 

User avatar
VanessaE
Moderator
 
Posts: 4315
Joined: Sun Apr 01, 2012 12:38
Location: Waynesville, NC
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE

by VanessaE » Wed Jan 01, 2014 02:41

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'
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (16-512px)
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Jan 01, 2014 20:45

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.
 

User avatar
pandaro
Member
 
Posts: 307
Joined: Sun Jan 08, 2012 21:34
Location: behind
GitHub: pandaro

by pandaro » Wed Jan 01, 2014 20:46

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.
sorry for bad english
Linux debian 7 wheezy 64
kde
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Jan 01, 2014 21:38

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).
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam
 

User avatar
Krock
Developer
 
Posts: 4144
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

by Krock » Mon Jan 06, 2014 18:51

PilzAdam wrote:Update!
It also logs the number of crafted items now.

Hand crafted or with autocrafter too? (dumb question)
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Mon Jan 06, 2014 19:55

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.
 

keyxmakerx
Member
 
Posts: 104
Joined: Mon Apr 08, 2013 23:53

by keyxmakerx » Mon Jan 06, 2014 23:25

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#
 

User avatar
Pitriss
Member
 
Posts: 253
Joined: Mon Aug 05, 2013 17:09
Location: Czech republic, Bohumin
GitHub: Pitriss
IRC: pitriss
In-game: pitriss

by Pitriss » Tue Jan 07, 2014 10:33

OMG running MT under root? *runs away*
I reject your reality and substitute my own. (A. Savage, Mythbusters)
I'm not modding and/or playing minetest anymore. All my mods were released under WTFPL. You can fix/modify them yourself. Don't ask me for support. Thanks.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
Location: Germany
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Tue Jan 07, 2014 16:38

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.
 


Return to Mod Releases



Who is online

Users browsing this forum: sirrobzeroone and 4 guests