lexington
08-14-2007, 08:42 PM
Hello, this should be very easy to do so if you could please help that would be great. I created a script but one part has me kinda confused. Instead of having to repeat a switch code over and over again, I rather use a variable for the switch name so that it could detect the mons_name from the DB and make a selection. I guess I would use an array for this, but I am not sure if that is the correct way of doing it. Here is what I have coded so far (I replaced the item name with (NORMAL ITEM *, and boss name with BOSS NAME HERE * in this post):
// normal item drops
if ($battle['mons_type'] == 1)
{
$newrand = rand(1,2);
switch($newrand)
{
case 1:
$stealitem = 'NORMAL ITEM 1';
break;
case 2:
$stealitem = 'NORMAL ITEM 2';
break;
}
}
// special boss item drops
if ($battle['mons_type'] == 2)
{
$boss_item = array(
'BOSS NAME HERE 1' => 'SPECIAL ITEM HERE 1',
'BOSS NAME HERE 2' => 'SPECIAL ITEM HERE 2',
'BOSS NAME HERE 3' => 'SPECIAL ITEM HERE 3'
);
// new boss entry
if ($battle['mons_name'] = 'BOSS NAME HERE 2')
{
$bossrand = rand(1,2);
switch($bossrand)
{
case 1:
$stealitem = $boss_item;
break;
case 2:
$stealitem = 'NORMAL ITEM HERE 1';
break;
}
}
I am not sure if I should use an array in this case or not. Basically I want the script to know if the mons name is the name of the mons, it will drop a specific item from my array. The script can already detect the mons_name, so how should I write this so that when it detects the mons name it can select the special item I have assigned? I hope this makes sense.
// normal item drops
if ($battle['mons_type'] == 1)
{
$newrand = rand(1,2);
switch($newrand)
{
case 1:
$stealitem = 'NORMAL ITEM 1';
break;
case 2:
$stealitem = 'NORMAL ITEM 2';
break;
}
}
// special boss item drops
if ($battle['mons_type'] == 2)
{
$boss_item = array(
'BOSS NAME HERE 1' => 'SPECIAL ITEM HERE 1',
'BOSS NAME HERE 2' => 'SPECIAL ITEM HERE 2',
'BOSS NAME HERE 3' => 'SPECIAL ITEM HERE 3'
);
// new boss entry
if ($battle['mons_name'] = 'BOSS NAME HERE 2')
{
$bossrand = rand(1,2);
switch($bossrand)
{
case 1:
$stealitem = $boss_item;
break;
case 2:
$stealitem = 'NORMAL ITEM HERE 1';
break;
}
}
I am not sure if I should use an array in this case or not. Basically I want the script to know if the mons name is the name of the mons, it will drop a specific item from my array. The script can already detect the mons_name, so how should I write this so that when it detects the mons name it can select the special item I have assigned? I hope this makes sense.
