Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***************INFORMATION***************
- // Player Info Library uScript Remake of https://harbor.rocketmod.net/plugins/player-info-library/
- // Created By: Modern_Mo#2947
- // Command: /info (Player Name or SteamID)
- // Requires MySQL
- // If you already use Player Info Lib from RocketMod it will use the same playerinfo table
- // All data is stored the same as Player Info Lib
- // IP is converted into a Decimal Value
- // ******Config START******
- // Interval is in Seconds of when the playtime is saved periodically incase of server crash
- // Do not set the interval to less than 900 seconds (15 minutes) or you will lag the server. Default = 1800 seconds (30 minutes)
- // This does seem to give a lag spike, you may optionally remove this onInterval event.
- saveInterval = 1800;
- // ******Config END******
- // Auto Save Event
- event onInterval(saveInterval){
- connectedPlayers = server.players[0];
- foreach (player in connectedPlayers) {
- logger.log(player.id);
- database.execute("UPDATE `playerinfo` SET TotalPlayTime = TotalPlayTime + UNIX_TIMESTAMP(NOW()) - LastLoginGlobal, LastLoginGlobal = UNIX_TIMESTAMP(NOW()) WHERE SteamID = '" + player.id + "';");
- }
- }
- // Player Joined Event Initialization
- event onPlayerJoined(player){
- logger.log(player.id);
- ipSpliced = toString(player.ip).split(".");
- w = 16777216*toInt(ipSpliced[0]);
- x = 65536*toInt(ipSpliced[1]);
- y = 256*toInt(ipSpliced[2]);
- z = toInt(ipSpliced[3]);
- ipInt = w + x + y + z;
- 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;");
- }
- // Load Event Connect Player Initialization
- event onLoad{
- 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;");
- connectedPlayers = server.players[0];
- foreach (player in connectedPlayers) {
- logger.log(player.id);
- ipSpliced = toString(player.ip).split(".");
- w = 16777216*toInt(ipSpliced[0]);
- x = 65536*toInt(ipSpliced[1]);
- y = 256*toInt(ipSpliced[2]);
- z = toInt(ipSpliced[3]);
- ipInt = w + x + y + z;
- 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;");
- }
- }
- // Quit Event Playtime Save
- event onPlayerQuit(player){
- database.execute("UPDATE `playerinfo` SET TotalPlayTime = TotalPlayTime + UNIX_TIMESTAMP(NOW()) - LastLoginGlobal, LastLoginGlobal = UNIX_TIMESTAMP(NOW()), IsOnline = 0 WHERE SteamID = '" + player.id + "';");
- }
- // Unload Event Playtime Save
- event onUnload{
- connectedPlayers = server.players[0];
- foreach (player in connectedPlayers) {
- logger.log(1);
- database.execute("UPDATE `playerinfo` SET TotalPlayTime = TotalPlayTime + UNIX_TIMESTAMP(NOW()) - LastLoginGlobal, LastLoginGlobal = UNIX_TIMESTAMP(NOW()), IsOnline = 0 WHERE SteamID = '" + player.id + "';");
- }
- }
- // Function for /Info
- function playedTimeCalc(secs){
- days = secs / 86400;
- days = toString(days).split(".");
- days = toInt(days[0]);
- //logger.log("Days: " + days);
- hours = days * 86400;
- hours = secs - hours;
- hours = hours / 3600;
- hours = toString(hours).split(".");
- hours = toInt(hours[0]);
- //logger.log("Hours: " + hours);
- minutes = days * 86400;
- hourcalc = hours * 3600;
- minutes = minutes - hourcalc;
- minutes = secs + minutes;
- minutes = minutes / 60;
- minutes = toString(minutes).split(".");
- minutes = toInt(minutes[0]);
- //logger.log("Minutes: " + minutes);
- dayscalc = days * 86400;
- minutescalc = minutes * 60;
- seconds = dayscalc + hourcalc;
- seconds = seconds + minutescalc;
- seconds = secs - seconds;
- seconds = toString(seconds).split(".");
- seconds = toInt(seconds[0]);
- //logger.log("Seconds: " + seconds);
- if (days > 0) {
- return str.format("{0} Days, {1} Hours, {2} Minutes, {3} Seconds", days, hours, minutes, seconds);
- }
- elseif (hours > 0) {
- return str.format("{0} Hours, {1} Minutes, {2} Seconds", hours, minutes, seconds);
- }
- elseif (minutes > 0) {
- return str.format("{0} Minutes, {1} Seconds", minutes, seconds);
- }
- elseif (seconds > 0) {
- return str.format("{0} Seconds", seconds);
- }
- else{
- return "None";
- }
- }
- // Info Command, Player Info Lib's /investigate
- command investigate(startPlayer){
- permission = "info";
- allowedCaller = "both";
- execute(){
- if (isSet(startPlayer) == false){
- if (isSet(player)){
- player.message("Invalid Arguements, Required: Player Name or SteamID", "red");
- }
- else{
- logger.log("Invalid Arguements, Required: Player Name or SteamID", "red");
- }
- return;
- }
- argPlayer = toPlayer(startPlayer);
- returned = "";
- if (isPlayer(argPlayer)){
- returned = database.execute("SELECT SteamID, SteamName, CharName, IP, FROM_UNIXTIME(LastLoginGlobal), TotalPlayTime FROM playerinfo WHERE SteamID = '" + argPlayer.id + "';");
- playerinfo = returned[0];
- if (isSet(player)){
- player.message(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
- }
- else{
- logger.log(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
- }
- return;
- }
- elseif (toString(startPlayer).contains("7656119")){
- returned = database.execute("SELECT SteamID, SteamName, CharName, IP, FROM_UNIXTIME(LastLoginGlobal), TotalPlayTime FROM playerinfo WHERE SteamID = '" + startPlayer + "';");
- playerinfo = returned[0];
- if (isSet(player)){
- player.message(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
- }
- else{
- logger.log(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerinfo[1], playerinfo[0], playerinfo[4], playedTimeCalc(toInt(playerinfo[5]))));
- }
- return;
- }
- returned = database.execute("SELECT SteamID, SteamName, CharName, IP, FROM_UNIXTIME(LastLoginGlobal), TotalPlayTime FROM playerinfo WHERE CharName LIKE '%" + startPlayer + "%' OR SteamName LIKE '%" + startPlayer + "%' LIMIT 11;");
- if (returned.count > 0) {
- if (returned.count > 10){
- if (isSet(player)){
- player.message("Refine your search! Too many Player's found, Maximum 10!", "red");
- }
- else{
- logger.log("Refine your search! Too many Player's found, Maximum 10!");
- }
- }
- else{
- if (isSet(player)){
- player.message(str.format("{0} Players on record for {1}", returned.count, startPlayer), "red");
- }
- else{
- logger.log(str.format("{0} Players on record for {1}", returned.count, startPlayer));
- }
- foreach (playerFound in returned) {
- if (isSet(player)){
- player.message(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerFound[1], playerFound[0], playerFound[4], playedTimeCalc(toInt(playerFound[5]))));
- }
- else{
- logger.log(str.format("Player: {0} <{1}>, Last Login: {2}, Playtime: {3}", playerFound[1], playerFound[0], playerFound[4], playedTimeCalc(toInt(playerFound[5]))));
- }
- }
- }
- }
- else{
- if (isSet(player)){
- player.message("No player found (" + startPlayer + ")");
- }
- else{
- logger.log("No player found (" + startPlayer + ")");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement