Ir para conteúdo

K/D Ratio com Rank Page - Baseado em Jogos FPS


Posts Recomendados

Opa, e ai galera do XTibia.

 

Sabe aqueles jogos FPS que fornecem ao jogador um valor baseado na quantidade de death e kill do jogador. Foi lembrando deste sistemas que remontei este kill/death ratio e fiz a integração com uma página Gesior para manter um rank interativo com os jogadores. Espero que gostem :plink:

 

 

1°- Siga até o diretório "/data/creaturescripts/" e adicione a tag ao arquivo "creaturescripts.xml":

<!-- K.D System -->
<event type="kill" name="killpoint" event="script" value="onkill.lua"/>
<event type="preparedeath" name="deathpoint" event="script" value="onpd.lua"/>
<event type="look" name="KdrLook" event="script" value="onlook.lua"/>
	

2°- Siga até o diretório "/data/creaturescripts/scripts" e adicione os registros de login em "login.lua":

registerCreatureEvent(cid, "KdrLook")
registerCreatureEvent(cid, "killpoint")
registerCreatureEvent(cid, "deathpoint")

3°- Siga até o diretório "/data/creaturescripts/scripts", crie um arquivo chamado "onpd.lua" e preencha:

function onPrepareDeath(cid, deathList, lastHitKiller, mostDamageKiller)
			if isPlayer(cid) == true then
				db.query("UPDATE `players` SET `deaths` = `deaths` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";") 
				doCreatureSay(cid, '+1 Death Point!', TALKTYPE_ORANGE_1) 
			end
 
			return true
		end

4°- Siga até o diretório "/data/creaturescripts/scripts", crie um arquivo chamado "onkill.lua" e preencha:

function onKill(cid, target, damage, flags)
			if isPlayer(target) == true then
				db.query("UPDATE `players` SET `frags` = `frags` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";") 
				doCreatureSay(cid, '+1 Frag Point!', TALKTYPE_ORANGE_1) 
			end
 
			return true
		end

5°- Siga até o diretório "/data/creaturescripts/scripts", crie um arquivo chamado "onlook.lua" e preencha:

function onLook(cid, thing, position, lookDistance)
		function getKillsPlayer(cid)
			local Info = db.getResult("SELECT `frags` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
				local frags= Info:getDataInt("frags")
					return frags
			end
 
		function getDeathsPlayer(cid)
			local Info = db.getResult("SELECT `deaths` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
				local deaths= Info:getDataInt("deaths")
					return deaths
			end
		if isPlayer(thing.uid) then
local kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
				doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Killed: ["..getKillsPlayer(thing.uid).."] Players."..(getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Died: ["..getDeathsPlayer(thing.uid).."] Times.\nThe Kdr(Kill Death Ratio) is: ["..kdr.."].")
			end
		if(thing.uid == cid) then
local kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
				doPlayerSetSpecialDescription(thing.uid, "\nYou have Killed: ["..getKillsPlayer(thing.uid).."] Players.\nYou have Died: ["..getDeathsPlayer(thing.uid).."] Times.\nYou Kdr(Kill Death Ratio) is: ["..kdr.."].")
			end
			return true
		end

6°- Siga até a pasta de seu website Gesior e prepare o "index.php" pare receber a página:

<?PHP
$page = $_REQUEST['page'];

if(count($config['site']['worlds']) > 1)
{
	foreach($config['site']['worlds'] as $idd => $world_n)
	{
		if($idd == (int) $_GET['world'])
		{
			$world_id = $idd;
			$world_name = $world_n;
		}
	}
}
if(!isset($world_id))
{
	$world_id = 0;
	$world_name = $config['server']['serverName'];
}
$offset = $page * 100;
//jesli chodzi o skilla
if(isset($id))
	$skills = $SQL->query('SELECT * FROM players, player_skills WHERE players.world_id = '.$world_id.' AND players.deleted = 0 AND players.group_id < '.$config['site']['players_group_id_block'].' AND players.id = player_skills.player_id AND player_skills.skillid = '.$id.' AND players.account_id != 1 ORDER BY value DESC, count DESC LIMIT 101 OFFSET '.$offset);
else
{
		$skills = $SQL->query('SELECT * FROM players WHERE players.world_id = '.$world_id.' AND players.deleted = 0 AND players.group_id < '.$config['site']['players_group_id_block'].' AND account_id != 1 AND deaths != 1  ORDER BY frags/deaths DESC, level DESC LIMIT 101 OFFSET '.$offset);
		$list_name = 'K.D System Ratio';
		$list = 'frags';
	
}
//wyswietlanie wszystkiego
$main_content .= '<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD><IMG SRC="'.$layout_name.'/images/general/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD><TD><CENTER><H2>Ranking for '.$list_name.' on '.$world_name.'</H2></CENTER><BR>';
	if(count($config['site']['worlds']) > 1)
	{
		$main_content .= '<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD>
		<FORM ACTION="index.php?subtopic=highscores&list='.$list.'" METHOD=get><INPUT TYPE=hidden NAME=subtopic VALUE=highscores><INPUT TYPE=hidden NAME=list VALUE=experience>
		<TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4><TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>World Selection</B></TD></TR><TR><TD BGCOLOR="'.$config['site']['lightborder'].'">
		<TABLE BORDER=0 CELLPADDING=1><TR><TD>World: </TD><TD><SELECT SIZE="1" NAME="world"><OPTION VALUE="" SELECTED>(choose world)</OPTION>';
		foreach($config['site']['worlds'] as $id => $world_n)
		{
			$main_content .= '<OPTION VALUE="'.$id.'">'.$world_n.'</OPTION>';
		}
		$main_content .= '</SELECT> </TD><TD><INPUT TYPE=image NAME="Submit" ALT="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18>
		</TD></TR></TABLE></TABLE></FORM></TABLE><br>';
	}
	$main_content .= '<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=1 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD WIDTH=5% CLASS=whites><B>Rank</B></TD>
	<TD WIDTH=65% CLASS=whites><B>Name</B></TD><TD WIDTH=30% CLASS=whites><b><center>K/D</center></B></TD>';
	$main_content .= '<TD CLASS=whites><b><center>Level</center></B></TD>';
	$main_content .= '</TR><TR>';
	
	foreach($skills as $skill)  
	{
		
		if($number_of_rows < 100) 
		{
				/* INICIO SCRIPT CONTAGEM */
				$deathssss = $skill['deaths']-1;
				$fragsss  = $skill['frags']-1;
									
				if($skill['deaths'] > 0){$num = $skill['deaths'];}else{	$num = 1;}

				$number2 = $skill['frags']/$num;
				$number = number_format($number2, 2, '.', '');

				if($number2 > 1){$st = "#98FB98";}elseif($number2 < 1){$st = "#FF6A6A";}else{$st = ""; /*#87CEEB*/}
				/* FIM SCRIPT CONTAGEM */

			$skill['value'] = $skill['level'];
			if(!is_int($number_of_rows / 2)) { $bgcolor = $config['site']['darkborder']; } else { $bgcolor = $config['site']['lightborder']; } $number_of_rows++;
			$main_content .= '<tr bgcolor="'.$bgcolor.'" style="background: '.$st.' !important;">
				<td>'.($offset + $number_of_rows).'.</td>
				<td>'.$flag.'<a href="index.php?subtopic=characters&name='.urlencode($skill['name']).'">'.$skill['name'].'</a>';
				if($config['site']['showMoreInfo'])
					$main_content .= '<br><small>Level: '.$skill['level'].', '.$vocation_name[$skill['world_id']][$skill['promotion']][$skill['vocation']];
					if(count($config['site']['worlds']) > 1)
						$main_content .= ', '.$config['site']['worlds'][$skill['world_id']];
					$main_content .= '</small>';


			$main_content .= '<td><center><b>'.$number.' </b> ('.$fragsss.'/'.$deathssss.')</center></td>';
			$main_content .= '</td><td>'.$skill['value'].'</td>';
			$main_content .= '</tr>';
		}
		else
			$show_link_to_next_page = TRUE;
	}



	$main_content .= '</TABLE><TABLE BORDER=0 CELLPADDING=4 CELLSPACING=1 WIDTH=100%>';
	//link to previous page if actual page isn't first
	if($page > 0) 
		$main_content .= '<TR><TD WIDTH=100% ALIGN=right VALIGN=bottom><A HREF="index.php?subtopic=eventrank&world='.$world_id.'&page='.($page - 1).'" CLASS="size_xxs">Previous Page</A></TD></TR>';
	//link to next page if any result will be on next page
	if($show_link_to_next_page) 
		$main_content .= '<TR><TD WIDTH=100% ALIGN=right VALIGN=bottom><A HREF="index.php?subtopic=eventrank&world='.$world_id.'&page='.($page + 1).'" CLASS="size_xxs">Next Page</A></TD></TR>';
	//end of page
	$main_content .= '</TABLE></TD>
	</TR>
	</TABLE>';
	$main_content .= '<center><b>Desenvolvido por: Wênio Ferraz - <a href="http://www.chaitosoft.com" target="_blank">ChaitoSoft.com</a></b></center>';
?>

7°- Siga até seu banco de dados e execute as seguintes QUERYS:

ALTER TABLE `players` ADD `frags` INT( 11 ) NOT NULL DEFAULT '1';

ALTER TABLE `players` ADD `deaths` INT( 11 ) NOT NULL DEFAULT '1';

Prontinho, obrigado!

Link para o comentário
Compartilhar em outros sites

Já ia perguntar "e o query?", quando tava lendo os primeiros passos, mas vi que deixou por último hehe...

não sei como não pensei nisso antes, ótimo sistema. :sml:


Gostei do ranking no index...

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...