CreatureEvent Kills and Deaths on Look

Joined
Jun 18, 2014
Messages
106
Best answers
0
Likes
0
Location
Brazil
#23
this is nice system Vodkart.

could you edit my rank system? instead of "!rank frags", could be "!rank kd" ?

this is my following Rank System.

Code:
local config = {
MaxPlayer = 20,
fight_skills = {
['fist'] = 0,
['club'] = 1,
['sword'] = 2,
['axe'] = 3,
['distance'] = 4,
['shielding'] = 5,
['fishing'] = 6,
['dist'] = 4,
['shield'] = 5,
['fish'] = 6,
},
other_skills = {
[''] = "level",
['level'] = "level",
['magic'] = "maglevel",
['health'] = "healthmax",
['mana'] = "manamax"
},
vocations = {
['sorcerer'] = {1,5},
['druid'] = {2,6},
['paladin'] = {3,7},
['knight'] = {4,8}
},
storages = {
['frags'] = 824544
}
}
function onSay(cid, words, param)
local store,exausted = 156201,30
local param,str = string.lower(param),""
if not config.fight_skills[param] and not config.other_skills[param] and not config.vocations[param] and not config.storages[param] then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "this ranking does not exists.") return true
elseif getPlayerStorageValue(cid, store) >= os.time() then
doPlayerSendCancel(cid, "wait " .. getPlayerStorageValue(cid, store) - os.time() .. " seconds to use this command again.") return true
end
str = "--[ RANK "..(param == "" and "LEVEL" or string.upper(param)).." ]--\n\n"
query = config.fight_skills[param] and db.getResult("SELECT `player_id`, `value` FROM `player_skills` WHERE `skillid` = "..config.fight_skills[param].." ORDER BY `value` DESC;") or config.other_skills[param] and db.getResult("SELECT `name`, `"..config.other_skills[param].."` FROM `players` WHERE `id` > 6 AND `group_id` < 2 ORDER BY `"..config.other_skills[param].."` DESC, `name` ASC;") or config.storages[param] and db.getResult("SELECT `player_id`, `value` FROM `player_storage` WHERE `key` = "..config.storages[param].." ORDER BY cast(value as INTEGER) DESC;") or db.getResult("SELECT `name`, `level` FROM `players` WHERE `group_id` <= 2 AND `vocation` = "..config.vocations[param][1].." or `vocation` = "..config.vocations[param][2].." ORDER BY `level` DESC;")
if (query:getID() ~= -1) then
k = 1
while true do
str = str .. "\n " .. k .. ". "..(config.fight_skills[param] and getPlayerNameByGUID(query:getDataString("player_id")) or config.storages[param] and getPlayerNameByGUID(query:getDataString("player_id")) or query:getDataString("name")).." - [" .. query:getDataInt((config.fight_skills[param] and "value" or config.storages[param] and "value" or config.vocations[param] and "level" or config.other_skills[param])) .. "]"
k = k + 1
if not(query:next()) or k > config.MaxPlayer then
break
end
end
query:free()
end
doShowTextDialog(cid,6500, str)
setPlayerStorageValue(cid, store, os.time()+exausted)
return true
end
TFS 0.4 3777

thx Thiago.
 

Flamiers

New Member
Joined
Feb 18, 2017
Messages
2
Best answers
0
Likes
1
#24
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.
If you are using TFS 0.36pl1 just search for
Code:
std::string Player::getDescription(int32_t lookDistance) const
and add

Code:
 s << getSpecialDescription();
at the end of
Code:
if(lookDistance == -1)
   {
       s << "yourself.";
       if(hasFlag(PlayerFlag_ShowGroupNameInsteadOfVocation))
           s << " You are " << group->getName();
       else if(vocation_id != 0)
           s << " You are " << vocation->getDescription();
       else
           s << " You have no vocation";
           
       s << getSpecialDescription();
   }
 
Joined
Oct 6, 2015
Messages
12
Best answers
0
Likes
5
#26
If you are using TFS 0.36pl1 just search for
Code:
std::string Player::getDescription(int32_t lookDistance) const
and add

Code:
 s << getSpecialDescription();
at the end of
Code:
if(lookDistance == -1)
   {
       s << "yourself.";
       if(hasFlag(PlayerFlag_ShowGroupNameInsteadOfVocation))
           s << " You are " << group->getName();
       else if(vocation_id != 0)
           s << " You are " << vocation->getDescription();
       else
           s << " You have no vocation";
          
       s << getSpecialDescription();
   }
need it for tfs 0.4
 

FearWar

New Member
Joined
Sep 17, 2017
Messages
9
Best answers
0
Likes
0
#27
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
Would I have a "rank" of Kills and Death?

My rank is:

Lua:
local displayoutput = {"Level","Magic Level","Fist Fighting","Club Fighting","Sword Fighting","Axe Fighting","Distance Fighting","Shielding"}

local itemtype = {9969,9933,5896,8929,8932,7388,8849,8906,2580}

function onSay(cid, words, param)
    number = 1
    param = string.lower(param)
    skilllist = ""
    command = TRUE
    if param == "level" then       
        display = 1
    elseif param == "magic" then
        display = 2
    elseif param == "club" then
        id = 1
        display = 4
    elseif param == "sword" then
        id = 2
        display = 5
    elseif param == "axe" then
        id = 3
        display = 6
    elseif param == "distance" then
        id = 4
        display = 7
    elseif param == "shield" then
        id = 5
        display = 8
    else
        error = 'Highscore Commands:\n\n!rank level\n!rank magic\n!rank fist\n!rank club\n!rank sword\n!rank axe\n!rank distance\n!rank shield\n'

        doShowTextDialog(cid, 5958, error)
        command = FALSE

    end

    if command ~= FALSE then
        if display == 1 then
            local player = db.getResult("SELECT `name`, `level` FROM `players` WHERE group_id < '2' ORDER BY `level` DESC LIMIT 50;")   
            if(player:getID() ~= -1) then
                while (true) do
                    local name = player:getDataString("name")
                    local level = player:getDataInt("level")

                      skilllist = skilllist.. "\n#"..string.format("%5s",number.."  "..name.."  -  "..level)
                    number = number + 1
                    if not(player:next()) then
                        break
                    end
                end
                player:free()
            end
        elseif display == 2 then
            local player = db.getResult("SELECT `name`, `maglevel` FROM `players` WHERE group_id < '2' ORDER BY `maglevel` DESC LIMIT 50;")
            if(player:getID() ~= -1) then   
                while (true) do
                    local name = player:getDataString("name")
                    local maglevel = player:getDataInt("maglevel")

                      skilllist = skilllist.. "\n#"..string.format("%5s",number.."  "..name.."  -  "..maglevel)
                    if not(player:next()) then
                        break
                    end
                    number = number + 1
                end
            end
            player:free()
        else
            local skills = db.getResult("SELECT `player_id`, `value`, `skillid` FROM `player_skills` WHERE `skillid` = "..id.." ORDER BY `value` DESC;")
            while (true) do
                local GUID = skills:getDataInt("player_id")
                local value = skills:getDataInt("value")
                local skillid = skills:getDataInt("skillid")
                local player = db.getResult("SELECT `name` FROM `players` WHERE `id` = "..GUID.." and group_id < '2' ")
                if(player:getID() ~= -1) then
                    local name = player:getDataString("name")
                      skilllist = skilllist.. "\n#"..string.format("%5s",number.."  "..name.."  -  "..value)
                    number = number + 1
                    player:free()
                end
                if number > 50 then
                    break
                end
                    if not(skills:next()) then
                    break
                end
            end
            skills:free()
        end
        dialog = ""..displayoutput[display].." Highscores: \n  "..skilllist..""
        doShowTextDialog(cid, itemtype[display], dialog)
    end   
end
Thanks!
 
Top