How would i go about monitoring the length of players lives and store each one and calculate the average life expectancy. If you can provide code example of similar things or for what i want i shall <3 forever
Listen to onjoin onleave ondeath events. Create a timestamp when each of those occurs. If onleave you take the onleave-onjoin timestamp and you get the time the player has been alive while on the server. Store this variable somewhere. Perhaps a map or list with the playername as key and the timestamp as value. Add the timestamp each time the player joins and leaves. Incase of a ondeath event you take the (ondeath - onjoin) + timealive and store that in another list. Then you can calculate the average by calculating the average from the last list
declanmc96 You could get how long they lived for per death then work out an average on all the times. Jozeth: Deaths (minutes): - 5 - 6 - 4 (5+6+4)/3 = 5 minutes is their average life expectancy.
Thx for the quick reply, i want something like minez life thing but i cant thinks of how to do it without it make a file huge would MySQL make it big if you just stored the time lived
Code: long join,death,leave; Map<String, Integer> aliveTime Map<String, Integer> deathTime onJoin(Event e){ join = System.currentTimeMillis() / 1000L; } onLeave(Event e){ leave = (System.currentTimeMillis() / 1000L)-join; aliveTime.put(e.getPlayer().getListName(),leave) } onDeath(Event e){ death = (System.currentTimeMillis() / 1000L)-join; death + aliveTime.get(e.getPlayer().getListName()); deathTime.put(e.getPlayer().getListName,death); } calcDeath(){ //Iterate the deathTime Map and calculate the average from the values } Try something like this, note this is just pseudo code
Depends some admins like databases whilst some like files. It's up to you tbh. But if you do get tons of players and tons of deaths then it will get large.
If you are only gonna need it locally use a sqlitedb It's just pseudo code to get him started EDIT by Moderator: merged posts, please use the edit button instead of double posting.
for a global life expectancy could you just start a number at zero and add 1 each second then divide it by how many deaths there has been