• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

K.D Ratio Script!

narko

vertrauenswürdig ~
Joined
Oct 19, 2008
Messages
1,317
Solutions
2
Reaction score
132
Location
Unknown
I am looking for a script that consists Kills / Deaths = K / D Ratio

I think it's a script onKill and onDeath that when killing a person frag add a +1 in a table in the database and also when you die ...

And then make a script onLook that kills divide the deaths and so get a number that would be the K / D Ratio.

All this has to do with creatureevents.

Narko.
 
LUA:
--Recording...
function onKill..
     doSetCreatureStorage...
     doSetCreatureStorage...
end

--Printing...
local kills = getCreatureStorage...
local deaths = getCreatureStorage...
print("K/D Ratio: %.2f":format(kills/deaths))
 
LUA:
--Recording...
function onKill..
     doSetCreatureStorage...
     doSetCreatureStorage...
end
 
--Printing...
local kills = getCreatureStorage...
local deaths = getCreatureStorage...
print("K/D Ratio: %.2f":format(kills/deaths))

I'm lost :x
 
Its like Heroes of Newerth, something called KDR a.k.a Kill death ratio, It counts how many time you died, and how many frags have you got, it can be shown when you look at the player, good idea to be in Tibia.
 
PHP:
function onKill(cid, target)	if (isPlayer(target)) then		doSetPlayerStorage(cid, 1000, getPlayerStorage(cid, 1000) + 1)	end	return trueend
function onDeath(cid, ...)	doSetPlayerStorage(cid, 1001, getPlayerStorage(cid, 1001) + 1)	return trueend
function onSay(cid, ...)	doSendAnimatedText(getThingPosition(cid), "K/D Ratio: %.2f":format(getPlayerStorage(cid, 1000) / getPlayerStorage(cid, 1001)), COLOR_BLUE)	return trueend

Try it =) Not tested, and written cu fast.​
 
@Allehopper
1. The editor destroyed your code, try not to preview it before you submit :/
2. You can use onKill only because itll be the killer + the person being killed. (or use onDeath if you want to loop through the deathlist to support multiple attackers)
 
LUA:
function onDeath(cid, corpse, deathList)
	-- Record the death for the person that just died
	local deaths = math.max(getCreatureStorage(cid, 40006), 0)
	doCreatureSetStorage(cid, 40006, deaths + 1)
	
	-- Record the kill for every PLAYER in the deathList
	for _, kid in ipairs(deathList) do
		if(isPlayer(kid))then
			local kills = math.max(getCreatureStorage(kid, 40005), 0)
			doCreatureSetStorage(kid, 40005, kills + 1)
		end
	end
	return true
end


LUA:
function onSay(cid, words, param, channel)
	local kills, deaths = math.max(getCreatureStorage(cid, 40005), 0), math.max(getCreatureStorage(cid, 40006), 1)
	return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your K/D Ratio: %.2f":format(kills/deaths))
end
 
Last edited:
Just incase anyone wants to actually learn how this works. Here's some key parts that alot of people may get lost on.

This function takes numbers (separated by commas) and returns the highest one in the list
LUA:
math.max(1, 2, 7, 5, .02)
output: 7

The function below ("string":format(values...) OR string.format("string", values...)) takes a string and integrates values into it based on the operators used and the variables.
NOTE: %f means a floating number (1.3252). %.2f formats this floating number as (1.33) rounding it to the nearest tenths
LUA:
local milk_oz, napkins = 35.212, 2
"I want %.2f cookies":format(milk_oz/napkins)
output: I want 17.61 cookies
 
LUA:
function onDeath(cid, corpse, deathList)
	return setPlayerStorageValue(cid, 2000, math.max(getPlayerStorageValue(cid, 2000), 1) + 1)
end

function onKill(cid, target)
	return isPlayer(target) and setPlayerStorageValue(cid, 2001, math.max(getPlayerStorageValue(cid, 2001), 1) + 1) or true
end

function onLook(cid, thing, position, lookDistance)
	return isPlayer(thing.uid) and doPlayerSetSpecialDescription(thing.uid,"\nK/D ratio: " .. math.max(getPlayerStorageValue(cid, 2001), 1) / math.max(getPlayerStorageValue(cid, 2000), 1) .. ".") or true
end

Make the xml yourself. :)
 
I would make the .xml code myself, If I could code XD
Code:
<event type="onkill" name="kill" event="script" value="kdratio.lua"/>
what should I write on event type and name? :P
 
Back
Top