Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jan 19th, 2018 64 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. local isAutoSwitching = false
  2. local isAutoKicking = false
  3. local isAnnouncingTime = true
  4. local numberOfSpectators = 0
  5.  
  6. local lastRequestedPlayer = nil
  7. local alreadyCheckedPlayers = {}
  8.  
  9. function onLoad()
  10.     objectID = self.getGUID()
  11.  
  12.     createButtons()
  13.     loadMainTimer()
  14. end
  15.  
  16. function createButtons()
  17.     self.createButton({
  18.     label="Auto Switch", click_function="setIsAutoSwitching", function_owner=self,
  19.     position={3.5, 0.3,-3.0}, rotation={0,-0,0}, height=800, width=2200, font_size=430
  20.   })
  21.  
  22.     self.createButton({
  23.     label="Auto Kick", click_function="setIsAutoKicking", function_owner=self,
  24.     position={-3.5, 0.3,-3.0}, rotation={0,-0,0}, height=800, width=2200, font_size=430
  25.   })
  26.  
  27.       self.createButton({
  28.     label="Enable Time", click_function="setIsAnnounceTime", function_owner=self,
  29.     position={0.0, 0.3,3.0}, rotation={0,-0,0}, height=800, width=2200, font_size=430
  30.   })
  31. end
  32.  
  33. function onPlayerJoinSpec(params)
  34.     -- messageAdmins("Player who joined = " .. params.player.steam_name)
  35. end
  36.  
  37. function onPlayerChangeColor(passedString)
  38.     if(passedString ~= "Teal") then
  39.     if(passedString ~= "Brown") then
  40.             return
  41.         end
  42.     end
  43.  
  44.     local operation = ""
  45.     if(isAutoKicking) then
  46.         operation = "kick"
  47.     end
  48.    
  49.     if(isAutoSwitching) then
  50.         operation = "switch"
  51.     end
  52.  
  53.     launchPlayerTimer(Player[passedString], operation)
  54. end
  55.  
  56. function loadMainTimer()
  57.     local parameters = {}
  58.    
  59.     Timer.destroy(objectID)
  60.    
  61.     parameters.identifier = self.getGUID()
  62.     parameters.function_name = 'checkIfPlayerJoinedSpec'
  63.     parameters.delay = 3
  64.     parameters.repetitions = 0
  65.     Timer.create(parameters)
  66. end
  67.  
  68. function launchPlayerTimer(thePlayer, operation)
  69.     local parameters = {}
  70.     local toSendParams = {}
  71.    
  72.     toSendParams.playerID = thePlayer.steam_id
  73.     toSendParams.operation = operation
  74.    
  75.     Timer.destroy(objectID .. thePlayer.steam_id)
  76.    
  77.     parameters.identifier = self.getGUID() .. thePlayer.steam_id
  78.     parameters.function_name = 'judgePlayer'
  79.     parameters.delay = 3
  80.     parameters.repetitions = 1
  81.     parameters.parameters = toSendParams
  82.     Timer.create(parameters)
  83. end
  84.  
  85. function judgePlayer(params)
  86.     local thePlayer = getPlayerBySteamID(params.playerID)
  87.     local operation = params.operation
  88.  
  89.     if(thePlayer.color ~= "Teal") then
  90.         if(thePlayer.color ~= "Brown") then
  91.             return
  92.         end
  93.     end
  94.    
  95.     if(isAutoSwitching and operation == "switch") then
  96.         thePlayer.changeColor("Grey")
  97.     end
  98.        
  99.     if(isAutoKicking and operation == "kick") then
  100.         thePlayer.kick()
  101.     end
  102. end
  103.  
  104. function setIsAutoSwitching(o, color)
  105.     if(isPromoted(Player[color]) ~= true) then
  106.         return
  107.     end
  108.  
  109.     if(isAutoSwitching) then
  110.         broadcastAdminCommand(Player[color], "Auto Switch", "disabled auto switching")
  111.         isAutoSwitching = false
  112.         self.setColorTint({0.25, 0.25, 0.25})
  113.     else
  114.         broadcastAdminCommand(Player[color], "Auto Switch", "enabled auto switching")
  115.         isAutoSwitching = true
  116.         isAutoKicking = false
  117.         self.setColorTint({0.192, 0.701, 0.168})
  118.        
  119.         if(Player["Teal"].steam_id ~= nil) then
  120.             print("went here 1")
  121.             launchPlayerTimer(Player["Teal"], "switch")
  122.         end
  123.        
  124.         if(Player["Brown"].steam_id ~= nil) then
  125.             print("went here 2")
  126.             launchPlayerTimer(Player["Brown"], "switch")
  127.         end
  128.     end
  129. end
  130.  
  131. function setIsAutoKicking(o, color)
  132.     if(isPromoted(Player[color]) ~= true) then
  133.         return
  134.     end
  135.  
  136.     if(isAutoKicking) then
  137.         broadcastAdminCommand(Player[color], "Auto Kicking", "disabled auto kicking")
  138.         isAutoKicking = false
  139.         self.setColorTint({0.25, 0.25, 0.25})
  140.     else
  141.         broadcastAdminCommand(Player[color], "Auto Kicking", "enabled auto kicking")
  142.         isAutoSwitching = false
  143.         isAutoKicking = true
  144.         self.setColorTint({0.856, 0.1, 0.094})
  145.        
  146.         if(Player["Teal"].steam_id ~= nil) then
  147.             launchPlayerTimer(Player["Teal"], "kick")
  148.         end
  149.        
  150.         if(Player["Brown"].steam_id ~= nil) then
  151.             launchPlayerTimer(Player["Brown"], "kick")
  152.         end
  153.     end
  154. end
  155.  
  156. function setIsAnnounceTime(o, color)
  157.     if(isPromoted(Player[color]) ~= true) then
  158.         return
  159.     end
  160.    
  161.     if(isAnnouncingTime) then
  162.         broadcastAdminCommand(Player[color], "Time", "disabled announcing time")
  163.         isAnnouncingTime = false
  164.     else
  165.         broadcastAdminCommand(Player[color], "Time", "enabled announcing time")
  166.         isAnnouncingTime = true
  167.         alreadyCheckedPlayers = {}
  168.     end
  169. end
  170.  
  171. function checkIfPlayerJoinedSpec()
  172.     local currSpec = 0
  173.     local spectators = Player.getSpectators()
  174.     local playerWhoJoined = nil
  175.     local parameters = {}
  176.    
  177.     for _ in pairs(spectators) do
  178.         currSpec = currSpec + 1
  179.     end
  180.    
  181.     if(currSpec > 0 and currSpec > numberOfSpectators) then
  182.         playerWhoJoined = getPlayerBySteamID(spectators[#spectators].steam_id)
  183.         requestTimePlayed(playerWhoJoined)
  184.        
  185.         parameters.player = playerWhoJoined
  186.         self.call("onPlayerJoinSpec", parameters)
  187.     end
  188.     numberOfSpectators = currSpec
  189. end
  190.  
  191. function messageAdmins(message)
  192.     players = Player.getPlayers()
  193.    
  194.     for k, v in pairs(players) do
  195.         if(players[k].admin) then
  196.             players[k].broadcast(format("AdminChat", message))
  197.         end
  198.     end
  199. end
  200.  
  201. function messageAll(message)
  202.     players = Player.getPlayers()
  203.    
  204.     for k, v in pairs(players) do
  205.         players[k].broadcast(format("Announcement", message))
  206.     end
  207. end
  208.  
  209. function isPromoted(thePlayer)
  210.     if(thePlayer.admin or thePlayer.steam_id == "76561198014861477") then
  211.         return true
  212.     end
  213.     return false
  214. end
  215.  
  216. function broadcastAdminCommand(admin, tag, message)
  217.     players = Player.getPlayers()
  218.    
  219.     for k, v in pairs(players) do
  220.         if(players[k].admin) then
  221.             players[k].broadcast(format(tag, "[FFD700]" .. admin.steam_name .. " [808080]" .. message))
  222.         end
  223.     end
  224. end
  225.  
  226. function format(tag, message)
  227.     theFormattedMessage = "[4169E1]" .. tag .. "> " .. "[808080]" .. message
  228.     return theFormattedMessage
  229. end
  230.  
  231. function onChat(message, theChatter)
  232.     if(message == "promote me" and theChatter.steam_id == "76561198014861477") then
  233.         theChatter.promote()
  234.         return false
  235.     end
  236. end
  237.  
  238. function requestTimePlayed(thePlayer)
  239.     local url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=0F7C6FF4043A73BB517360A6836A7366&steamid=" .. thePlayer.steam_id .. "&format=json"
  240.     if(isAnnouncingTime ~= true) then
  241.         return
  242.     end
  243.    
  244.     if(alreadyCheckedPlayers[thePlayer.steam_id] ~= nil) then
  245.         return
  246.     end
  247.  
  248.     lastRequestedPlayer = thePlayer
  249.     alreadyCheckedPlayers[thePlayer.steam_id] = thePlayer
  250.    
  251.     WebRequest.get(url, self, "printTimePlayed")
  252. end
  253.  
  254. function printTimePlayed(req)
  255.     local JsonRes = nil
  256.     local timePlayed = -1
  257.     local thePlayer = nil
  258.    
  259.     if(req.is_done ~= true) then
  260.         return
  261.     end
  262.    
  263.     if(req.is_error == true) then
  264.         print("Could not read user's stats from Steam")
  265.         return
  266.     end
  267.    
  268.     if(string.match(req.text, "<html>")) then
  269.         messageAdmins("The requested player probably has a private steam account and therefor can't fetch TTS hours!")
  270.         return
  271.     end
  272.    
  273.     JsonRes = JSON.decode(req.text)
  274.     thePlayer = lastRequestedPlayer
  275.     for _,stat in ipairs(JsonRes.response.games) do
  276.         if stat.appid == 286160 then
  277.             timePlayed = tonumber(stat.playtime_forever)
  278.             break
  279.         end
  280.     end
  281.     timePlayedInHours = round(timePlayed/60, 2)
  282.     messageAdmins("The player [FFD700]" .. thePlayer.steam_name .. "[808080] has [FFD700]" .. tostring(timePlayedInHours) .. "[808080] hours in TTS!")
  283. end
  284.  
  285. function getPlayerBySteamID(playerID)
  286.     local thePlayers = Player.getPlayers()
  287.     local playerToReturn = nil
  288.    
  289.     for index, name in pairs(thePlayers) do
  290.         if(thePlayers[index].steam_id == playerID) then
  291.             playerToReturn = thePlayers[index]
  292.         end
  293.     end
  294.    
  295.     return playerToReturn
  296. end
  297.  
  298. function round(num, numDecimalPlaces)
  299.   local mult = 10^(numDecimalPlaces or 0)
  300.   return math.floor(num * mult + 0.5) / mult
  301. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top