PDA

View Full Version : Classic DB Spawngroup Fix


sotonin
10-11-2004, 08:29 AM
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.


<?

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!

sdabbs65
10-11-2004, 11:08 AM
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.

cavedude
10-11-2004, 12:05 PM
This will work for any database created with the help of EQBuilder. Nice fix!

RangerDown
10-11-2004, 03:07 PM
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.

sotonin
10-11-2004, 05:55 PM
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 )

sotonin
10-11-2004, 05:57 PM
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. :wink:

Arcane
10-12-2004, 12:53 AM
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.