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

Frag counter

OperatorMopa

Member
Joined
Feb 10, 2014
Messages
127
Reaction score
6
TFS 1.2
Guys, what is the fastest/easiest way to check every kill how many times did i kill a specific player ?

I need something like "You've killed name x times".
Lua or cpp, doesn't metter.

I don't wanna check it in DB every kill.
 
Code:
local baseStorage = 38000

function onKill(creature, target)
    if Player(creature) and Player(target) then
        local storage_t = baseStorage + target:getUID()
        if player:getStorageValue(storage_t) == 0 then
            player:setStorageValue(storage_t, 1)
            player:sendTextMessage(MESSAGE_INFO_DESC, "You have killed this player "..player:getStorageValue(storage_t).." times.")
        else
            player:setStorageValue(storage_t, player:getStorageValue(storage_t) + 1)
            player:sendTextMessage(MESSAGE_INFO_DESC, "You have killed this player "..player:getStorageValue(storage_t).." times.")
        end
    end
end
 
Code:
local baseStorage = 38000

function onKill(creature, target)
    if Player(creature) and Player(target) then
        local storage_t = baseStorage + target:getUID()
        if player:getStorageValue(storage_t) == 0 then
            player:setStorageValue(storage_t, 1)
            player:sendTextMessage(MESSAGE_INFO_DESC, "You have killed this player "..player:getStorageValue(storage_t).." times.")
        else
            player:setStorageValue(storage_t, player:getStorageValue(storage_t) + 1)
            player:sendTextMessage(MESSAGE_INFO_DESC, "You have killed this player "..player:getStorageValue(storage_t).." times.")
        end
    end
end
This idea is pretty funny Are the storages unlimited?
 
Code:
local baseStorage = 38000

function onKill(creature, target)
    if Player(creature) and Player(target) then
        local storage_t = baseStorage + target:getUID()
        if player:getStorageValue(storage_t) == 0 then
            player:setStorageValue(storage_t, 1)
            player:sendTextMessage(MESSAGE_INFO_DESC, "You have killed this player "..player:getStorageValue(storage_t).." times.")
        else
            player:setStorageValue(storage_t, player:getStorageValue(storage_t) + 1)
            player:sendTextMessage(MESSAGE_INFO_DESC, "You have killed this player "..player:getStorageValue(storage_t).." times.")
        end
    end
end
That is just gonna give errors because of few reasons.
First, target:getUID() should be target:getGuid().
Second, both creature & target is "extending" player so no need to create player userdata object. (player in this case would not even be found since you not assigned it)
Third, if creature:getStorageValue(storage_t) == 0 then will fail on first, since it returns -1 for some reason.

This should do it:
Code:
local baseStorage = 38000

function onKill(creature, target)
    if creature:isPlayer() and target:isPlayer() then
        local storage_t = baseStorage + target:getGuid()
        if creature:getStorageValue(storage_t) > 0 then
            creature:setStorageValue(storage_t, creature:getStorageValue(storage_t) + 1)
            creature:sendTextMessage(4, "You have killed this player "..creature:getStorageValue(storage_t).." times.")
        else
            creature:setStorageValue(storage_t, 1)
            creature:sendTextMessage(4, "You have killed this player 1 time.")
        end
    end
end
 
I made the script very early in the morning so small mistakes are expected. All I can say is if he couldn't fix the code that I premade for what he wanted he shouldn't be working on creating a server.
 
Back
Top