Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local isAutoSwitching = false
- local isAutoKicking = false
- local isAnnouncingTime = true
- local numberOfSpectators = 0
- local lastRequestedPlayer = nil
- local alreadyCheckedPlayers = {}
- function onLoad()
- objectID = self.getGUID()
- createButtons()
- loadMainTimer()
- end
- function createButtons()
- self.createButton({
- label="Auto Switch", click_function="setIsAutoSwitching", function_owner=self,
- position={3.5, 0.3,-3.0}, rotation={0,-0,0}, height=800, width=2200, font_size=430
- })
- self.createButton({
- label="Auto Kick", click_function="setIsAutoKicking", function_owner=self,
- position={-3.5, 0.3,-3.0}, rotation={0,-0,0}, height=800, width=2200, font_size=430
- })
- self.createButton({
- label="Enable Time", click_function="setIsAnnounceTime", function_owner=self,
- position={0.0, 0.3,3.0}, rotation={0,-0,0}, height=800, width=2200, font_size=430
- })
- end
- function onPlayerJoinSpec(params)
- -- messageAdmins("Player who joined = " .. params.player.steam_name)
- end
- function onPlayerChangeColor(passedString)
- if(passedString ~= "Teal") then
- if(passedString ~= "Brown") then
- return
- end
- end
- local operation = ""
- if(isAutoKicking) then
- operation = "kick"
- end
- if(isAutoSwitching) then
- operation = "switch"
- end
- launchPlayerTimer(Player[passedString], operation)
- end
- function loadMainTimer()
- local parameters = {}
- Timer.destroy(objectID)
- parameters.identifier = self.getGUID()
- parameters.function_name = 'checkIfPlayerJoinedSpec'
- parameters.delay = 3
- parameters.repetitions = 0
- Timer.create(parameters)
- end
- function launchPlayerTimer(thePlayer, operation)
- local parameters = {}
- local toSendParams = {}
- toSendParams.playerID = thePlayer.steam_id
- toSendParams.operation = operation
- Timer.destroy(objectID .. thePlayer.steam_id)
- parameters.identifier = self.getGUID() .. thePlayer.steam_id
- parameters.function_name = 'judgePlayer'
- parameters.delay = 3
- parameters.repetitions = 1
- parameters.parameters = toSendParams
- Timer.create(parameters)
- end
- function judgePlayer(params)
- local thePlayer = getPlayerBySteamID(params.playerID)
- local operation = params.operation
- if(thePlayer.color ~= "Teal") then
- if(thePlayer.color ~= "Brown") then
- return
- end
- end
- if(isAutoSwitching and operation == "switch") then
- thePlayer.changeColor("Grey")
- end
- if(isAutoKicking and operation == "kick") then
- thePlayer.kick()
- end
- end
- function setIsAutoSwitching(o, color)
- if(isPromoted(Player[color]) ~= true) then
- return
- end
- if(isAutoSwitching) then
- broadcastAdminCommand(Player[color], "Auto Switch", "disabled auto switching")
- isAutoSwitching = false
- self.setColorTint({0.25, 0.25, 0.25})
- else
- broadcastAdminCommand(Player[color], "Auto Switch", "enabled auto switching")
- isAutoSwitching = true
- isAutoKicking = false
- self.setColorTint({0.192, 0.701, 0.168})
- if(Player["Teal"].steam_id ~= nil) then
- print("went here 1")
- launchPlayerTimer(Player["Teal"], "switch")
- end
- if(Player["Brown"].steam_id ~= nil) then
- print("went here 2")
- launchPlayerTimer(Player["Brown"], "switch")
- end
- end
- end
- function setIsAutoKicking(o, color)
- if(isPromoted(Player[color]) ~= true) then
- return
- end
- if(isAutoKicking) then
- broadcastAdminCommand(Player[color], "Auto Kicking", "disabled auto kicking")
- isAutoKicking = false
- self.setColorTint({0.25, 0.25, 0.25})
- else
- broadcastAdminCommand(Player[color], "Auto Kicking", "enabled auto kicking")
- isAutoSwitching = false
- isAutoKicking = true
- self.setColorTint({0.856, 0.1, 0.094})
- if(Player["Teal"].steam_id ~= nil) then
- launchPlayerTimer(Player["Teal"], "kick")
- end
- if(Player["Brown"].steam_id ~= nil) then
- launchPlayerTimer(Player["Brown"], "kick")
- end
- end
- end
- function setIsAnnounceTime(o, color)
- if(isPromoted(Player[color]) ~= true) then
- return
- end
- if(isAnnouncingTime) then
- broadcastAdminCommand(Player[color], "Time", "disabled announcing time")
- isAnnouncingTime = false
- else
- broadcastAdminCommand(Player[color], "Time", "enabled announcing time")
- isAnnouncingTime = true
- alreadyCheckedPlayers = {}
- end
- end
- function checkIfPlayerJoinedSpec()
- local currSpec = 0
- local spectators = Player.getSpectators()
- local playerWhoJoined = nil
- local parameters = {}
- for _ in pairs(spectators) do
- currSpec = currSpec + 1
- end
- if(currSpec > 0 and currSpec > numberOfSpectators) then
- playerWhoJoined = getPlayerBySteamID(spectators[#spectators].steam_id)
- requestTimePlayed(playerWhoJoined)
- parameters.player = playerWhoJoined
- self.call("onPlayerJoinSpec", parameters)
- end
- numberOfSpectators = currSpec
- end
- function messageAdmins(message)
- players = Player.getPlayers()
- for k, v in pairs(players) do
- if(players[k].admin) then
- players[k].broadcast(format("AdminChat", message))
- end
- end
- end
- function messageAll(message)
- players = Player.getPlayers()
- for k, v in pairs(players) do
- players[k].broadcast(format("Announcement", message))
- end
- end
- function isPromoted(thePlayer)
- if(thePlayer.admin or thePlayer.steam_id == "76561198014861477") then
- return true
- end
- return false
- end
- function broadcastAdminCommand(admin, tag, message)
- players = Player.getPlayers()
- for k, v in pairs(players) do
- if(players[k].admin) then
- players[k].broadcast(format(tag, "[FFD700]" .. admin.steam_name .. " [808080]" .. message))
- end
- end
- end
- function format(tag, message)
- theFormattedMessage = "[4169E1]" .. tag .. "> " .. "[808080]" .. message
- return theFormattedMessage
- end
- function onChat(message, theChatter)
- if(message == "promote me" and theChatter.steam_id == "76561198014861477") then
- theChatter.promote()
- return false
- end
- end
- function requestTimePlayed(thePlayer)
- local url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=0F7C6FF4043A73BB517360A6836A7366&steamid=" .. thePlayer.steam_id .. "&format=json"
- if(isAnnouncingTime ~= true) then
- return
- end
- if(alreadyCheckedPlayers[thePlayer.steam_id] ~= nil) then
- return
- end
- lastRequestedPlayer = thePlayer
- alreadyCheckedPlayers[thePlayer.steam_id] = thePlayer
- WebRequest.get(url, self, "printTimePlayed")
- end
- function printTimePlayed(req)
- local JsonRes = nil
- local timePlayed = -1
- local thePlayer = nil
- if(req.is_done ~= true) then
- return
- end
- if(req.is_error == true) then
- print("Could not read user's stats from Steam")
- return
- end
- if(string.match(req.text, "<html>")) then
- messageAdmins("The requested player probably has a private steam account and therefor can't fetch TTS hours!")
- return
- end
- JsonRes = JSON.decode(req.text)
- thePlayer = lastRequestedPlayer
- for _,stat in ipairs(JsonRes.response.games) do
- if stat.appid == 286160 then
- timePlayed = tonumber(stat.playtime_forever)
- break
- end
- end
- timePlayedInHours = round(timePlayed/60, 2)
- messageAdmins("The player [FFD700]" .. thePlayer.steam_name .. "[808080] has [FFD700]" .. tostring(timePlayedInHours) .. "[808080] hours in TTS!")
- end
- function getPlayerBySteamID(playerID)
- local thePlayers = Player.getPlayers()
- local playerToReturn = nil
- for index, name in pairs(thePlayers) do
- if(thePlayers[index].steam_id == playerID) then
- playerToReturn = thePlayers[index]
- end
- end
- return playerToReturn
- end
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult + 0.5) / mult
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement