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

TFS 0.X TFS 0.3.6 - 8.60 on look problem on look [Frags: 0 - Deaths: 0] on other player

samuel157

Intermediate OT User
Joined
Mar 19, 2010
Messages
616
Solutions
4
Reaction score
122
Location
São Paulo, Brazil
GitHub
Samuel10M
LUA:
--Script By Theax ""
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, "fraglook")
   return true
end

function onLook(cid, thing, position, lookDistance)
   if isPlayer(thing.uid) and thing.uid ~= cid then
       doPlayerSetSpecialDescription(thing.uid,'[Frags: '..getPlayerFrags(thing.uid)..']')
       return true
   elseif thing.uid == cid then
       doPlayerSetSpecialDescription(cid,'[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)..''

       if getPlayerNameByGUID(getPlayerPartner(cid), false, false) ~= nil then
           string = string..' You are '.. (getPlayerSex(cid) == 0 and 'wife' or 'husband') ..' of '.. getPlayerNameByGUID(getPlayerPartner(cid)) ..'.'
       end

       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

Code:
function getDeaths(cid)
   local query, d = db.getResult("SELECT `player_id` FROM `player_killers` 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 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 onLook(cid, thing, position, lookDistance)
   if isPlayer(thing.uid) and thing.uid ~= cid then
      return doPlayerSetSpecialDescription(thing.uid, '\n'.. '[Frags: ' .. getPlayerFrags(thing.uid) .. ' - Deaths: ' .. getDeaths(thing.uid) .. ']')
   elseif thing.uid == cid then     
      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
              

      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
      
      string = string..'\n'.. '[Frags: ' .. getPlayerFrags(cid) .. ' - Deaths: ' .. getDeaths(cid) .. ']'

      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
      return false, doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string) 
   end
   return 1
end
 

Attachments

Last edited:
Solution
creaturescript.xml
LUA:
     <event type="login" name="fraglook_register" event="script" value="fraglook.lua"/>
          <event type="look" name="fraglook" event="script" value="fraglook.lua"/>

creaturescript/script

Code:
-- =========================
-- FRAGS
-- =========================
function getPlayerFrags(cid)
    if not isPlayer(cid) then
        return 0
    end

    local time = os.time()
    local times = {
        today = time - 86400,
        week = time - (7 * 86400)
    }

    local frags = 0
    local guid = getPlayerGUID(cid)

    local result = db.getResult(
        "SELECT pd.date FROM player_killers pk " ..
        "LEFT JOIN killers k ON pk.kill_id = k.id " ..
        "LEFT JOIN player_deaths pd ON k.death_id =...
creaturescript.xml
LUA:
     <event type="login" name="fraglook_register" event="script" value="fraglook.lua"/>
          <event type="look" name="fraglook" event="script" value="fraglook.lua"/>

creaturescript/script

Code:
-- =========================
-- FRAGS
-- =========================
function getPlayerFrags(cid)
    if not isPlayer(cid) then
        return 0
    end

    local time = os.time()
    local times = {
        today = time - 86400,
        week = time - (7 * 86400)
    }

    local frags = 0
    local guid = getPlayerGUID(cid)

    local result = db.getResult(
        "SELECT pd.date 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 " ..
        "WHERE pk.player_id = " .. guid .. " " ..
        "AND k.unjustified = 1 " ..
        "AND pd.date >= " .. (time - (30 * 86400))
    )

    if result:getID() ~= -1 then
        repeat
            frags = frags + 1
        until not result:next()
        result:free()
    end

    return frags
end

-- =========================
-- DEATHS
-- =========================
function getPlayerDeaths(cid)
    if not isPlayer(cid) then
        return 0
    end

    local guid = getPlayerGUID(cid)
    local result = db.getResult(
        "SELECT COUNT(*) AS deaths FROM player_deaths WHERE player_id = " .. guid
    )

    if result:getID() ~= -1 then
        local deaths = result:getDataInt("deaths")
        result:free()
        return deaths
    end

    return 0
end

-- =========================
-- LOGIN
-- =========================
function onLogin(cid)
    registerCreatureEvent(cid, "fraglook")
    return true
end

-- =========================
-- LOOK
-- =========================
function onLook(cid, thing, position, lookDistance)
    if isPlayer(thing.uid) then
        doPlayerSetSpecialDescription(thing.uid,
            "[Frags: " .. getPlayerFrags(thing.uid) ..
            "] [Deaths: " .. getPlayerDeaths(thing.uid) .. "]"
        )
    end

    -- LOOK NA SIEBIE
    if thing.uid == cid then
        local str = "You see yourself."

        -- vocation / group
        if getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION) then
            str = str .. " You are " .. getPlayerGroupName(cid) .. "."
        elseif getPlayerVocation(cid) > 0 then
            str = str .. " You are " .. getPlayerVocationName(cid) .. "."
        else
            str = str .. " You have no vocation."
        end

        str = str .. getPlayerSpecialDescription(cid)

        -- ===== MARRIAGE (SAFE) =====
        local partnerGUID = getPlayerPartner(cid)
        if partnerGUID and partnerGUID > 0 then
            local result = db.getResult(
                "SELECT name FROM players WHERE id = " .. partnerGUID
            )
            if result:getID() ~= -1 then
                local partnerName = result:getDataString("name")
                result:free()

                str = str .. " You are " ..
                    (getPlayerSex(cid) == 0 and "wife" or "husband") ..
                    " of " .. partnerName .. "."
            end
        end

        -- ===== GUILD =====
        if getPlayerGuildId(cid) > 0 then
            str = str .. " You are " ..
                (getPlayerGuildRank(cid) ~= "" and getPlayerGuildRank(cid) or "a member") ..
                " of the " .. getPlayerGuildName(cid)

            if getPlayerGuildNick(cid) ~= "" then
                str = str .. " (" .. getPlayerGuildNick(cid) .. ")."
            else
                str = str .. "."
            end
        end

        -- ===== DETAILS =====
        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS) then
            str = str .. "\nHealth: [" .. getCreatureHealth(cid) .. "/" .. getCreatureMaxHealth(cid) ..
                "], Mana: [" .. getCreatureMana(cid) .. "/" .. getCreatureMaxMana(cid) .. "]."
            str = str .. "\nIP: " .. doConvertIntegerToIp(getPlayerIp(cid)) .. "."
        end

        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION) then
            str = str .. "\nPosition: [X:" .. position.x ..
                "] [Y:" .. position.y ..
                "] [Z:" .. position.z .. "]."
        end

        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str)
        return false
    end

    return true
end

and to creaturescript/login.lua
registerCreatureEvent(cid, "fraglook")
registerCreatureEvent(cid, "fraglook_register")
 
Solution
I advise doing it via storage, especially on servers with thousands of players where this version has a look script, as each database query ends up overloading the server.
 
Adding onLook Death&Frag STORAGE:

data/creaturescript.xml

LUA:
<event type="login" name="FragDeathLogin" script="frag_death_storage.lua"/>
<event type="kill" name="FragDeathKill" script="frag_death_storage.lua"/>
<event type="death" name="FragDeath" script="frag_death_storage.lua"/>
<event type="look" name="FragDeathLook" script="frag_death_storage.lua"/>

data/creaturescript/script
Code:
-- =========================
-- CONFIG
-- =========================
STORAGE_FRAGS  = 50000
STORAGE_DEATHS = 50001

-- =========================
-- LOGIN
-- =========================
function onLogin(cid)
    registerCreatureEvent(cid, "FragDeathKill")
    registerCreatureEvent(cid, "FragDeath")
    registerCreatureEvent(cid, "FragDeathLook")

    -- init storage
    if getPlayerStorageValue(cid, STORAGE_FRAGS) < 0 then
        setPlayerStorageValue(cid, STORAGE_FRAGS, 0)
    end
    if getPlayerStorageValue(cid, STORAGE_DEATHS) < 0 then
        setPlayerStorageValue(cid, STORAGE_DEATHS, 0)
    end

    return true
end

-- =========================
-- KILL (FRAGS)
-- =========================
function onKill(cid, target, lastHit)
    if not isPlayer(cid) or not isPlayer(target) then
        return true
    end

    if lastHit then
        local frags = getPlayerStorageValue(cid, STORAGE_FRAGS)
        if frags < 0 then frags = 0 end
        setPlayerStorageValue(cid, STORAGE_FRAGS, frags + 1)
    end

    return true
end

-- =========================
-- DEATH (DEATHS)
-- =========================
function onDeath(cid, corpse, killer)
    if not isPlayer(cid) then
        return true
    end

    local deaths = getPlayerStorageValue(cid, STORAGE_DEATHS)
    if deaths < 0 then deaths = 0 end
    setPlayerStorageValue(cid, STORAGE_DEATHS, deaths + 1)

    return true
end

-- =========================
-- LOOK
-- =========================
function onLook(cid, thing, position, lookDistance)
    if isPlayer(thing.uid) then
        local frags  = getPlayerStorageValue(thing.uid, STORAGE_FRAGS)
        local deaths = getPlayerStorageValue(thing.uid, STORAGE_DEATHS)

        if frags < 0 then frags = 0 end
        if deaths < 0 then deaths = 0 end

        doPlayerSetSpecialDescription(thing.uid,
            "[Frags: " .. frags .. "] [Deaths: " .. deaths .. "]"
        )
    end

    return true
end
 
Back
Top