PDA

View Full Version : Players PvP Stats



shadowslayer133
09-06-10, 03:30 PM
I was experimenting with LUA tables and eventually wrote a lua script that stored stats, and displayed stats when requested.

Type #Stats
Typing that will display your kills your deaths and you K/D Ratio
This works well on PvP servers where people are curious on how well they are doing.



TEST_Death = {}
TEST_Kill = {}
TEST_KD = {}
TEST_NAME = {}
local KDMessage = "#stats"

function KillDeath_OnChat(event, plr, message, type, language)

if (message == KDMessage) and (TEST_Death[plr:GetName()] == nil) and (TEST_Kill[plr:GetName()] == nil) then
TEST_Death[plr:GetName()] = 0
TEST_Kill[plr:GetName()] = 0
end

if (message == KDMessage) and (TEST_Kill[plr:GetName()] == nil) then
TEST_Kill[plr:GetName()] = 0

end

if (message == KDMessage) and (TEST_Death[plr:GetName()] == nil) then
TEST_Death[plr:GetName()] = 0

end

if (message == KDMessage) then

TEST_NAME[plr:GetName()] = plr:GetName()
plr:SendBroadcastMessage("|cFF0000FF Stats since last server restart")
plr:SendBroadcastMessage("|cFFFF0000 "..TEST_NAME[plr:GetName()].." Stats")
plr:SendBroadcastMessage("|cFFFFFF00 Kills: "..TEST_Kill[plr:GetName()].."")
plr:SendBroadcastMessage("|cFFFFFF00 Deaths: "..TEST_Death[plr:GetName()].."")
TEST_KD[plr:GetName()] = TEST_Kill[plr:GetName()] / TEST_Death[plr:GetName()]
if (TEST_Death[plr:GetName()] == 0) and (TEST_Kill[plr:GetName()] == 0) then
TEST_KD[plr:GetName()] = 0
end
plr:SendBroadcastMessage("|cFFFFFF00 Kills to deaths ratio: "..TEST_KD[plr:GetName()].."")

end
end

function TEST_Death.OnKillPlayer(event, pPlayer)
TEST_Death[pPlayer:GetName()] = TEST_Death[pPlayer:GetName()] or 0 --assigns the variable to 0 if one doesn't exist
TEST_Death[pPlayer:GetName()] = TEST_Death[pPlayer:GetName()] + 1
pPlayer:SendBroadcastMessage("|cFFADD8E6 You have died "..TEST_Death[pPlayer:GetName()].." times since the server restarted.")
end

function TEST_Kill.OnKillPlayer2(event, pPlayer, pVictim)
TEST_Kill[pPlayer:GetName()] = TEST_Kill[pPlayer:GetName()] or 0
TEST_Kill[pPlayer:GetName()] = TEST_Kill[pPlayer:GetName()] + 1
pPlayer:SendBroadcastMessage("|cFFADD8E6 You have Killed "..TEST_Death[pPlayer:GetName()].." people since the server restarted.")
end


RegisterServerHook(6, TEST_Death.OnKillPlayer)
RegisterServerHook(2, TEST_Kill.OnKillPlayer2)
RegisterServerHook(16, "KillDeath_OnChat")

Fixed 0/0 problem

Dimman
09-06-10, 04:17 PM
Thanks for sharing =)
2 bad i have no rep power left now lol, but i will give you rep when i can & gratz on contributor in 1 rep =)

.SalMAX™
10-06-10, 02:27 AM
Nice Nice.

I will Add You, you're Last reputation so You can Earn that Contributor, hopefully you will be as nice to others as I am to you.

shadowslayer133
10-06-10, 05:49 AM
Thanks Dimarxx

Pedregon
11-06-10, 04:53 AM
Great release, this could be useful when experimenting with armor stats, etc.
+ rep