-- Totti's custom leaderboard
print("Leaderboard script version 4.00 loaded")
function onPlayerEntered(newPlayer)
local TKs = Instance.new("IntValue")
TKs.Name = "TeamKills"
TKs.Value = 0
TKs.Parent = newPlayer
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local kills = Instance.new("IntValue")
kills.Name = "Points"
kills.Value = 0
local deaths = Instance.new("IntValue")
deaths.Name = "Points"
deaths.Value = 0
kills.Parent = stats
deaths.Parent = stats
-- VERY UGLY HACK
-- Will this leak threads?
-- Is the problem even what I think it is (player arrived before character)?
while true do
if newPlayer.Character ~= nil then break end
wait(5)
end
local humanoid = newPlayer.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
-- start to listen for new humanoid
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
stats.Parent = newPlayer
end
--function checkTKs(victim, killer)
-- print("CHECK TKS")
-- if (killer == nil) then return end
-- if (victim == killer) then return end
-- if (victim.Team == killer.Team and killer:findFirstChild("TeamKills") ~= nil) then
-- killer.TeamKills.Value = killer.TeamKills.Value + 1
-- print("TK++")
-- show an appropraite msg
-- local msg = Instance.new("Message")
-- if (killer.TeamKills.Value == 1) then msg.Text = "Try not to blox your team mates!" end
-- if (killer.TeamKills.Value == 2) then msg.Text = "WARNING: blox your team, go to jail!" end
-- if (killer.TeamKills.Value > 2) then
-- Jail time
-- msg.Text = "JAIL TIME!"
-- killer.Character.Humanoid.Health = 0
-- end
-- msg.Parent = killer
-- wait(5)
-- msg.Parent = nil
--end
--end
function Send_DB_Event_Died(victim, killer)
-- killer may be nil
local killername = "no one"
if killer ~= nil then killername = killer.Name end
print("DIED EVENT: ", victim.Name, " KILLED by ", killername)
if shared["deaths"] ~= nil then
shared["deaths"](victim, killer)
print("SENT DB DEATH EVENT")
end
end
function Send_DB_Event_Kill(killer, victim)
print("KILL EVENT. ", killer.Name, " BLOXXED ", victim.Name)
if shared["kills"] ~= nil then
shared["kills"](killer, victim)
print("SENT DB KILL EVENT")
end
end
function onHumanoidDied(humanoid, player)
local stats = player:findFirstChild("leaderstats")
if stats ~= nil then
local deaths = stats:findFirstChild("Points")
kills.Value = kills.Value - 5
-- do short dance to try and find the killer
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
--checkTKs(player, killer)
Send_DB_Event_Died(player, killer)
handleKillCount(humanoid, player)
end
end
function onPlayerRespawn(property, player)
-- need to connect to new humanoid
if property == "Character" and player.Character ~= nil then
local humanoid = player.Character.Humanoid
local p = player
local h = humanoid
humanoid.Died:connect(function() onHumanoidDied(h, p) end )
end
end
function getKillerOfHumanoidIfStillInGame(humanoid)
-- returns the player object that killed this humanoid
-- returns nil if the killer is no longer in the game
-- check for kill tag on humanoid - may be more than one - todo: deal with this
local tag = humanoid:findFirstChild("creator")
-- find player with name on tag
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then -- killer still in game
return killer
end
end
return nil
end
function handleKillCount(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if killer ~= nil then
local stats = killer:findFirstChild("leaderstats")
if stats ~= nil then
local kills = stats:findFirstChild("Points")
if killer ~= player then
kills.Value = kills.Value + 10
else
kills.Value = kills.Value - 5
end
Send_DB_Event_Kill(killer, player)
end
end
end
game.Players.ChildAdded:connect(onPlayerEntered)
--------------------------------------------------------------------------------------------------------------------------------------
Thats the leaderboard.
--------------------------------------------------------------------------------------------------------------------------------------
--Totti's Game Script
local game_length = 300 -- every X seconds, end the game, show a message, regen the map, rebalance teams, cause MASSIVE LAG
message = nil
function showMessage(text)
-- This function flashes a message to all players
-- Clear the message with hideMessage()
hideMessage() -- Never show more than one message at a time
if message == nil then message = Instance.new("Message") end -- only make a message if we don't have a message object lying around
message.Text = text
message.Parent = game.Workspace
end
function hideMessage()
if message == nil then return end
message.Parent = nil
end
function clearPlayerInfo()
-- resets KOs and WOs
local players = game.Players:children()
for i = 1, #players do
if (players[i]:findFirstChild("leaderstats") ~= nil) and (players[i].leaderstats.KOs ~= nil) then players[i].leaderstats.KOs.Value = 0 end
if (players[i]:findFirstChild("leaderstats") ~= nil) and (players[i].leaderstats.Wipeouts ~= nil) then players[i].leaderstats.Wipeouts.Value = 0 end
end
end
function getWinnerInfo()
-- returns a string that we display to everyone about who the winner is
-- in case of tie, no one wins. if someone wants to code something better, be my guest.
local highscore = 0
local winner = "No one"
local tie = false
local players = game.Players:children()
for i = 1, #players do
local pscore = -1
if players[i]:findFirstChild("leaderstats") ~= nil then
if players[i].leaderstats.Points ~= nil then
pscore = players[i].leaderstats.Points.Value
end
end
if pscore == highscore then
tie = true
end
if pscore > highscore then
-- new highscore
highscore = pscore
winner = players[i].Name
tie = false
end
end
if tie == true then return "There was a tie. How boring." end
local text = string.format("%s %s %d %s", winner, "wins with", highscore, "points!")
return text
end
function getWinningTeamString()
local red = 0
local blue = 0
local p = game.Players:children()
for i=1,#p do
if (p[i].TeamColor == game.Teams:findFirstChild("Blue zenxers").TeamColor) then
if (p[i]:findFirstChild("leaderstats") ~= nil and p[i].leaderstats.KOs ~= nil) then
blue = blue + p[i].leaderstats.KOs.Value
end
end
if (p[i].TeamColor == game.Teams:findFirstChild("Red zenxons").TeamColor) then
if (p[i]:findFirstChild("leaderstats") ~= nil and p[i].leaderstats.KOs ~= nil) then
red = red + p[i].leaderstats.KOs.Value
end
end
end
if (red == blue) then return "Red and Blue tied. How boring!" end
if (red > blue) then return string.format("Red won the match by %d points!", red - blue) end
return string.format("Blue won the match by %d points!", blue - red)
end
while true do
wait(game_length - 30)
showMessage("30 seconds left until end of game!")
wait(5)
hideMessage()
wait(25)
showMessage("Rebalancing teams and launching new game...")
wait(5)
clearPlayerInfo()
game.Teams:rebalanceTeams()
hideMessage()
end
--------------------------------------------------------------------------------------------------------------------------------------
Thats the game script.