Prev Previous Post   Next Post Next
Old 10-19-2010   #1
[TTH]BiZkiT
Registered User
 
Join Date: Sep 2010
Posts: 11
[TTH]BiZkiT is on a distinguished road[TTH]BiZkiT is on a distinguished road
stats

Hello, i have a problem with a stats script i want to use with VLE but how can i get this to work without having problems with onPlayerConnect and onPlayerDeath functions VLE uses.
This is the stats script:
If someone could help me out would be nice

--------------------------------------------------------------------------------
-- Statistics of Players
--------------------------------------------------------------------------------

local Kills = {}
local Deaths = {}

function onPlayerConnect(PlayerID)
IonPlayerConnect(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,"Welcome to the server, " .. getPlayerName(PlayerID) .. "!",0,255,0,255)
outputChatBox(PlayerID,"BE SURE TO TYPE \"/commands\" TO VIEW THE SERVER'S COMMANDS!",255,255,0,255)
end

function onPlayerDeath(PlayerID,KillerID,WeaponID)
IonPlayerDeath(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,-DEATH_MONEY)
outputChatBox(KillerID,"Congratulations! You have obtained $" .. DEATH_MONEY .. " from your ace kill!",0,255,0,255)
givePlayerCash(KillerID,DEATH_MONEY)
else
if getPlayerCash(PlayerID) == 0 then
outputChatBox(KillerID,"Your opponent is broke and thus you have not received any money. :-(",0,255,0,255)
else
outputChatBox(KillerID,"Congratulations! You have obtained $" .. getPlayerCash(PlayerID) .. " from your ace kill!",0,255,0,255)
end
givePlayerCash(KillerID,getPlayerCash(PlayerID))
setPlayerCash(PlayerID,0)
end
end

function OutputStats(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","OutputStats")

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")
[TTH]BiZkiT is offline   Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -6. The time now is 04:23 AM.