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

Lua TFS 0.3.6 - LUA - [Frags: 16 - Deaths: 29] - NO SHOW FOR OTHER PLAYER ON LOOK

samuel157

/root
Joined
Mar 19, 2010
Messages
608
Solutions
4
Reaction score
120
Location
São Paulo, Brazil
GitHub
Samuel10M
TFS 0.3.6 - LUA - [Frags: 16 - Deaths: 29] - NO SHOW FOR OTHER PLAYER ON LOOK

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
 
Solution
LUA:
local fragCache = {}
local CACHE_TIME = 10 -- segundos

local function getPlayerFrags(cid)
    local guid = getPlayerGUID(cid)
    local now = os.time()

    -- cache
    if fragCache[guid] and fragCache[guid].time > now then
        return fragCache[guid].value
    end

    local time = now - (30 * 86400)
    local frags = 0

    local result = db.getResult(
        "SELECT COUNT(*) AS `frags` 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
    )

    if result:getID() ~= -1 then
        frags = result:getDataInt("frags")...
LUA:
local fragCache = {}
local CACHE_TIME = 10 -- segundos

local function getPlayerFrags(cid)
    local guid = getPlayerGUID(cid)
    local now = os.time()

    -- cache
    if fragCache[guid] and fragCache[guid].time > now then
        return fragCache[guid].value
    end

    local time = now - (30 * 86400)
    local frags = 0

    local result = db.getResult(
        "SELECT COUNT(*) AS `frags` 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
    )

    if result:getID() ~= -1 then
        frags = result:getDataInt("frags")
        result:free()
    end

    fragCache[guid] = {
        value = frags,
        time = now + CACHE_TIME
    }

    return frags
end

function onLook(cid, thing, position, lookDistance)
    if not thing.uid or not isPlayer(thing.uid) then
        return true
    end

    local frags = getPlayerFrags(thing.uid)
    local description

    if thing.uid == cid then
        description = "You see yourself."
    else
        description = "You see " .. getCreatureName(thing.uid) .. "."
    end

    description = description ..
        "\nFrags (last 30 days): [" .. frags .. "]"

    if getPlayerFlagValue(thing.uid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION) then
        description = description ..
            "\nYou are " .. getPlayerGroupName(thing.uid) .. "."
    elseif getPlayerVocation(thing.uid) ~= 0 then
        description = description ..
            "\nYou are " .. getPlayerVocationName(thing.uid) .. "."
    else
        description = description ..
            "\nYou have no vocation."
    end

    if getPlayerGuildId(thing.uid) > 0 then
        description = description ..
            "\nGuild: " ..
            (getPlayerGuildRank(thing.uid) == "" and "Member" or getPlayerGuildRank(thing.uid)) ..
            " of " .. getPlayerGuildName(thing.uid)
    end

    if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS) then
        description = description ..
            "\nHealth: [" .. getCreatureHealth(thing.uid) .. "/" .. getCreatureMaxHealth(thing.uid) .. "]" ..
            ", Mana: [" .. getCreatureMana(thing.uid) .. "/" .. getCreatureMaxMana(thing.uid) .. "]"
    end

    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, description)
    return false
end

login.lua
LUA:
registerCreatureEvent(cid, "fraglook")
 
Solution
Back
Top