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

[Gesior AAC] Most Creature Killers! [update! fixed with 1 query]

Zonet

Web Developer
Joined
Sep 1, 2008
Messages
4,393
Reaction score
52
Location
Tibia VS RL-life, guess whos back?
I made this script, shows ** players that have killed ** monsters. You can add more monsters, and also choose how many players that should be shown.
This is just a example pic, I took storage from db, just test :)
126690662154.png

PHP script:
PHP:
<?php
/* Scrip by zonet */
$kills = $config['site']['creatureKills'];
$limit = $config['site']['creatureKillShowLimit'];
$main_content .= '<table border="0px" cellspacing="1px" cellpadding="4px" width="100%">
            <tr bgcolor="#505050" style="color: white;"><th width="10%">Creature</th><th>Creature name</th><th>Most Killer ( '.$limit.' )</th></tr>';
$row = 1;
    foreach($kills as $name => $storage) {
    $qa = $SQL->query('SELECT `player_storage`.`player_id`, `player_storage`.`key`, `player_storage`.`value` AS `value`, `players`.`id`, `players`.`name` AS `name` FROM `player_storage` LEFT JOIN `players` ON `player_storage`.`player_id` = `players`.`id` WHERE `player_storage`.`key` = '.$storage.' ORDER BY ABS(value) DESC LIMIT '.$limit)->fetchAll();
    $color = ( $row % 2 ? $config['site']['darkborder'] : $config['site']['lightborder']);
    $row++;
    $main_content .= '<tr bgcolor="'.$color.'"><td><img src="/monsters/'.(str_replace(" ", "" , $name)).'.gif"></td><td width="20%" style="font-size: 13pt; font-weight: bold; color: darkorange;"><center>'.(ucfirst($name)).'</center></td><td>';
        $a = 0;
        foreach( $qa as $q )
        {
            $a++;
            if($a == 1)
                $main_content .= '<font color="green">';
            if($a == $limit)
                $main_content .= '<font color="red">';
            if($a == $limit/2)
                $main_content .= '<font color="darkorange">';

            $main_content .= '<b>'.$a.'. Name:</b> <a href="?subtopic=characters&name='.urlencode($q['name']).'">'.$q['name'].'</a> (Kills:  '.$q['value'].') </font></font></font><br />';
        }
    }
    $main_content .= '</td></table>';
?>

Website config.php
PHP:
$config['site']['creatureKillShowLimit'] = 6;
$config['site']['creatureKills'] = array('dragon' => 9541, 'dragon lord' => 9542, 'frost dragon' => 9543, 'wyrm' => 9544, 'demon' => 9545);

Creaturescript.xml
Code:
<event type="kill" name="countKill" event="script" value="count.lua"/>

login.lua
Code:
	registerCreatureEvent(cid, "countKill")

count.lua
Lua:
--[[ Script by slawkens, modified by Zonet]]--

local monsters = {
	["dragon"] = 9541,
	["dragon lord"] = 9542,
	["frost dragon"] = 9543,
	["wyrm"] = 9544,
	["demon"] = 9545,
}

function onKill(cid, target)
	if(isPlayer(target) ~= true and isPlayer(cid)) then
		local name = getCreatureName(target)
		local monster = monsters[string.lower(name)]
		if(monster) then
			local killedMonsters = getPlayerStorageValue(cid, monster)
			if(killedMonsters < 0) then
				killedMonsters = 1
			end
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You killed " .. killedMonsters .. " " .. name .. "'s.")
			setPlayerStorageValue(cid, monster, killedMonsters + 1)
		end
	end
	return true
end

Any errors or any question, wouldn't mind answering them :)
 
Last edited:
In case you want to create the whole monster list, here you go:

PHP:
<?php
        $strg_num = 9541;

        if(file_exists($path = '/home/migxxx/tfs/data/monster/monsters.xml') && $xml = simplexml_load_file($path))
                foreach($xml as $xmlx)
                        echo('["'.strtolower($xmlx['name']).'"] = '.$strg_num++.',<br />');
?>
 
´Here is a pic, but with most death, not done yet ;) This is only with most kills.
126690662154.png


This is just Example of a storage I took from db, so that's why they have all same kills ;)
 
Last edited:
Aint this lagg the Server since it takes alot of queries from database at an big amount of players?
 
Cool but i think to killers bosses, because add all monsters ... time after time ;d
 
2 queries. Could be with one, but I'm bad in SQL :)


Code:
    $qa = $SQL->query('SELECT `player_storage`.`value`, `players`.`name` FROM `player_storage`, `players` WHERE `player_storage`.`key` = '.$storage.' AND `player_storage`.`player_id` = `players`.`id` ORDER BY `player_storage`.`value` DESC LIMIT '.$limit)->fetchAll();

I guess thats the only thing you need, also one tip, never use * (Select all) when you going to use only 1~2 fields.
 
Code:
    $qa = $SQL->query('SELECT `player_storage`.`value`, `players`.`name` FROM `player_storage`, `players` WHERE `player_storage`.`key` = '.$storage.' AND `player_storage`.`player_id` = `players`.`id` ORDER BY `player_storage`.`value` DESC LIMIT '.$limit)->fetchAll();

I guess thats the only thing you need, also one tip, never use * (Select all) when you going to use only 1~2 fields.

yea, I could do `player_id`. But I'm still new to this, the 2 queries could be done with 1 :p

#up
Make sure you put this to config.php
PHP:
$config['site']['creatureKillShowLimit'] = 6;
$config['site']['creatureKills'] = array('dragon' => 9541, 'dragon lord' => 9542, 'frost dragon' => 9543, 'wyrm' => 9544, 'demon' => 9545);
 
BUMP, modified the script, 1 query! :)

PHP:
<?php
/* Scrip by zonet */
$kills = $config['site']['creatureKills'];
$limit = $config['site']['creatureKillShowLimit'];
$main_content .= '<table border="0px" cellspacing="1px" cellpadding="4px" width="100%">
            <tr bgcolor="#505050" style="color: white;"><th width="10%">Creature</th><th>Creature name</th><th>Most Killer ( '.$limit.' )</th></tr>';
$row = 1;
    foreach($kills as $name => $storage) {
    $qa = $SQL->query('SELECT `player_storage`.`player_id`, `player_storage`.`key`, `player_storage`.`value` AS `value`, `players`.`id`, `players`.`name` AS `name` FROM `player_storage` LEFT JOIN `players` ON `player_storage`.`player_id` = `players`.`id` WHERE `player_storage`.`key` = '.$storage.' ORDER BY value DESC LIMIT '.$limit)->fetchAll();
    $color = ( $row % 2 ? $config['site']['darkborder'] : $config['site']['lightborder']);
    $row++;
    $main_content .= '<tr bgcolor="'.$color.'"><td><img src="/monsters/'.(str_replace(" ", "" , $name)).'.gif"></td><td width="20%" style="font-size: 13pt; font-weight: bold; color: darkorange;"><center>'.(ucfirst($name)).'</center></td><td>';
        $a = 0;
        foreach( $qa as $q )
        {
            $a++;
            if($a == 1)
                $main_content .= '<font color="green">';
            if($a == $limit)
                $main_content .= '<font color="red">';
            if($a == $limit/2)
                $main_content .= '<font color="darkorange">';

            $main_content .= '<b>'.$a.'. Name:</b> <a href="?subtopic=characters&name='.urlencode($qa['name']).'">'.$q['name'].'</a> (Kills:  '.$q['value'].') </font></font></font><br />';
        }
    }
    $main_content .= '</td></table>';
?>
 
Back
Top