Created
September 27, 2016 07:47
-
-
Save dbjorkholm/87c20ef3223c649a8a73e807344f21e7 to your computer and use it in GitHub Desktop.
[TFS 1.x] KD Ratio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 91cb163ade94b80abe4a31d8b7cea2cdfea74e97 Tue, 27 Sep 2016 09:45:40 +0200 | |
From: Daniel Björkholm <[email protected]> | |
Date: Tue, 27 Sep 2016 09:45:40 +0200 | |
Subject: [PATCH] [TFS 1.x] KD Ratio | |
--- | |
global.lua | 5 ++++- | |
playedeath.lua | 24 +++++++++++++++++++++++- | |
player.lua | 16 +++++++++++++++- | |
3 files changed, 42 insertions(+), 3 deletions(-) | |
diff --git a/global.lua b/global.lua | |
index 594a5a2..076a05d 100644 | |
--- a/global.lua | |
+++ b/global.lua | |
@@ -1,5 +1,8 @@ | |
dofile('data/lib/lib.lua') | |
+STORAGEVALUE_ASSISTS = 30000 | |
+STORAGEVALUE_DEATHS = 30001 | |
+STORAGEVALUE_KILLS = 30002 | |
STORAGEVALUE_PROMOTION = 30018 | |
ropeSpots = {384, 418, 8278, 8592, 13189, 14435, 14436, 15635, 19518} | |
@@ -47,4 +50,4 @@ end | |
if nextUseStaminaTime == nil then | |
nextUseStaminaTime = {} | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/playedeath.lua b/playedeath.lua | |
index d9e4630..185443f 100644 | |
--- a/playedeath.lua | |
+++ b/playedeath.lua | |
@@ -1,6 +1,24 @@ | |
local deathListEnabled = true | |
local maxDeathRecords = 5 | |
+local function addAssistsPoints(attackerId, target) | |
+ if not attackerId or type(attackerId) ~= 'number' then | |
+ return | |
+ end | |
+ | |
+ if not target or type(target) ~= 'userdata' or not target:isPlayer() then | |
+ return | |
+ end | |
+ | |
+ local ignoreIds = {attackerId, target:getId()} | |
+ for id in pairs(target:getDamageMap()) do | |
+ local tmpPlayer = Player(id) | |
+ if tmpPlayer and not isInArray(ignoreIds, id) then | |
+ tmpPlayer:setStorageValue(STORAGEVALUE_ASSISTS, math.max(0, tmpPlayer:getStorageValue(STORAGEVALUE_ASSISTS)) + 1) | |
+ end | |
+ end | |
+end | |
+ | |
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified) | |
local playerId = player:getId() | |
if nextUseStaminaTime[playerId] ~= nil then | |
@@ -67,6 +85,10 @@ function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDama | |
end | |
if byPlayer == 1 then | |
+ addAssistsPoints(killer:getId(), player) | |
+ player:setStorageValue(STORAGEVALUE_DEATHS, math.max(0, player:getStorageValue(STORAGEVALUE_DEATHS)) + 1) | |
+ killer:setStorageValue(STORAGEVALUE_KILLS, math.max(0, killer:getStorageValue(STORAGEVALUE_KILLS)) + 1) | |
+ | |
local targetGuild = player:getGuild() | |
targetGuild = targetGuild and targetGuild:getId() or 0 | |
if targetGuild ~= 0 then | |
@@ -86,4 +108,4 @@ function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDama | |
end | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/player.lua b/player.lua | |
index 75e373f..1853209 100644 | |
--- a/player.lua | |
+++ b/player.lua | |
@@ -52,6 +52,14 @@ function Player:onLook(thing, position, distance) | |
end | |
end | |
end | |
+ | |
+ if thing:isCreature() then | |
+ if thing:isPlayer() then | |
+ local KD = (math.max(0, thing:getStorageValue(STORAGEVALUE_KILLS)) + math.max(0, thing:getStorageValue(STORAGEVALUE_ASSISTS))) / math.max(1, thing:getStorageValue(STORAGEVALUE_DEATHS)) | |
+ description = string.format("%s\nKD: [%0.2f]", description, KD) | |
+ end | |
+ end | |
+ | |
self:sendTextMessage(MESSAGE_INFO_DESCR, description) | |
end | |
@@ -74,6 +82,12 @@ function Player:onLookInBattleList(creature, distance) | |
description = string.format("%s\nIP: %s", description, Game.convertIpToString(creature:getIp())) | |
end | |
end | |
+ | |
+ if creature:isPlayer() then | |
+ local KD = (math.max(0, creature:getStorageValue(STORAGEVALUE_KILLS)) + math.max(0, creature:getStorageValue(STORAGEVALUE_ASSISTS))) / math.max(1, creature:getStorageValue(STORAGEVALUE_DEATHS)) | |
+ description = string.format("%s\nKD: [%0.2f]", description, KD) | |
+ end | |
+ | |
self:sendTextMessage(MESSAGE_INFO_DESCR, description) | |
end | |
@@ -179,4 +193,4 @@ function Player:onGainSkillTries(skill, tries) | |
return tries * configManager.getNumber(configKeys.RATE_MAGIC) | |
end | |
return tries * configManager.getNumber(configKeys.RATE_SKILL) | |
-end | |
\ No newline at end of file | |
+end | |
-- | |
2.6.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment