• 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.
 
Why you think it is broken? It works fine. He asked for onLook script.
Even If my script doesn't help him, it might be usefull for someone else. :p

your using max for no reason in one part, your not rounding incase of a repeating decimal number. (you have to use s:format())
I didn't say the onlook wasn't what he wanted, just was saying to modify the recent one i posted cause your using my previous lines wrong :S no offense
 
doesnt work for me :/ This Is what I have in creaturescripts.xml
Code:
	<event type="kill" name="kill" event="script" value="kdratio.lua"/>
and kdratio.lua
Code:
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
login.lua
Code:
registerCreatureEvent(cid, "kdratio")
talkactions.xml
Code:
<talkaction words="!kd" event="script" value="kdratio.lua"/>
Code:
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
btw Im using 0.4
 
Code:
<event type="[COLOR=#ff0000][B]death[/B][/COLOR]" name="[B][COLOR=#FF0000]kdratio[/COLOR][/B]" event="script" value="kdratio.lua"/>
 
Ah okay, TFS doesn't interpret the :format function right use this:

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, string.format("Your K/D Ratio: %.2f",kills/deaths))
end
 
your using max for no reason in one part, your not rounding incase of a repeating decimal number. (you have to use s:format())
I didn't say the onlook wasn't what he wanted, just was saying to modify the recent one i posted cause your using my previous lines wrong :S no offense

I'am using math.max for a reason, because if you divide by 0 you recive inf. And if player hasn't died nor killed anybody he'd have k/d ration equal to 1 not 0 (0 deaths, 0 kills).
You're right about rounding, totally forgot about that.
 
I'am using math.max for a reason, because if you divide by 0 you recive inf. And if player hasn't died nor killed anybody he'd have k/d ration equal to 1 not 0 (0 deaths, 0 kills).
You're right about rounding, totally forgot about that.

Yeah deaths can't be 0 that's why I using: math.max(getCreatureStorage(cid, 40006), 1)
So if the storage is -1 or 0 it'll divide by 1 so 300:0 is just like 300:1 = same ratio

Kills CAN be 0 because you aren't dividing by 0 your dividing by whatever deaths is 1+
So if kills is 0 and deaths is 1: you get 0 still. not an infinite number.

:)
 
Yeah deaths can't be 0 that's why I using: math.max(getCreatureStorage(cid, 40006), 1)
So if the storage is -1 or 0 it'll divide by 1 so 300:0 is just like 300:1 = same ratio

Kills CAN be 0 because you aren't dividing by 0 your dividing by whatever deaths is 1+
So if kills is 0 and deaths is 1: you get 0 still. not an infinite number.

:)

I did the same. Way old trick.
 
I did the same. Way old trick.

No you didn't im trying to tell you your kills have a minimum of 1, they need to have a minimum of 0
"math.max(getPlayerStorageValue(cid, 2001), 1)" -> "math.max(getPlayerStorageValue(cid, 2001), 0)"
Only deaths have to be above 0 because your are dividing by deaths, not kills.

EDIT: the way you are doing it now, if they die 5 times and get 0 kills your script will show that they have a
1/5 = 0.2 ratio. When it should be 0/5 = 0 ratio.
 
No you didn't im trying to tell you your kills have a minimum of 1, they need to have a minimum of 0
"math.max(getPlayerStorageValue(cid, 2001), 1)" -> "math.max(getPlayerStorageValue(cid, 2001), 0)"
Only deaths have to be above 0 because your are dividing by deaths, not kills.

EDIT: the way you are doing it now, if they die 5 times and get 0 kills your script will show that they have a
1/5 = 0.2 ratio. When it should be 0/5 = 0 ratio.

Ratio should start at 1, because if you have 0 deaths and 0 kills the ration should be 1.
 
Back
Top