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

CreatureEvent TFS 1.0 KDR System!

Codinablack

Dreamer
Content Editor
Joined
Dec 26, 2013
Messages
1,558
Solutions
11
Reaction score
774
Ok first off credits to respective owners.
@narko for creating original code and solving problem for looking at a player with no deaths.
@Amiroslo for changing mod into creaturescripts in first place
@Elwyn for fixing functions getKillsPlayer(), getDeathsPlayer(), and all other work found here http://otland.net/threads/tfs-1-0-onlook.221582/

Special thanks to Elwyn for taking the time to work with me until we got it right!

Now for the scripts!

/creaturescripts/scripts/onkill.lua
Code:
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 Kill Point!', TALKTYPE_ORANGE_1) 
 end
 return true
 end

/creaturescripts/scripts/onpd.lua
Code:
 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
in creaturescripts.xml add
Code:
    <event type="kill" name="killpoint" script="onkill.lua"/>
    <event type="preparedeath" name="deathpoint" script="onpd.lua"/>
in /creaturescripts/scripts/login.lua add
Code:
    player:registerEvent("killpoint")
    player:registerEvent("deathpoint")
in /events/scripts/player.lua add
Code:
function getKillsPlayer(cid)
    local Info = db.storeQuery("SELECT `frags` FROM `players` WHERE `id` = " .. cid:getGuid())
    local frags = result.getDataInt(Info, 'frags')
    result.free(Info)
    return frags
end

function getDeathsPlayer(cid)
    local Info = db.storeQuery("SELECT `deaths` FROM `players` WHERE `id` = " .. cid:getGuid())
    local deaths = result.getDataInt(Info, 'deaths')
    result.free(Info)
    return deaths
end
to the very top !
and in same file: (creaturescripts/scripts/player.lua)
replace the onLook function for this one
Code:
function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance)
    if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItemID: [%d]", description, thing:getId())

            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, ActionID: [%d]", description, actionId)
            end
           
            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, UniqueId: [%d]", description, uniqueId)
            end
           
            description = description .. "."
            local itemType = thing:getType()
           
            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransformTo: [%d] (onEquip).", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransformTo: [%d] (onDeEquip).", description, transformDeEquipId)
            end

            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecayTo: [%d]", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: [%d / %d]"
            if thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: [%d / %d]", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
        end
       
        local position = thing:getPosition()
        description = string.format(
            "%s\nPosition: [X: %d] [Y: %d] [Z: %d].",
            description, position.x, position.y, position.z
        )       
          if thing:isCreature() then
           if thing:isPlayer() then
               description = string.format("%s\nIP: [%s].", description, Game.convertIpToString(thing:getIp()))
            end
         end
    end
        if thing:isCreature() then
            if thing:isPlayer() then
                if(getDeathsPlayer(thing)==0)then 
                    kdr = getKillsPlayer(thing) 
                        else 
                if(getDeathsPlayer(thing)~=0) then
                    kdr = getKillsPlayer(thing)/getDeathsPlayer(thing)
                end
                end
            description = string.format("%s\nThis player killed %s and died %s times. Their KDR is %s", description, getKillsPlayer(thing), getDeathsPlayer(thing), kdr)
            end
        end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
Then finally execute this command in sql in phpmyadmin for your database
Code:
ALTER TABLE `players` ADD `frags` INT( 11 ) NOT NULL DEFAULT '0';
ALTER TABLE `players` ADD `deaths` INT( 11 ) NOT NULL DEFAULT '0';
 
I know it doesn't tell you fancy stuff like He or She, or tell the difference when you are looking at yourself or not, but hey the code is completely functional now so if anyone would like to help build on it here's the opportunity...
 
How close? I might could make it the way you wish. I am playing with metamethods right now and I think I got some stuff figured out...
 
Well like u posted before, it doesnt say for example, "He/She has 1.75 kill/death ratio.". It would be nice if it said something like that when looking at the player :p Also it would be nice to have some kind of broadcast built in the system, like if the player have killed.. let's say 5 people in a row it broadcasts something like "Player Name is on a killing spree!".

And maybe a talkaction to check what your current KDr is? Also i've been thinking of putting the players KDr on the character view on the website, but that's easy to fix :p

That's my suggestion for now, might come up something more later.. x'D
 
Code:
        if thing:isCreature() then
            if thing:isPlayer() then
                if(getDeathsPlayer(thing)==0)then
                    kdr = getKillsPlayer(thing)
                        else
                if(getDeathsPlayer(thing)~=0) then
                    kdr = getKillsPlayer(thing)/getDeathsPlayer(thing)
                end
                end
                if self:isPlayer() then
                description = string.format("%sYou have killed %s and died %s times. Your Kill/Death Ratio is %s", description, getKillsPlayer(thing), getDeathsPlayer(thing), kdr)
                else
            description = string.format("%s" .. (getPlayerSex(thing) == 0 and "\nShe" or "\nHe") .. " killed %s and died %s times." .. (getPlayerSex(thing) == 0 and "\nHer" or "\nHis") ..  " Kill/Death Ratio is %s", description, getKillsPlayer(thing), getDeathsPlayer(thing), kdr)
            end
            end
        end
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end

Thats updated, if you leave out
Code:
if self:isPlayer() then 
                description = string.format("%sYou have killed %s and died %s times. Your Kill/Death Ratio is %s", description, getKillsPlayer(thing), getDeathsPlayer(thing), kdr)
                else"
and take away one of the "end" after the second description it will read gender just fine but not be able to tell if its yourself. However even with above code it counts everyone as yourself... Does anyone know how to fix this? I have tried if thing=cid but that doesn't work either...
 
101 Views. No one is using this? I swear I have seen tons of people asking how to see frags, how to see frags....
 
Keep it up, I will try this out! :)
You are making new and nice scripts for TFS 1.0 and I will keep on following you with interest.

Kind Regards,
Eldin.
 
Great job, just has to make a minor change in the onkill.lua because it is counting monsters killing, maybe a return false if is monster before the whole function
 
Great job, just has to make a minor change in the onkill.lua because it is counting monsters killing, maybe a return false if is monster before the whole function

Very good, yeah this is based off an old system, I converted this with very very little lua knowledge, you are absolutely right though that is way better, gonna fix that for myself, and probably the bug in player.lua and update main post... still need to update main post for my weapon fist type in source too....
 
I tried using this and got some problems like players can't die, can't look anything etc.. no errors on console
 
I tried using this and got some problems like players can't die, can't look anything etc.. no errors on console


Which server are you using? This does need a couple fixes to be updated to main post...
 
Back
Top