Thread: stats
View Single Post
Old 10-28-2010   #5
[TTH]BiZkiT
Registered User
 
Join Date: Sep 2010
Posts: 11
[TTH]BiZkiT is on a distinguished road[TTH]BiZkiT is on a distinguished road
fixed both isues still it doesnt seem to work as soon i have the script loaded and i enter the server it crashes.
In server console there no errors.
This is the whole script so far --
--------------------------------------------------------------------------------
-- Stats
--------------------------------------------------------------------------------

local Kills = {}
local Deaths = {}
vaddCallback("onPlayerConnect", "onPlayerConnect_beer")
function onPlayerConnect_beer(PlayerID)
-- callback
onPlayerConnect(PlayerID)
givePlayerCash(PlayerID,5000)
Kills[strval(PlayerID)] = 0
Deaths[strval(PlayerID)] = 0

-- Random colors upon connection
setPlayerColor(PlayerID,math.random(0,255),math.ra ndom(0,255),math.random(0,255))

-- Connect messages
outputChatBox(PlayerID,'BE SURE TO TYPE "/cmds" TO VIEW THE SERVER COMMANDS!',257,23,13,255)
outputChatBox(PlayerID,'BE SURE TO TYPE "/teles" TO VIEW THE TELEPORT COMMANDS!',252,209,22,255)
end

vaddCallback("onPlayerDeath", "onPlayerDeath_beer")
function onPlayerDeath_beer(PlayerID,KillerID,WeaponID)
-- callback
onPlayerDeath(PlayerID,KillerID,WeaponID)
Deaths[PlayerID] = Deaths[PlayerID] + 1

-- Case for self-kill
if strval(KillerID) == 255 then
if WeaponID == 255 then
outputChatBox(getPlayerName(strval(PlayerID)) .. " died.",255,255,0,255)
else
outputChatBox(getPlayerName(strval(PlayerID)) .. " died. (" .. getWeaponName(strval(WeaponID)) .. ")",255,255,0,255)
end
return
end
outputChatBox(getPlayerName(strval(KillerID)) .. " killed " .. getPlayerName(strval(PlayerID)) .. ". (" .. getWeaponName(strval(WeaponID)) .. ")",255,255,0,255)

-- Increase the score
local Score = strval(getPlayerScore(strval(KillerID)))
setPlayerScore(KillerID,Score + 1)
Kills[KillerID] = Kills[KillerID] + 1

-- Give the other player money
if getPlayerCash(PlayerID) > 500 then
givePlayerCash(PlayerID,-Bounty)
outputChatBox(KillerID,"GratZ! You have obtained $" .. BOUNTY .. " for your kill!",124,252,0,255)
givePlayerCash(KillerID,Bounty)
else
if getPlayerCash(PlayerID) == 0 then
outputChatBox(KillerID,"Your opponent is poor you have not received any money this time!. :-(",227,23,13,255)
else
outputChatBox(KillerID,"GratZ! You have obtained $" .. getPlayerCash(PlayerID) .. " for your kill!",124,252,0,255)
end
givePlayerCash(KillerID,getPlayerCash(PlayerID))
setPlayerCash(PlayerID,0)
end
end

function Stats(PlayerID,OptionalOtherPlayer)
if OptionalOtherPlayer == nil then -- They entered nothing for the parameter
local Ratio = 0
if Deaths[PlayerID] == 0 then
if Kills[PlayerID] == 0 then
Ratio = 1
else
Ratio = Kills[PlayerID]
end
else
Ratio = (((Kills[PlayerID]) / (Deaths[PlayerID])) / 100.0) * 100
end
outputChatBox(PlayerID, "Your stats are: [Kills: " .. Kills[PlayerID] .. " || Deaths: " .. Deaths[PlayerID] .. " || Ratio: " .. Ratio .. "]",255,255,0,255)
else
local Player = strval(OptionalOtherPlayer)
if Deaths[PlayerID] == 0 then
if Kills[Player] == 0 then
Ratio = 1
else
Ratio = Kills[Player]
end
else
Ratio = (((Kills[Player]) / (Deaths[Player])) / 100.0) * 100
end
outputChatBox(PlayerID, getPlayerName(Player) .. "'s stats are: [Kills: " .. Kills[Player] .. " || Deaths: " .. Deaths[Player] .. " || Ratio: " .. Ratio .. "]",255,255,0,255)
end
end

addCommand("stats","Stats")

function TopScore(PlayerID)
local TopPlayerKillID = -1
local TopPlayerRatioID = -1
local TopKills = 0
local TopRatio = 0

-- Loop through all of the players
for i = 0, 100 do
if isPlayerConnected(i) == 1 then
local Player = strval(i)
local Ratio = 0
if Deaths[Player] == 0 then
if Kills[Player] == 0 then
Ratio = 1
else
Ratio = Kills[Player]
end
else
Ratio = (((Kills[Player]) / (Deaths[Player])) / 100.0) * 100
end
if Ratio > TopRatio then
TopPlayerRatioID = Player
TopRatio = Ratio
end
if Kills[Player] > TopKills then
TopKills = Kills[Player]
TopPlayerKillID = Player
end
end
end

-- Double check
for i = 0, 100 do
if isPlayerConnected(i) == 1 then
local Player = strval(i)
local Ratio = 0
if Deaths[Player] == 0 then
if Kills[Player] == 0 then
Ratio = 1
else
Ratio = Kills[Player]
end
else
Ratio = (((Kills[Player]) / (Deaths[Player])) / 100.0) * 100
end
local Found = false
if Ratio == TopRatio and Player ~= TopPlayerRatioID then
TopPlayerRatioID = -1
Found = true
end
if Kills[Player] == TopKills and Player ~= TopPlayerKillID then
TopPlayerKillID = -1
Found = true
end
if Found == true then break end
end
end

-- Now output
local TopKillName = "N/A"
local TopNameRatio = "N/A"

if TopPlayerKillID > -1 then TopKillName = getPlayerName(strval(TopPlayerKillID)) end
if TopPlayerRatioID > -1 then TopNameRatio = getPlayerName(strval(TopPlayerRatioID)) end

outputChatBox(PlayerID,"Leaderboard: [Top Kills: " .. TopKillName .. " || Top Ratio: " .. TopNameRatio .. "]",255,255,0,255)
end

addCommand("top","TopScore")

oh and the space after the a comes if i copy it here its not in the script

Last edited by [TTH]BiZkiT; 10-28-2010 at 05:50 PM.. Reason: auto-merged double post
[TTH]BiZkiT is offline   Reply With Quote