CreatureEvent Kills and Deaths on Look

Critico

Sexy
Joined
Mar 25, 2010
Messages
358
Reaction score
161
About: Show in the look how many players you killed and how many deaths you have.



KillsandDeath.lua
Lua:
function onLook(cid, thing, position, lookDistance)
function getDeathsAndKills(cid, type) -- by vodka
	local query,d = db.getResult("SELECT `player_id` FROM "..(tostring(type) == "kill" and "`player_killers`" or "`player_deaths`").." WHERE `player_id` = "..getPlayerGUID(cid)),0
		if (query:getID() ~= -1) then 
			repeat
				d = d+1
			until not query:next()
			query:free()
		end
	return d  
end
if isPlayer(thing.uid) then
doPlayerSetSpecialDescription(thing.uid, "\n"..(getPlayerSex(thing.uid) == 0 and "She" or "He").." has Killed: ["..getDeathsAndKills(thing.uid, "kill").."] Players.\n"..(getPlayerSex(thing.uid) == 0 and "She" or "He").." has Died: ["..getDeathsAndKills(thing.uid, "death").."] Times")
end
return true
end
creaturescript.xml
Code:
<event type="look" name="showKD" event="script" value="KillsandDeath.lua"/>
in creaturescript/script/login.lua add:

Lua:
registerCreatureEvent(cid, "showKD")
 

kozmo

Excellent OT User
Joined
Jan 30, 2009
Messages
372
Reaction score
12
Quite interesting iv seen this before and thought about using it , Ill consider it thanks for posting also added rep :)
 

xLosT

Active Member
Joined
Jan 11, 2010
Messages
1,032
Reaction score
10
Location
Brasil, Rio Grande do Sul
nice thx
you could also add to appear if look yourself

21:32 You see yourself. You are an elite knight. <make for yourself look

thx +REP
 

Synthetic_

deathzot.net
Joined
Dec 30, 2008
Messages
2,526
Reaction score
477
nice thx
you could also add to appear if look yourself

21:32 You see yourself. You are an elite knight. <make for yourself look

thx +REP
It's a bug with TFS, you'd need to source edit it.

Also @ topic I don't think db queries are the best way to do this script because it'd be easy to flood a database using bots to grab the information faster then the server could handle. I think it would be better off to just use storages on player kill & death and to display them.
 
OP
Critico

Critico

Sexy
Joined
Mar 25, 2010
Messages
358
Reaction score
161
It's a bug with TFS, you'd need to source edit it.

Also @ topic I don't think db queries are the best way to do this script because it'd be easy to flood a database using bots to grab the information faster then the server could handle. I think it would be better off to just use storages on player kill & death and to display them.
True, I had not thought to do for storage... after, I post a new version.

Thanks
 

Ghazer

New Member
Joined
Mar 13, 2009
Messages
350
Reaction score
6
Amazing but not works for look yourself, can you updatE?

- - - Updated - - -

with that system I can look yourself... Update to look yourself please!!

Code:
function getPlayerFrags(cid)
    local time = os.time()
    local times = {today = (time - 86400), week = (time - (7 * 86400))}
 
    local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `k`.`unjustified` = 1 AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
    if(result:getID() ~= -1) then
        repeat
            local content = {date = result:getDataInt("date")}
            if(content.date > times.today) then
                table.insert(contents.day, content)
            elseif(content.date > times.week) then
                table.insert(contents.week, content)
            else
                table.insert(contents.month, content)
            end
        until not result:next()
        result:free()
    end
 
    local size = {
        day = table.maxn(contents.day),
        week = table.maxn(contents.week),
        month = table.maxn(contents.month)
    } 
    return size.day + size.week + size.month
end 
 
function onLogin(cid)
    registerCreatureEvent(cid, "newlook")
    return true
end
 
function onLook(cid, thing, position, lookDistance)
    if isPlayer(thing.uid) and thing.uid ~= cid then
        doPlayerSetSpecialDescription(thing.uid,'\n[Frags: '..getPlayerFrags(thing.uid)..']')
        return true
    elseif thing.uid == cid then
        doPlayerSetSpecialDescription(cid,'\n[Frags: '..getPlayerFrags(cid)..']')
        local string = 'You see yourself.'
        if getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION) then
            string = string..' You are '.. getPlayerGroupName(cid) ..'.'
        elseif getPlayerVocation(cid) ~= 0 then
            string = string..' You are '.. getPlayerVocationName(cid) ..'.'
        else
            string = string..' You have no vocation.'
        end
        string = string..getPlayerSpecialDescription(cid)..'\n'
 
        if getPlayerGuildId(cid) > 0 then 
            string = string..' You are ' .. (getPlayerGuildRank(cid) == '' and 'a member' or getPlayerGuildRank(cid)) ..' of the '.. getPlayerGuildName(cid)
            string = getPlayerGuildNick(cid) ~= '' and string..' ('.. getPlayerGuildNick(cid) ..').' or string..'.'
        end 
 
        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS) then
            string = string..'\nHealth: ['.. getCreatureHealth(cid) ..' / '.. getCreatureMaxHealth(cid) ..'], Mana: ['.. getCreatureMana(cid) ..' / '.. getCreatureMaxMana(cid) ..'].'
            string = string..'\nIP: '.. doConvertIntegerToIp(getPlayerIp(cid)) ..'.'
        end
 
        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION) then
            string = string..'\nPosition: [X:'.. position.x..'] [Y:'.. position.y..'] [Z:'.. position.z..'].'
        end
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string)  
        return false
    end
    return true
end
 
Last edited:
OP
Critico

Critico

Sexy
Joined
Mar 25, 2010
Messages
358
Reaction score
161
Lua:
function getPlayerFrags(cid)
    local time = os.time()
    local times = {today = (time - 86400), week = (time - (7 * 86400))}
    local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `k`.`unjustified` = 1 AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
    if(result:getID() ~= -1) then
        repeat
            local content = {date = result:getDataInt("date")}
            if(content.date > times.today) then
                table.insert(contents.day, content)
            elseif(content.date > times.week) then
                table.insert(contents.week, content)
            else
                table.insert(contents.month, content)
            end
        until not result:next()
        result:free()
    end
    local size = {
        day = table.maxn(contents.day),
        week = table.maxn(contents.week),
        month = table.maxn(contents.month)
    } 
    return size.day + size.week + size.month
end 
function getDeathsAndKills(cid, type) -- by vodka
	local query,d = db.getResult("SELECT `player_id` FROM "..(tostring(type) == "kill" and "`player_killers`" or "`player_deaths`").." WHERE `player_id` = "..getPlayerGUID(cid)),0
		if (query:getID() ~= -1) then 
			repeat
				d = d+1
			until not query:next()
			query:free()
		end
	return d  
end 
function onLogin(cid)
    registerCreatureEvent(cid, "newlook")
    return true
end
 
function onLook(cid, thing, position, lookDistance)
    if isPlayer(thing.uid) and thing.uid ~= cid then
        doPlayerSetSpecialDescription(thing.uid,"\n"..(getPlayerSex(thing.uid) == 0 and "She" or "He").." Has Killed: ["..getDeathsAndKills(thing.uid, "kill").."]Players.\n"..(getPlayerSex(thing.uid) == 0 and "She" or "He").." has Died: ["..getDeathsAndKills(thing.uid, "death").."] Times\n[Frags: "..getPlayerFrags(thing.uid).."]")
        return true
    elseif thing.uid == cid then
        doPlayerSetSpecialDescription(cid,"\nYou Has Killed: ["..getDeathsAndKills(cid, "kill").."]Players.\nYou has Died: ["..getDeathsAndKills(cid, "death").."] Times.\n[Frags: "..getPlayerFrags(cid).."]")
        local string = 'You see yourself.'
        if getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION) then
            string = string..' You are '.. getPlayerGroupName(cid) ..'.'
        elseif getPlayerVocation(cid) ~= 0 then
            string = string..' You are '.. getPlayerVocationName(cid) ..'.'
        else
            string = string..' You have no vocation.'
        end
        string = string..getPlayerSpecialDescription(cid)..'\n'
 
        if getPlayerGuildId(cid) > 0 then 
            string = string..' You are ' .. (getPlayerGuildRank(cid) == '' and 'a member' or getPlayerGuildRank(cid)) ..' of the '.. getPlayerGuildName(cid)
            string = getPlayerGuildNick(cid) ~= '' and string..' ('.. getPlayerGuildNick(cid) ..').' or string..'.'
        end 
 
        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS) then
            string = string..'\nHealth: ['.. getCreatureHealth(cid) ..' / '.. getCreatureMaxHealth(cid) ..'], Mana: ['.. getCreatureMana(cid) ..' / '.. getCreatureMaxMana(cid) ..'].'
            string = string..'\nIP: '.. doConvertIntegerToIp(getPlayerIp(cid)) ..'.'
        end
 
        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION) then
            string = string..'\nPosition: [X:'.. position.x..'] [Y:'.. position.y..'] [Z:'.. position.z..'].'
        end
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string)  
        return false
    end
    return true
end
 

1579091

New Member
Joined
Jul 18, 2012
Messages
5
Reaction score
0
this mod is the best:


<?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>
 

kozmo

Excellent OT User
Joined
Jan 30, 2009
Messages
372
Reaction score
12
I guess i did end up adding it into my Server thanks again i am sure players will enjoy that little extra feature.
 
Top