Updating defense and displaying it real time.

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
rapid3642
Posts: 45
Joined: Thu Nov 26, 2009 9:38 pm

Updating defense and displaying it real time.

Post by rapid3642 »

Hey people, so i have a equipment page showing the current Armor the player has unequipped and equipped just as shown on the MMO Series. and i added in code to display the Defense of the player witch is quite simple but when someone equips a piece of armor it will add 2 or subtract 2 when unequiping, so with that being said, my problem is that the player has to refresh the page just to see the updated defense and that can get really confusing to players, so i did try making a script saying if a piece of armor got equipped then it will print defense + 2 and that works real time and is fine with me but at the same time i don't think it will work correctly when going into battle, so i have to update their armor some how. But when i equip more than one piece of armor it leaves it at the highest amount of armor witch is 2 so instead of equipping another piece of armor and it displaying defense + 4 it says defense + 2. can anyone guide me in the right direction please. I got rid of the code because it didn't work properly but i will display my original code if someone can get an idea of what to do.

I broke this up into parts, This is the equip and unequip part of the script.

Code: Select all

<?php
	    $type=$_GET['type'];
		$local=$_GET['local'];
	   $randid=$_GET['randid'];
	  
		if ($type=="a")
	  {
	   	 $updateequip="Update playerarmor SET equip=0 WHERE pid='$id' AND equip=1 AND location='$local'";
	    mysql_query($updateequip) or die("Could not update armor");	
		
		 
		 $reequip="Update playerarmor set equip=1 where pid='$id' AND randid='$randid' AND location='$local'";
	    mysql_query($reequip) or die("Could not update armor2");	
		
		echo "<center><big><big>Armor Equipped<br></big></big>";
		}
		
				if ($type=="ua")
	   {
	   	 $updateequip="Update playerarmor SET equip=0 WHERE pid='$id' AND equip=1 AND location='$local'";
	    mysql_query($updateequip) or die("Could not update armor");	
		
		echo "<center><big><big>Armor UnEquipped<br></big></big>";
		}
?>

This is the query for the armor and where it displays the weapon and armor table.

Code: Select all

 <?php
   print "<center><h3>Armor</h3></center>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $selectarmor="SELECT * from playerarmor where pid='$id'";
      $selectarmor2=mysql_query($selectarmor) or die("could not select armor3");
      print "<table border='1' bordercolor='white' bgcolor='#FFFFFF' >";
      print "<tr><td><img src='Images/Name_Text.gif'></td><td>
	  <img src='Images/Defense_Text.gif'></td><td>
	  <img src='Images/Level_Text.gif'></td><td>
	  <img src='Images/Location_Text.gif'><td>
	  <img src='Images/Status_Text.gif'></td></tr>";
      while($selectarmor3=mysql_fetch_array($selectarmor2))
      {
       if ($selectarmor3[equip] == 1)
	   {$selectarmor3[equip] = "<img src='Images/Equipped_Text.gif'>" . " <a href='Equipment.php?equip=1&type=ua&local=$selectarmor3[location]'><img src='Images/unequip_Button.gif'></a><br><br>";}
	   else {$selectarmor3[equip] = "<A href='equipment.php?equip=1&randid=$selectarmor3[randid]&type=a&local=$selectarmor3[location]'><img src='Images/Equip_Button.gif'></a>";} 
	    $randid = $selectarmor3[randid];  
	   print "<tr><td><center>$selectarmor3[name]</center></td><td><center>$selectarmor3[defense]</center></td><td><center>$selectarmor3[level]</center></td><td><center>$selectarmor3[location]</center></td><td><center>$selectarmor3[equip]</center></td>   
</tr>";  
      }

      print "</table>";
      print "</td></tr></table>";    
      print "</center>";
 }

?>
Any help is appreciated! Thanks for anyone who can help! :)
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Updating defense and displaying it real time.

Post by hallsofvallhalla »

not sure exactly how you have things setup. Don't they have to refresh to make the equipment update work anyways? If so then it should update on refresh. Make sure it is pulling stat info after the update also. Make the update the first thing that runs.
rapid3642
Posts: 45
Joined: Thu Nov 26, 2009 9:38 pm

Re: Updating defense and displaying it real time.

Post by rapid3642 »

Yea let me know if I could provide any more information.

Well actually i have it to were the equip is scripted in the same page so actually it doesn't refresh when someone equips a piece of armor. and yup I had the update the first thing that runs then at the end it sets the variable and prints it. Hey whats a good free video recorder that i could use to make a quick video to help demonstrate whats going on. And Could i upload a video on these forums to show you ppl whats going on?
Post Reply

Return to “Advanced Help and Support”