|
<?php
include "/home/froger/public_html/_private/exampleconnect.php";
$sql = mysql_fetch_array(mysql_query("SELECT subno, currenthp, clan, x, y, z FROM example WHERE subno='{$subno}'"));
$map = mysql_fetch_array(mysql_query("SELECT tx, ty, tz, ID, Zone FROM Test WHERE X='{$sql['x']}' AND Y='{$sql['y']}' AND Z='{$sql['z']}'"));
if ($map['ID'] == 'teleport')
{
if ($map['Zone'] != 'Cave Entrance')
{
$query = mysql_query("UPDATE example SET x='{$map['tx']}', y='{$map['ty']}', z='{$map['tz']}' WHERE subno='{$subno}'");
$sql = mysql_fetch_array(mysql_query("SELECT subno, currenthp, x, y, z FROM example WHERE subno='{$subno}'"));
} else {
$query = mysql_query("UPDATE example SET x='{$map['tx']}', y='{$map['ty']}', z='{$map['tz']}' WHERE subno='{$subno}'");
$sql = mysql_fetch_array(mysql_query("SELECT subno, currenthp, x, y, z FROM example WHERE subno='{$subno}'"));
}
}
$back = imagecreate(72,72);
$player = imagecreatefromgif('http://example.com/images/player3.gif');
$rowz = mysql_query("SELECT X, Y, Z, Zone, townid FROM Example2 WHERE (X BETWEEN " . ($sql['x']-4) . " AND " . ($sql['x']+4) . ") AND (Y BETWEEN " . ($sql['y']-4) . " AND " . ($sql['y']+4) . ") AND Z='{$sql['z']}' ORDER BY Y, X");
$i = 0;
$l = 0;
while ($img = mysql_fetch_array($rowz))
{
if ($y == NULL)
{
$y = $img['Y'];
}
if ($y != $img['Y'])
{
$y++;
$i++;
}
$loc = mysql_fetch_array(mysql_query("SELECT subno FROM example WHERE x='{$img['X']}' AND y='{$img['Y']}' AND z='". $sql['z'] . "'"));
$clan = mysql_fetch_array(mysql_query("SELECT subno FROM clan WHERE name='{$sql['clan']}' AND subno='{$loc['subno']}'"));
$watch = mysql_fetch_array(mysql_query("SELECT subno FROM watch WHERE subno='{$loc['subno']}' AND mysubno='{$subno}'"));
$monsterloc = mysql_fetch_array(mysql_query("SELECT monstername, subno FROM MonsterLocation WHERE x='{$img['X']}' AND y='{$img['Y']}' AND z='{$sql['z']}'"));
$treasure = mysql_fetch_array(mysql_query("SELECT id FROM lootlocation WHERE x='{$img['X']}' AND y='{$img['Y']}' AND z='". $sql['z'] . "'"));
if (($monsterloc['subno'] == NULL) && ($sql['currenthp'] > 0))
{
$id = mysql_fetch_array(mysql_query("SELECT uniqueid FROM MonsterLocation WHERE x='{$img['X']}' AND y='{$img['Y']}' AND z='{$img['Z']}'"));
$attack = mysql_query("UPDATE MonsterLocation SET subno='{$subno}' WHERE uniqueid='{$id['uniqueid']}'");
}
$z = $i * 8;
$o = $l * 8;
$l++;
if ($l >= 9)
{
$l = 0;
}
if (($loc['subno'] == NULL) && ($clan['subno'] == NULL) && ($watch['subno'] == NULL) && ($monsterloc['monstername'] == NULL) && ($treasure['id'] == NULL) && ($img['Zone'] != 'Town'))
switch ($img['Zone'])
{
case 'Ground':
if ($grass == NULL)
{
$grass = imagecreatefromgif('http://example.com/images/grassyground.gif');
}
$image = imagecopymerge($back, $grass, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Dead Grass':
if ($dgrass == NULL)
{
$dgrass = imagecreatefromgif('http://example.com/images/deadgrass.gif');
}
$image = imagecopymerge($back, $dgrass, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Ladder':
if ($ladder == NULL)
{
$ladder = imagecreatefromgif('http://example.com/images/ladder.gif');
}
$image = imagecopymerge($back, $ladder, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Pillar':
if ($pillar == NULL)
{
$pillar = imagecreatefromgif('http://example.com/images/pillar.gif');
}
$image = imagecopymerge($back, $pillar, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Sign':
if ($sign == NULL)
{
$sign = imagecreatefromgif('http://example.com/images/sign.gif');
}
$image = imagecopymerge($back, $sign, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Bridge':
if ($bridge == NULL)
{
$bridge = imagecreatefromgif('http://example.com/images/bridge.gif');
}
$image = imagecopymerge($back, $bridge, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Rock':
if ($rock == NULL)
{
$rock = imagecreatefromgif('http://example.com/images/rock.gif');
}
$image = imagecopymerge($back, $rock, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Mountain':
if ($mountain == NULL)
{
$mountain = imagecreatefromgif('http://example.com/images/mountain.gif');
}
$image = imagecopymerge($back, $mountain, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Cave Wall':
if ($cavew == NULL)
{
$cavew = imagecreatefromgif('http://example.com/images/mountain.gif');
}
$image = imagecopymerge($back, $cavew, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Trail':
if ($bridge == NULL)
{
$bridge = imagecreatefromgif('http://example.com/images/bridge.gif');
}
$image = imagecopymerge($back, $bridge, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Portal':
if ($portal == NULL)
{
$portal = imagecreatefromgif('http://example.com/images/portal.gif');
}
$image = imagecopymerge($back, $portal, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Water':
if ($water == NULL)
{
$water = imagecreatefromgif('http://example.com/images/water.gif');
}
$image = imagecopymerge($back, $water, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Small Tree':
if ($stree == NULL)
{
$stree = imagecreatefromgif('http://example.com/images/smalltree.gif');
}
$image = imagecopymerge($back, $stree, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Large Tree':
if ($ltree == NULL)
{
$ltree = imagecreatefromgif('http://example.com/images/largetree.gif');
}
$image = imagecopymerge($back, $ltree, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Small Pine Tree':
if ($sptree == NULL)
{
$sptree = imagecreatefromgif('http://example.com/images/smallpinetree.gif');
}
$image = imagecopymerge($back, $sptree, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Dragonwood':
if ($sptree == NULL)
{
$sptree = imagecreatefromgif('http://example.com/images/smallpinetree.gif');
}
$image = imagecopymerge($back, $sptree, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Large Pine Tree':
if ($lptree == NULL)
{
$lptree = imagecreatefromgif('http://example.com/images/largepinetree.gif');
}
$image = imagecopymerge($back, $lptree, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Rubble':
if ($rubble == NULL)
{
$rubble = imagecreatefromgif('http://example.com/images/cavewallrubble.gif');
}
$image = imagecopymerge($back, $rubble, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Dock':
if ($dock == NULL)
{
$dock = imagecreatefromgif('http://example.com/images/dock.gif');
}
$image = imagecopymerge($back, $dock, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Lava':
if ($lava == NULL)
{
$lava = imagecreatefromgif('http://example.com/images/lava.gif');
}
$image = imagecopymerge($back, $lava, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Gate':
if ($gate == NULL)
{
$gate = imagecreatefromgif('http://example.com/images/gate.gif');
}
$image = imagecopymerge($back, $gate, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Dead Tree':
if ($deadt == NULL)
{
$deadt = imagecreatefromgif('http://example.com/images/deadtree.gif');
}
$image = imagecopymerge($back, $deadt, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Night Ground':
if ($deadt == NULL)
{
$nightg = imagecreatefromgif('http://example.com/images/nightground.gif');
}
$image = imagecopymerge($back, $nightg, $o, $z, 0, 0, 8, 8, 100);
break;
}
if (($treasure['id'] != NULL) && ($monsterloc['monstername'] == NULL) && ($loc['subno'] == NULL))
{
if ($treasures == NULL)
{
$treasures = imagecreatefromgif('http://example.com/images/chest.gif');
}
$image = imagecopymerge($back, $treasures, $o, $z, 0, 0, 8, 8, 100);
}
if ($monsterloc['monstername'] != NULL)
switch ($monsterloc['monstername']) {
case 'Rat':
if ($rat == NULL)
{
$rat = imagecreatefromgif('http://example.com/images/rat.gif');
}
$image = imagecopymerge($back, $rat, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Bear':
if ($bear == NULL)
{
$bear = imagecreatefromgif('http://example.com/images/bear.gif');
}
$image = imagecopymerge($back, $bear, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Goblin Peon':
if ($goblinp == NULL)
{
$goblinp = imagecreatefromgif('http://example.com/images/goblinpeon.gif');
}
$image = imagecopymerge($back, $goblinp, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Zombie':
if ($zombie == NULL)
{
$zombie = imagecreatefromgif('http://example.com/images/zombie.gif');
}
$image = imagecopymerge($back, $zombie, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Goblin King':
if ($goblink == NULL)
{
$goblink = imagecreatefromgif('http://example.com/images/goblinking.gif');
}
$image = imagecopymerge($back, $goblink, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Goblin Warrior':
if ($goblinw == NULL)
{
$goblinw = imagecreatefromgif('http://example.com/images/goblinwarrior.gif');
}
$image = imagecopymerge($back, $goblinw, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Ghost':
if ($ghost == NULL)
{
$ghost = imagecreatefromgif('http://example.com/images/ghost.gif');
}
$image = imagecopymerge($back, $ghost, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Zombie Assassin':
if ($zombiea == NULL)
{
$zombiea = imagecreatefromgif('http://example.com/images/zombieassassin.gif');
}
$image = imagecopymerge($back, $zombiea, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Green Dragon':
if ($greend == NULL)
{
$greend = imagecreatefromgif('http://example.com/images/greendragon.gif');
}
$image = imagecopymerge($back, $greend, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Goblin Sorcerer':
if ($goblins == NULL)
{
$goblins = imagecreatefromgif('http://example.com/images/goblinsorcerer.gif');
}
$image = imagecopymerge($back, $goblins, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Orc Warrior':
if ($orcw == NULL)
{
$orcw = imagecreatefromgif('http://example.com/images/orcwarrior.gif');
}
$image = imagecopymerge($back, $orcw, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Fire Wizard':
if ($firewizard == NULL)
{
$firewizard = imagecreatefromgif('http://example.com/images/firewizard.gif');
}
$image = imagecopymerge($back, $firewizard, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Demon Imp':
if ($demonimp == NULL)
{
$demonimp = imagecreatefromgif('http://example.com/images/demonimp.gif');
}
$image = imagecopymerge($back, $demonimp, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Revanant Demon':
if ($revanantd == NULL)
{
$revanantd = imagecreatefromgif('http://example.com/images/revanantdemon.gif');
}
$image = imagecopymerge($back, $revanantd, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Ancient Dragon':
if ($ancientd == NULL)
{
$ancientd = imagecreatefromgif('http://example.com/images/ancientdragon.gif');
}
$image = imagecopymerge($back, $ancientd, $o, $z, 0, 0, 8, 8, 100);
break;
case 'Snake':
if ($snake == NULL)
{
$snake = imagecreatefromgif('http://example.com/images/snake.gif');
}
$image = imagecopymerge($back, $snake, $o, $z, 0, 0, 8, 8, 100);
break;
}
if ($loc['subno'] != NULL)
{
$hp = mysql_fetch_array(mysql_query("SELECT currenthp FROM example WHERE subno='{$loc['subno']}'"));
if ($hp['currenthp'] > 0)
{
if (($watch['subno'] != NULL) && ($clan['subno'] == NULL))
{
if ($player4 == NULL)
{
$player4 = imagecreatefromgif('http://example.com/images/watch.gif');
}
$image = imagecopymerge($back, $player4, $o, $z, 0, 0, 8, 8, 100);
} elseif (($clan['subno'] != NULL) && ($sql['subno'] != $clan['subno'])) {
if ($player5 == NULL)
{
$player5 = imagecreatefromgif('http://example.com/images/clan.gif');
}
$image = imagecopymerge($back, $player5, $o, $z, 0, 0, 8, 8, 100);
} else {
if ($sql['subno'] == $loc['subno'])
{
$image = imagecopymerge($back, $player, $o, $z, 0, 0, 8, 8, 100);
} else {
if ($players == NULL)
{
$players = imagecreatefromgif('http://example.com/images/Player.gif');
}
$image = imagecopymerge($back, $players, $o, $z, 0, 0, 8, 8, 100);
}
}
} else {
if ($corpse == NULL)
{
$corpse = imagecreatefromgif('http://example.com/images/corpse.gif');
}
$image = imagecopymerge($back, $corpse, $o, $z, 0, 0, 8, 8, 100);
}
}
if ($img['Zone'] == 'Town')
{
if ($img['townid'] == '1')
{
if ($tlb == NULL)
{
$tlb = imagecreatefromgif('http://example.com/images/topleftbyren.gif');
}
$image = imagecopymerge($back, $tlb, $o, $z, 0, 0, 8, 8, 100);
}
if ($img['townid'] == '2')
{
if ($trb == NULL)
{
$trb = imagecreatefromgif('http://example.com/images/toprightbyren.gif');
}
$image = imagecopymerge($back, $trb, $o, $z, 0, 0, 8, 8, 100);
}
if ($img['townid'] == '3')
{
if ($blb == NULL)
{
$blb = imagecreatefromgif('http://example.com/images/bottleftbyren.gif');
}
$image = imagecopymerge($back, $blb, $o, $z, 0, 0, 8, 8, 100);
}
if ($img['townid'] == '4')
{
if ($brb == NULL)
{
$brb = imagecreatefromgif('http://example.com/images/bottrightbyren.gif');
}
$image = imagecopymerge($back, $brb, $o, $z, 0, 0, 8, 8, 100);
}
}
}
mysql_free_result($rowz);
header("Content-Type: image/gif");
imagegif($back);
imagedestroy($back);
?>
Hello, is there anyway to optimize this code? You see, it just makes a simple 2D image composed of a whole bunch of small 8pix X 8pix images that makes a 9X9 image.. I am using image copy merge to help accomplish this. It makes the image because I have things set in place in my database in X, Y, Z co ordinates.
I have been having problems as of recently though. This scblockedript is taking to long to load as more users come to my site. I made this scblockedript a long time ago, optimized it as much as I could. Is there something I am not seeing? Am I using the wrong methods to do this? Any tips to lead me in the right direction would be greatly appreciated. |