[Mod] Stats [stats]

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

[Mod] Stats [stats]

by PilzAdam » Post

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: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

I don't have a compatible mod for this yet but I like this.

Something I've found in your codes...
Spoiler
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?
Look, I programmed a bug for you. >> 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 » Post

hey Philzadam,
can you test my mod?

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

by Linxx » Post

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: 254
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss
Location: Czech republic, Bohumin

by Pitriss » Post

Krock wrote:I don't have a compatible mod for this yet but I like this.

Something I've found in your codes...
Spoiler
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?
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
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

Krock wrote:I don't have a compatible mod for this yet but I like this.

Something I've found in your codes...
Spoiler
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?
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: 1482
Joined: Fri Apr 19, 2013 16:19
GitHub: twoelk
IRC: twoelk
In-game: twoelk
Location: northern Germany

by twoelk » Post

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: 6977
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

by rubenwardy » Post

Nice. I will add this to capture the flag :P
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

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

by PilzAdam » Post

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: 4282
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

by Sokomine » Post

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: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

by VanessaE » Post

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 (64-512px)

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

by PilzAdam » Post

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: 327
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

by pandaro » Post

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
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

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
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

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

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

by Krock » Post

PilzAdam wrote:Update!
It also logs the number of crafted items now.
Hand crafted or with autocrafter too? (dumb question)
Look, I programmed a bug for you. >> 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
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

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 » Post

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: 254
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss
Location: Czech republic, Bohumin

by Pitriss » Post

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
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

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.

User avatar
sil_el_mot
Member
Posts: 13
Joined: Sat Feb 11, 2017 17:49
In-game: sil_el_mot

Re: [Mod] Stats [stats]

by sil_el_mot » Post

i tried to add some stats. for example how many mobs a player killed . is there smth like register_on_punchentity or so? or do i have to go right into the code of mobs:redo to achive this

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests