Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Database/World Building

Development::Database/World Building World Building forum, dedicated to the EQEmu MySQL Database. Post partial/complete databases for spawns, items, etc.

Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2004, 08:29 AM
sotonin
Demi-God
 
Join Date: May 2004
Posts: 1,177
Default Classic DB Spawngroup Fix

Found a bug with the log parser we use to make the database. It seems spawngroups were being assigned 50% chance per npc, regardless of how many npcs were in the spawngroup. This caused a greater than 100% chance on groups with more than 2 npcs in it. Thus making the lower mobs on the list not spawn. I created a php script to fix this. Tested it today seems to work great. All our future databases will have this run before release now that we've identified the problem. You must have a php capable web server to run this script.

Fill it in with your own database mysql connect info.

Code:
<? 

class database {
	function database(){
		$dbhost = 'localhost';
		$dbuser = 'dbuser';
		$dbpass = 'dbpass';
		$db = 'database';
		$link = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($db) or die("Failed to select database with error: ".mysql_error());
	}

	function openConnectionWithReturn($query){
		$result=@mysql_query($query) or die("Query failed with error: ".mysql_error());
		return $result;
	}

	function openConnectionNoReturn($query){
		@mysql_query($query) or die("Query failed with error: ".mysql_error());
	}
}

$database = new database();

$from =0;
$from2 = 0;

$count_q = "SELECT * FROM spawngroup";
$count_r = mysql_query($count_q);
$count_x = mysql_num_rows($count_r);

while($from2 < $count_x) {
	$max_results = $from + 1000;
	
	$query = "SELECT * FROM spawngroup ORDER by id ASC LIMIT $from, $max_results";
	$result = mysql_query($query);
	
	while($row = mysql_fetch_array($result)){
		$spawngroupID = $row['id'];
		
		$query2 = "SELECT * FROM spawnentry WHERE spawngroupID='$spawngroupID'";
		$result2 = mysql_query($query2);
		$count = mysql_num_rows($result2);
		
		echo($spawngroupID . "<Br />");
		if (!$result2 || ($count<1)) {
			?>ERROR <?
		} else {
			if ($count==1) {
				$percent = 100;
			} else {
				$percent = (100/$count);
				$percent = round($percent);
			}
		
			while(($percent*$count)>100) {
				$percent=$percent-1;
			}
		
			$leftover = (100 - ($percent * $count));
			$final = $percent+$leftover;
			
			$i = 1;
		
			while($row2 = mysql_fetch_array($result2)){
				$npcID = $row2['npcID'];
				$chance = $row2['chance'];
			
				if (($count==1) && ($chance!=100)) {
					$query3 = "UPDATE spawnentry SET chance=100 WHERE spawngroupID=$spawngroupID AND npcID=$npcID";
				}
			
				if (($count==2) && ($chance!=50)) {
					$query3 = "UPDATE spawnentry SET chance=50 WHERE spawngroupID=$spawngroupID AND npcID=$npcID";
				} else {
					if (($i==$count)) {
						$query3 = "UPDATE spawnentry SET chance=$final WHERE spawngroupID=$spawngroupID AND npcID=$npcID";
					} else {
						$query3 = "UPDATE spawnentry SET chance=$percent WHERE spawngroupID=$spawngroupID AND npcID=$npcID";
					}
					$result3 = @mysql_query($query3);
					$i++;
				}
			}
		}
	}
	$from2 = $from;
	$from = $from + 1000;
}
	
	?>DONE!
Use it at your own risk. i've tested it but who knows what it may do for you. ALWAYS back up your database before doing something big like this.

hope it helps!
Reply With Quote
  #2  
Old 10-11-2004, 11:08 AM
sdabbs65
Dragon
 
Join Date: Dec 2003
Location: Earth
Posts: 818
Default ugh....

I tried php but seemed to do nothing..
tried to source it but no dice.

Content-type: text/html
X-Powered-By: PHP/4.3.4

<br />
Parse error: parse error, unexpected '}' in C:\eqemu\test.php on l
ine 46<br />


im sure there will be people asking what to do with it..
so I wanted to be the first.
Reply With Quote
  #3  
Old 10-11-2004, 12:05 PM
cavedude's Avatar
cavedude
The PEQ Dude
 
Join Date: Apr 2003
Location: -
Posts: 1,988
Default

This will work for any database created with the help of EQBuilder. Nice fix!
Reply With Quote
  #4  
Old 10-11-2004, 03:07 PM
RangerDown
Demi-God
 
Join Date: Mar 2004
Posts: 1,066
Default

Might I suggest a design fix in the code that would eliminate this problem in the future:

Don't require the chance to add up to 100. Let it add up to any arbitrary number, and the chance value is the mob's chance to spawn WHEN WEIGHED against the total chance points for that spawngroup. Doing it that way might make it a little more fool-tolerant.
__________________
<idleRPG> Rogean ate a plate of discounted, day-old sushi. This terrible calamity has slowed them 0 days, 15:13:51 from level 48.
Reply With Quote
  #5  
Old 10-11-2004, 05:55 PM
sotonin
Demi-God
 
Join Date: May 2004
Posts: 1,177
Default

ya i guess. But they probably wont change the code for a system that works fine. You just have to know wtf is going on with it )
Reply With Quote
  #6  
Old 10-11-2004, 05:57 PM
sotonin
Demi-God
 
Join Date: May 2004
Posts: 1,177
Default

Quote:
im sure there will be people asking what to do with it..
so I wanted to be the first.
it's quite simple. First you can't do it unless you have a php web server running. You change the lines at the top with your database name, user and password then you upload it to a web accessible path and run it from your browser. Thats that.
Reply With Quote
  #7  
Old 10-12-2004, 12:53 AM
Arcane
Sarnak
 
Join Date: Sep 2004
Location: Shreveport, LA
Posts: 81
Default

Even if you have php installed, if your web server doesn't know it's there, you will achieve the same results.

For a quick install, if you don't have IIS installed on a winpc, google for foxserv; the only problem with that is it installs MySQL as part of the package and points everything to it's installation. If you use this installation with Winbloze XtraPee, you will also need to change the .conf file for Apache and make a web directory somewhere other than under the foxserv root directory.
__________________
Echoes of the past lend themselves to the future (c) The Realms of Faust, 2001-2004 http://FaustRealms.servegame.com
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 04:06 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3