Sueta
[S

[SKRIPT] skTimePlayed - Simple and efficient time counting.

1.1

Script that allows to check how much time a player spent on server.

·Script

skTimePlayed
Simple and efficient.
NOTE: There is no in-build UUID support, you can add it on your own if you want.

Code:

CODE
# skTimePlayed made by Grabsky
#
# I'd recommend adding SQLite/MySQL database for variables with "sktp" prefix
# to make sure your vars won't get delete. (I experienced problems with vars not saving properly in other scripts.)
#
# For better date formating of /lastseen, you can edit your config.sk (line 93 as of SKript 2.4-alpha4, 'dd/MM/yyyy HH:mm:ss' looks great)
#
# Known issues:
# - New players' time can't be check until logout
#
# I do not provide support for that script. It's yours now.

options:  
   # Variable for time played is {_p}
   timeSelf: "&8[&6&lSKTP&8] &7You have played for &6%{_p}%"
   timeOthers: "&8[&6&lSKTP&8] &7This player has played for &6%{_p}%"
   playerNotFound: "&8[&6&lSKTP&8] &cPlayer not found."
  
   # Variable for last seen is {sktp-session::%{_p}%}
   seenOnline: "&8[&6&lSKTP&8] &7This player is &aONLINE&7 since &a%{sktp-session::%{_p}%}%"
   seenOffline: "&8[&6&lSKTP&8] &7This player is &cOFFLINE&7 since &c%{sktp-session::%{_p}%}%"
   seenUsage: "&8[&6&lSKTP&8] &7Usage: &6/lastseen <player>"
  
   noPermissions: "&8[&6&lSKTP&8] &cYou have not enough permissions to  use that command."

on join:
   set {sktp-session::%player%} to now

on quit:
   add difference between {sktp-session::%player%} and now to {sktp-time::%player%}
   set {sktp-session::%player%} to now
  
command /lastseen [<text>]:
   aliases: seen
   permission: sktp.lastseen
   permission message: {@noPermissions}
   trigger:
       if arg 1 is set:
           set {_p} to arg 1 parsed as offlineplayer
           if {sktp-session::%{_p}%} is set:
               if {_p} is online:
                   message {@seenOnline}
               else:
                   message {@seenOffline}
           else:
               message {@playerNotFound}
       else:
           message {@seenUsage}

command /playtime [<text>]:
   aliases: pt, ptime
   permission: sktp.self
   permission message: {@noPermissions}
   trigger:
       if arg 1 is not set:
           set {_p} to (difference between {sktp-session::%player%} and now)
           add {sktp-time::%player%} to {_p}
           set {_p} to "%{_p}%"
           replace all " days" and " day" with "d" in {_p}
           replace all " hours" and " hour" with "h" in {_p}
           replace all " minutes" and " minute" with "min" in {_p}
           replace all " seconds" and " second" with "s" in {_p}
           message {@timeSelf}
       else if arg 1 is set:
           if player has permission "sktp.others":
               set {_a} to arg 1 parsed as offlineplayer
               if {sktp-time::%{_a}%} is set:
                   if {_a} is online:
                       set {_p} to difference between {sktp-session::%{_a}%} and now
                       add {sktp-time::%{_a}%} to {_p}
                       set {_p} to "%{_p}%"
                   else:
                       set {_p} to "%{sktp-time::%{_a}%}%"
                   replace all " days" and " day" with "d" in {_p}
                   replace all " hours" and " hour" with "h" in {_p}
                   replace all " minutes" and " minute" with "min" in {_p}
                   replace all " seconds" and " second" with "s" in {_p}
                   message {@timeOthers}
               else:
                   message {@playerNotFound}
           else:
               message {@noPermissions}

Dependencies:

  • Skript (written using 2.4-alpha4)

Features:

  • Lighweight as possible.
  • Offline players support.
  • Check player's last seen date.

Commands:

  • /playtime [player] - checks your or arg's time spent on online.
  • /lastseen <player> - checks arg's last seen date. (or online since when player is online)

Permissions:

  • sktp.self - possibility to check self play time.
  • sktp.others - possibility to check someone's play time.
  • sktp.lastseen - possibility to check someone's last seen date.

Terms:

  • I do not provide support for this script - you edit it on your own.
  • You can do with that resource whatever you want.

Similar projects

Script →