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

[PHP] View a players house in character search!

ond

Veteran OT User
Joined
Mar 24, 2008
Messages
2,782
Solutions
25
Reaction score
491
Location
Sweden
EDIT: Solved, thanks to Cykotitan.

Hello, I'm not much of a PHP coder, so I wonder if otland can help me out with a function.

What I want to acheive with this is that when you search on a character, you can see the Name, Level, Vocation etc. but I want it to show (IF) a player has a house, and if not, just skip that line.

Here is a picture example:
(This is just an example)

examplefj.jpg


And here is character.php:

PHP:
<?php 
/*
    Copyright (C) 2007 - 2009  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
include ("include.inc.php");
$ptitle="Characters - $cfg[server_name]";
include("header.inc.php");
?>
<div id="content">
    <div class="top">Character Lookup</div>
    <div class="mid">
        <form method="get" action="characters.php">
            <input type="text" name="player_name"/>
            <input type="submit" value="Search"/>
        </form>
        <?php
        try {
            $player = new Player();
            if (!empty($_GET['player_id'])) {
                $player->load($_GET['player_id']);
            } elseif (!empty($_GET['player_name'])) {
                $player->find($_GET['player_name']);
            } else {
                throw new PlayerException();
            }
            $account = new Account();
            $account->load($player->attrs['account']);

            echo '<hr/><table style="width: 100%"><tr><td><b>Name:</b> '.htmlspecialchars($player->attrs['name'])."<br/>\n";
            $gender = Array('Female','Male');
            echo '<b>Sex:</b> '.$gender[$player->attrs['sex']].'<br/>'."\n";
	    echo '<b>Profession:</b> '.$cfg['vocations'][$player->attrs['vocation']]['name']."<br/>\n";	
	    echo '<b>Level:</b> '.$player->attrs['level']."<br/>\n";
	    echo '<b>Experience:</b> '.$player->attrs['experience']."<br/>\n";

            if (!empty($cfg['temple'][$player->attrs['city']]['name']))
                echo "<b>Residence</b>: ".ucfirst($cfg['temple'][$player->attrs['city']]['name'])."<br/>";

            try {
                echo '<b>Guild:</b> '.$player->guild['guild_rank_name'].' of <a href="guilds.php?guild_id='.$player->guild['guild_id'].'">'.htmlspecialchars($player->guild['guild_name']).'</a><br/>'."\n";
            } catch(GuildNotFoundException $e) {}

            /*try {
                echo '<b>House:</b> '.$HousesXML = simplexml_load_file($cfg['dirdata'].$cfg['house_file'])."<br>\n";
            } catch(GuildNotFoundException $e) {}*/


            if ($account->attrs['premend'] > time()) {
                echo "<b>Premium: </b> ".ceil(($account->attrs['premend'] - time())/(3600*24))." day(s)<br/>";
            }
            if ($player->attrs['lastlogin'] == 0)
                $lastlogin = 'Never';
            else
                $lastlogin = date("jS F Y H:i:s",$player->attrs['lastlogin']);
            echo "<b>Last Login:</b> ".$lastlogin."<br/>\n";
			
			echo '<b>House:</b>'. "<br/>\n";



            echo '<b>Status:</b> ';
            if($player->isStatus()) echo '<span style="color:green">Online</span>'."<br/>\n";
            else echo '<span style="color:red">Offline</span>'."<br/>\n";
	
            if ($cfg['show_skills']) {
                echo "</td><td>";
                $sn = $cfg['skill_names'];
                for ($i=0; $i < count($sn); $i++) {
                    echo '<b>'.ucfirst($sn[$i]).':</b> '.$player->skills[$i]['skill']."<br/>\n";
                }
                echo '</td></tr>';
            }
            echo '</table>';
            if (strlen($account->attrs['comment'])>0) {
                echo "<b>Comments</b><br/><div style=\"overflow:hidden\"><pre>".htmlspecialchars($account->attrs['comment'])."</pre></div><br/>\n";
            }
            echo '<hr/>';
            if ($account->attrs['reveal_characters'] && $account->players && count($account->players) > 1) {
                echo '<b>Characters on the same account</b><br/><ul class="task-menu">';
                foreach ($account->players as $_player) {
                    echo '<li style="background-image: url(resource/user.png);" onclick="window.location.href=\'characters.php?player_id='.htmlspecialchars($_player['id']).'\'">'.htmlspecialchars($_player['name']).'</li>';
                }
                echo '</ul><hr/>';
            }


            if ($cfg['show_deathlist']) {
                if ($player->deaths) {
                    echo '<b>Latest Deaths</b><br/>';
                    $prevdate = 0;
                    foreach ($player->deaths as $death) {
                        if ($death['killer_id'])
                            $name = '<a href="characters.php?player_id='.$death['killer_id'].'">'.$death['killer_name'].'</a>';
                        else
                            $name = $death['killer_name'];
                        if($prevdate == $death['date'])
                            echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and by '.$name.'<br/>';
                        else
                            echo '<i>'.date("jS F Y H:i:s",$death['date']).'</i> Killed at level '.$death['victim_level'].' by '.$name.'<br/>';
                        $prevdate = $death['date'];
                    }
                }
            }
        } catch(PlayerNotFoundException $e) {
            echo 'Player not found';
        } catch(PlayerException $e) {}
        ?>
    </div>
    <div class="bot"></div>
</div>
<?php include ("footer.inc.php");?>

Would be real glad if someone could help me out with this one.
Thanks for now!
 
Last edited:
Code:
<?php 
/*
	Copyright (C) 2007 - 2009  Nicaw

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
include ("include.inc.php");
$ptitle="Characters - $cfg[server_name]";
include("header.inc.php");
?>
<div id="content">
	<div class="top">Character Lookup</div>
	<div class="mid">
		<form method="get" action="characters.php">
			<input type="text" name="player_name"/>
			<input type="submit" value="Search"/>
		</form>
		<?php
		try {
			$player = new Player();
			if (!empty($_GET['player_id'])) {
				$player->load($_GET['player_id']);
			} elseif (!empty($_GET['player_name'])) {
				$player->find($_GET['player_name']);
			} else {
				throw new PlayerException();
			}
			$account = new Account();
			$account->load($player->attrs['account']);

			echo '<hr/><table style="width: 100%"><tr><td><b>Name:</b> '.htmlspecialchars($player->attrs['name'])."<br/>\n";
			$gender = Array('Female','Male');
			echo '<b>Sex:</b> '.$gender[$player->attrs['sex']].'<br/>'."\n";
		echo '<b>Profession:</b> '.$cfg['vocations'][$player->attrs['vocation']]['name']."<br/>\n";    
		echo '<b>Level:</b> '.$player->attrs['level']."<br/>\n";
		echo '<b>Experience:</b> '.$player->attrs['experience']."<br/>\n";

			if (!empty($cfg['temple'][$player->attrs['city']]['name']))
				echo "<b>Residence</b>: ".ucfirst($cfg['temple'][$player->attrs['city']]['name'])."<br/>";

			try {
				echo '<b>Guild:</b> '.$player->guild['guild_rank_name'].' of <a href="guilds.php?guild_id='.$player->guild['guild_id'].'">'.htmlspecialchars($player->guild['guild_name']).'</a><br/>'."\n";
			} catch(GuildNotFoundException $e) {}

			$MySQL = AAC::$SQL;
			$MySQL->myQuery('SELECT `id` FROM `houses` WHERE `owner` = '.$player->attrs['id'].' LIMIT 1');
			if ($row = $MySQL->fetch_array()) {
				echo "<b>House:</b> ";
				foreach (simplexml_load_file($cfg['dirdata'].$cfg['house_file'])->house as $house) {
					if((int)$row['id'] == (int)$house['houseid']) {
						echo $house['name'];
						break;
					}
				}
				echo "<br/>\n";
			}

			if ($account->attrs['premend'] > time()) {
				echo "<b>Premium: </b> ".ceil(($account->attrs['premend'] - time())/(3600*24))." day(s)<br/>";
			}
			if ($player->attrs['lastlogin'] == 0)
				$lastlogin = 'Never';
			else
				$lastlogin = date("jS F Y H:i:s",$player->attrs['lastlogin']);
			echo "<b>Last Login:</b> ".$lastlogin."<br/>\n";
			
			echo '<b>House:</b>'. "<br/>\n";



			echo '<b>Status:</b> ';
			if($player->isStatus()) echo '<span style="color:green">Online</span>'."<br/>\n";
			else echo '<span style="color:red">Offline</span>'."<br/>\n";
	
			if ($cfg['show_skills']) {
				echo "</td><td>";
				$sn = $cfg['skill_names'];
				for ($i=0; $i < count($sn); $i++) {
					echo '<b>'.ucfirst($sn[$i]).':</b> '.$player->skills[$i]['skill']."<br/>\n";
				}
				echo '</td></tr>';
			}
			echo '</table>';
			if (strlen($account->attrs['comment'])>0) {
				echo "<b>Comments</b><br/><div style=\"overflow:hidden\"><pre>".htmlspecialchars($account->attrs['comment'])."</pre></div><br/>\n";
			}
			echo '<hr/>';
			if ($account->attrs['reveal_characters'] && $account->players && count($account->players) > 1) {
				echo '<b>Characters on the same account</b><br/><ul class="task-menu">';
				foreach ($account->players as $_player) {
					echo '<li style="background-image: url(resource/user.png);" onclick="window.location.href=\'characters.php?player_id='.htmlspecialchars($_player['id']).'\'">'.htmlspecialchars($_player['name']).'</li>';
				}
				echo '</ul><hr/>';
			}


			if ($cfg['show_deathlist']) {
				if ($player->deaths) {
					echo '<b>Latest Deaths</b><br/>';
					$prevdate = 0;
					foreach ($player->deaths as $death) {
						if ($death['killer_id'])
							$name = '<a href="characters.php?player_id='.$death['killer_id'].'">'.$death['killer_name'].'</a>';
						else
							$name = $death['killer_name'];
						if($prevdate == $death['date'])
							echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and by '.$name.'<br/>';
						else
							echo '<i>'.date("jS F Y H:i:s",$death['date']).'</i> Killed at level '.$death['victim_level'].' by '.$name.'<br/>';
						$prevdate = $death['date'];
					}
				}
			}
		} catch(PlayerNotFoundException $e) {
			echo 'Player not found';
		} catch(PlayerException $e) {}
		?>
	</div>
	<div class="bot"></div>
</div>
<?php include ("footer.inc.php");?>
 
Mabye this could help?

Code:
<?php
/*
    Copyright (C) 2007  Nicaw

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
include ("include.inc.php");
$ptitle="Bans - $cfg[server_name]";
include ("header.inc.php");
// maximum ban time to display, set 0 to show all bans
$cfg['max_ban_time'] = 2*30*24*60*60; //2 months
?>
<div id="content">
<div class="top">Banishments</div>
<div class="mid">
<?php
$SQL = AAC::$SQL;
$SQL->myQuery('SELECT players.name, bans.comment, bans.expires, bans.active FROM bans, players WHERE bans.type = 2 AND players.id = bans.value OR bans.type = 3 AND players.account_id = bans.value ORDER BY expires ASC');

echo '<table style="width:100%">'."\n";
echo '<tr class="color0"><td style="width:25%"><b>Player</b></td><td style="width:25%"><b>Comment</b></td><td style="width:25%"><b>Banished Until</b></td></tr>'."\n";
while ($ban = $SQL->fetch_array()){
	if(!$ban['active']) continue;
	$time = date("jS F Y H:i:s",(int) $ban['expires']);
	$d = floor(($ban['expires'] - time())/(24*3600));
	$h = floor(($ban['expires'] - time() - $d * 24*3600)/3600);
	if ($d != 0)
		$timeleft = $d.'d '.$h.'h';
	else
		$timeleft = $h.'h';
	if ($ban['expires'] - time() > 0 && (($ban['expires'] - time()) < $cfg['max_ban_time'] || $cfg['max_ban_time'] == 0)){
		$i++;
		echo '<tr '.getStyle($i).'><td>'.$ban['name'].'</td><td>'.$ban['comment'].'</td><td>'.$time.'</td></tr>'."\n";
	}
}
echo '</table>'."\n";
?>
</div>
<div class="bot"></div>
</div>
<?php include ("footer.inc.php");?>
 
Back
Top