• 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!

[Mod]K/D Ratio System by Narko

narko

vertrauenswürdig ~
Joined
Oct 19, 2008
Messages
1,317
Solutions
2
Reaction score
131
Location
Unknown
kdrsystem.JPG
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="KDR SYSTEM" version="1.0" author="Narko" contact="[email protected]" enabled="yes">
	<event type="kill" name="killpoint" event="script"><![CDATA[
		function onKill(cid, target, damage, flags)
			if isPlayer(target) == true then
				db.query("UPDATE `players` SET `frags` = `frags` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";") 
				doCreatureSay(cid, '+1 Frag Point!', TALKTYPE_ORANGE_1) 
			end
			
			return true
		end
	]]></event>

	<event type="preparedeath" name="deathpoint" event="script"><![CDATA[
		function onPrepareDeath(cid, deathList, lastHitKiller, mostDamageKiller)
			if isPlayer(cid) == true then
				db.query("UPDATE `players` SET `deaths` = `deaths` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";") 
				doCreatureSay(cid, '+1 Death Point!', TALKTYPE_ORANGE_1) 
			end

			return true
		end
	]]></event>

	<event type="look" name="KdrLook" event="script"><![CDATA[
		function onLook(cid, thing, position, lookDistance)
		function getKillsPlayer(cid)
			local Info = db.getResult("SELECT `frags` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
				local frags= Info:getDataInt("frags")
					return frags
			end

		function getDeathsPlayer(cid)
			local Info = db.getResult("SELECT `deaths` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
				local deaths= Info:getDataInt("deaths")
					return deaths
			end
		if isPlayer(thing.uid) then
local kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
				doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Killed: ["..getKillsPlayer(thing.uid).."] Players."..(getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Died: ["..getDeathsPlayer(thing.uid).."] Times.\nThe Kdr(Kill Death Ratio) is: ["..kdr.."].")
			end
		if(thing.uid == cid) then
local kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
				doPlayerSetSpecialDescription(thing.uid, "\nYou have Killed: ["..getKillsPlayer(thing.uid).."] Players.\nYou have Died: ["..getDeathsPlayer(thing.uid).."] Times.\nYou Kdr(Kill Death Ratio) is: ["..kdr.."].")
			end
			return true
		end
	]]></event>
	<event type="login" name="KdrLook" event="buffer"><![CDATA[
		registerCreatureEvent(cid, "KdrLook")
		registerCreatureEvent(cid, "killpoint")
		registerCreatureEvent(cid, "deathpoint")
		_result = true
	]]></event>
</mod>
I hope opinions or improvements!
 

Attachments

Last edited:
The first bug I see when i look at the picture is that your looking at yourself, yet it says "He has killed..." / "He has died..."
Change it so that it says "You have killed..."/"You have died..."

its easy, just make:
Code:
if(thing.uid == cid) then
to know if the player is looking at himself or not

You could also store the kill/death values on a storageValue so that you don't have to make so many SQL Queries, it can be troublesome as you'll make an SQL Query everytime a player looks at another player, it can possibly generate alot of lag
 
Last edited:
Fixed issue the player is looking at himself!
Next update Change system to storages!
 
yeah, but to make a small optimization to the code, place the if that checks if thing.uid == cid before the other one and change the other one to an elseif

reason: like this it works obviously, but if the player is looking at itself, you are setting his description twice because you first check if thing.uid is player and if it is change it and only then you check if its itself, and you change again, its something very minor, but its still a waste of resources

there's also a typo: "
You Kdr(Kill Death Ratio) is: ["..kdr.."].")
" should be "Your Kdr..."
 
SQL:
ALTER TABLE `players` ADD `frags` INT( 11 ) NOT NULL DEFAULT '0';
ALTER TABLE `players` ADD `deaths` INT( 11 ) NOT NULL DEFAULT '0';
 
An error message would tell you where the problem is located..
 
Mods suck, better off putting this in creaturescripts.
 
[5/9/2012 20:48:16] sqlite3_prepare_v2(): SQLITE ERROR: no such column: deaths (UPDATE "players" SET "deaths" = "deaths" + 1 WHERE id = 164;)
[5/9/2012 20:48:16] sqlite3_prepare_v2(): SQLITE ERROR: no such column: frags (UPDATE "players" SET "frags" = "frags" + 1 WHERE id = 5;)

5/9/2012 20:48:21] Error during getDataInt(frags).
[5/9/2012 20:48:21] Error during getDataInt(deaths).
[5/9/2012 20:48:21] Error during getDataInt(frags).
[5/9/2012 20:48:21] Error during getDataInt(deaths).
[5/9/2012 20:48:21] Error during getDataInt(frags).
[5/9/2012 20:48:21] Error during getDataInt(deaths).
[5/9/2012 20:48:21] Error during getDataInt(frags).
[5/9/2012 20:48:21] Error during getDataInt(deaths).
 
ill convert it in a min
 
Last edited:
can anyone convert this to a normal lua script :D?

It's simple, look at the mod.
You have 4 event types (all which are creaturescripts).

First one, you have onKill
Second one, you have onPrepareDeath
Third one, you have onLook
and last one you have onLogin (just need to register the events)

One line above each of those functions are the action callings (stuff you put in creaturescripts.xml).
However, it's missing the "value" attribute part, so you need to add that.

For example, in the mod, we have for onKill:
<event type="look" name="KdrLook" event="script">
To add the value and finish it up:
<event type="look" name="KdrLook" event="script" value="KdrLook.lua"/>

After you do those, then create 3 new different files, then you would add your functions separately.
For example, to do KdrLook.lua, just create a new lua file and add:
Lua:
function onLook(cid, thing, position, lookDistance)
		function getKillsPlayer(cid)
			local Info = db.getResult("SELECT `frags` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
				local frags= Info:getDataInt("frags")
					return frags
			end

		function getDeathsPlayer(cid)
			local Info = db.getResult("SELECT `deaths` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
				local deaths= Info:getDataInt("deaths")
					return deaths
			end
		if isPlayer(thing.uid) then
local kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
				doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Killed: ["..getKillsPlayer(thing.uid).."] Players."..(getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Died: ["..getDeathsPlayer(thing.uid).."] Times.\nThe Kdr(Kill Death Ratio) is: ["..kdr.."].")
			end
		if(thing.uid == cid) then
local kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
				doPlayerSetSpecialDescription(thing.uid, "\nYou have Killed: ["..getKillsPlayer(thing.uid).."] Players.\nYou have Died: ["..getDeathsPlayer(thing.uid).."] Times.\nYou Kdr(Kill Death Ratio) is: ["..kdr.."].")
			end
			return true
		end
* Kind of messy because I copied it from the mod, but still works.

Just need to do the rest.
Then for login stuff, just add the register stuff in your already existing login.lua.
 
Back
Top