Advertisement
Guest User

uScript Player Info Library w/ Online Status

a guest
Dec 12th, 2019
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.05 KB | None | 0 0
  1. // ***************INFORMATION***************
  2. // Player Info Library uScript Remake of https://harbor.rocketmod.net/plugins/player-info-library/
  3. // Created By: Modern_Mo#2947
  4. // Command: /info (Player Name or SteamID)
  5. // Requires MySQL
  6. // If you already use Player Info Lib from RocketMod it will use the same playerinfo table
  7. // All data is stored the same as Player Info Lib
  8. // IP is converted into a Decimal Value
  9.  
  10.  
  11. // ******Config START******
  12.  
  13. // Interval is in Seconds of when the playtime is saved periodically incase of server crash
  14. // Do not set the interval to less than 900 seconds (15 minutes) or you will lag the server. Default = 1800 seconds (30 minutes)
  15. // This does seem to give a lag spike, you may optionally remove this onInterval event.
  16. saveInterval = 1800;
  17.  
  18. // ******Config END******
  19.  
  20.  
  21.  
  22.  
  23.  
  24. // Auto Save Event
  25. event onInterval(saveInterval){
  26. connectedPlayers = server.players[0];
  27. foreach (player in connectedPlayers) {
  28. logger.log(player.id);
  29. database.execute("UPDATE `playerinfo` SET TotalPlayTime = TotalPlayTime + UNIX_TIMESTAMP(NOW()) - LastLoginGlobal, LastLoginGlobal = UNIX_TIMESTAMP(NOW()) WHERE SteamID = '" + player.id + "';");
  30. }
  31. }
  32.  
  33. // Player Joined Event Initialization
  34. event onPlayerJoined(player){
  35. logger.log(player.id);
  36. ipSpliced = toString(player.ip).split(".");
  37. w = 16777216*toInt(ipSpliced[0]);
  38. x = 65536*toInt(ipSpliced[1]);
  39. y = 256*toInt(ipSpliced[2]);
  40. z = toInt(ipSpliced[3]);
  41. ipInt = w + x + y + z;
  42. database.execute("INSERT INTO `playerinfo` (`SteamID`, `SteamName`, `CharName`, `IP`, `LastLoginGlobal`, `TotalPlayTime`, `IsOnline`) VALUES ('" + player.id + "', '" + player.steam.name + "', '" + player.name + "', '" + ipInt + "', UNIX_TIMESTAMP(NOW()), '0', '1') ON DUPLICATE KEY UPDATE LastLoginGlobal = UNIX_TIMESTAMP(NOW()), IP = '" + ipInt + "', CharName = '" + player.name + "', SteamName = '" + player.name + "', IsOnline = 1;");
  43. }
  44.  
  45. // Load Event Connect Player Initialization
  46. event onLoad{
  47. database.execute("CREATE TABLE IF NOT EXISTS `playerinfo` (`SteamID` VARCHAR(50) NULL DEFAULT NULL,`SteamName` TEXT NULL,`CharName` TEXT NULL,`IP` VARCHAR(50) NULL DEFAULT NULL,`LastLoginGlobal` VARCHAR(50) NULL DEFAULT NULL,`TotalPlayTime` INT(11) NULL DEFAULT NULL, `IsOnline` INT NULL)ENGINE=InnoDB;");
  48. connectedPlayers = server.players[0];
  49. foreach (player in connectedPlayers) {
  50. logger.log(player.id);
  51. ipSpliced = toString(player.ip).split(".");
  52. w = 16777216*toInt(ipSpliced[0]);
  53. x = 65536*toInt(ipSpliced[1]);
  54. y = 256*toInt(ipSpliced[2]);
  55. z = toInt(ipSpliced[3]);
  56. ipInt = w + x + y + z;
  57. database.execute("INSERT INTO `playerinfo` (`SteamID`, `SteamName`, `CharName`, `IP`, `LastLoginGlobal`, `TotalPlayTime`, `IsOnline`) VALUES ('" + player.id + "', '" + player.steam.name + "', '" + player.name + "', '" + ipInt + "', UNIX_TIMESTAMP(NOW()), '0', '1') ON DUPLICATE KEY UPDATE LastLoginGlobal = UNIX_TIMESTAMP(NOW()), IP = '" + ipInt + "', CharName = '" + player.name + "', SteamName = '" + player.name + "', IsOnline = 1;");
  58. }
  59. }
  60.  
  61. // Quit Event Playtime Save
  62. event onPlayerQuit(player){
  63. database.execute("UPDATE `playerinfo` SET TotalPlayTime = TotalPlayTime + UNIX_TIMESTAMP(NOW()) - LastLoginGlobal, LastLoginGlobal = UNIX_TIMESTAMP(NOW()), IsOnline = 0 WHERE SteamID = '" + player.id + "';");
  64. }
  65.  
  66. // Unload Event Playtime Save
  67. event onUnload{
  68. connectedPlayers = server.players[0];
  69. foreach (player in connectedPlayers) {
  70. logger.log(1);
  71. database.execute("UPDATE `playerinfo` SET TotalPlayTime = TotalPlayTime + UNIX_TIMESTAMP(NOW()) - LastLoginGlobal, LastLoginGlobal = UNIX_TIMESTAMP(NOW()), IsOnline = 0 WHERE SteamID = '" + player.id + "';");
  72. }
  73. }
  74.  
  75. // Function for /Info
  76. function playedTimeCalc(secs){
  77. days = secs / 86400;
  78. days = toString(days).split(".");
  79. days = toInt(days[0]);
  80. //logger.log("Days: " + days);
  81.  
  82. hours = days * 86400;
  83. hours = secs - hours;
  84. hours = hours / 3600;
  85. hours = toString(hours).split(".");
  86. hours = toInt(hours[0]);
  87. //logger.log("Hours: " + hours);
  88.  
  89. minutes = days * 86400;
  90. hourcalc = hours * 3600;
  91. minutes = minutes - hourcalc;
  92. minutes = secs + minutes;
  93. minutes = minutes / 60;
  94. minutes = toString(minutes).split(".");
  95. minutes = toInt(minutes[0]);
  96. //logger.log("Minutes: " + minutes);
  97.  
  98. dayscalc = days * 86400;
  99. minutescalc = minutes * 60;
  100. seconds = dayscalc + hourcalc;
  101. seconds = seconds + minutescalc;
  102. seconds = secs - seconds;
  103. seconds = toString(seconds).split(".");
  104. seconds = toInt(seconds[0]);
  105. //logger.log("Seconds: " + seconds);
  106.  
  107. if (days > 0) {
  108. return str.format("{0} Days, {1} Hours, {2} Minutes, {3} Seconds", days, hours, minutes, seconds);
  109. }
  110. elseif (hours > 0) {
  111. return str.format("{0} Hours, {1} Minutes, {2} Seconds", hours, minutes, seconds);
  112. }
  113. elseif (minutes > 0) {
  114. return str.format("{0} Minutes, {1} Seconds", minutes, seconds);
  115. }
  116. elseif (seconds > 0) {
  117. return str.format("{0} Seconds", seconds);
  118. }
  119. else{
  120. return "None";
  121. }
  122. }
  123.  
  124. // Info Command, Player Info Lib's /investigate
  125. command investigate(startPlayer){
  126. permission = "info";
  127. allowedCaller = "both";
  128. execute(){
  129. if (isSet(startPlayer) == false){
  130. if (isSet(player)){
  131. player.message("Invalid Arguements, Required: Player Name or SteamID", "red");
  132. }
  133. else{
  134. logger.log("Invalid Arguements, Required: Player Name or SteamID", "red");
  135. }
  136. return;
  137. }
  138. argPlayer = toPlayer(startPlayer);
  139. returned = "";
  140. if (isPlayer(argPlayer)){
  141. returned = database.execute("SELECT SteamID, SteamName, CharName, IP, FROM_UNIXTIME(LastLoginGlobal), TotalPlayTime FROM playerinfo WHERE SteamID = '" + argPlayer.id + "';");
  142. playerinfo = returned[0];
  143. if (isSet(player)){
  144. player.message(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
  145. }
  146. else{
  147. logger.log(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
  148. }
  149. return;
  150. }
  151. elseif (toString(startPlayer).contains("7656119")){
  152. returned = database.execute("SELECT SteamID, SteamName, CharName, IP, FROM_UNIXTIME(LastLoginGlobal), TotalPlayTime FROM playerinfo WHERE SteamID = '" + startPlayer + "';");
  153. playerinfo = returned[0];
  154. if (isSet(player)){
  155. player.message(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
  156. }
  157. else{
  158. logger.log(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
  159. }
  160. return;
  161. }
  162. returned = database.execute("SELECT SteamID, SteamName, CharName, IP, FROM_UNIXTIME(LastLoginGlobal), TotalPlayTime FROM playerinfo WHERE CharName LIKE '%" + startPlayer + "%' OR SteamName LIKE '%" + startPlayer + "%' LIMIT 11;");
  163. if (returned.count > 0) {
  164. if (returned.count > 10){
  165. if (isSet(player)){
  166. player.message("Refine your search! Too many Player's found, Maximum 10!", "red");
  167. }
  168. else{
  169. logger.log("Refine your search! Too many Player's found, Maximum 10!");
  170. }
  171. }
  172. else{
  173. if (isSet(player)){
  174. player.message(str.format("{0} Players on record for {1}", returned.count, startPlayer), "red");
  175. }
  176. else{
  177. logger.log(str.format("{0} Players on record for {1}", returned.count, startPlayer));
  178. }
  179. foreach (playerFound in returned) {
  180. if (isSet(player)){
  181. player.message(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerFound[1], playerFound[0], playerFound[4], playedTimeCalc(toInt(playerFound[5]))));
  182. }
  183. else{
  184. logger.log(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerFound[1], playerFound[0], playerFound[4], playedTimeCalc(toInt(playerFound[5]))));
  185. }
  186. }
  187. }
  188. }
  189. else{
  190. if (isSet(player)){
  191. player.message("No player found (" + startPlayer + ")");
  192. }
  193. else{
  194. logger.log("No player found (" + startPlayer + ")");
  195. }
  196. }
  197. }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement