Jump to content

PHP Help?


entity

Recommended Posts

Hi, I've only just joined; but I've been a part of the PHP phenomena for quite a while now. Well I've been scripting a code for an Online RPG (Adventure Quest); this code allows you to work out stats. Anyway, I've been working quite hard on this code but I have finally come to a full stop on it. My problem is that stats can only be in 5's so 5 all the way up to 175 (unless your a staff member you can get anything as long as it is a multiple of five), my problem is I don't know how to make a validation code that will only allow multiples of five. Any help on this would be greatly appriciated as this is the first code I've written without copying parts here and there.
Thank you very much.

- entity
Link to comment
Share on other sites

i dont know your approach on this (how your numbers is sendt) but here is something for you to work on.
It wouldn't surprice me if there is an easier way though...
In this i've assumed that numbers sendt can be any sum of numbers

Test it with page.php?n=105 or whatever
[code]
<?

$number = $_GET['n'];
settype($number,"integer");
$max = "175";

if(!empty($number))
{
if($number > $max)
{
  print "The number is higher than $max";
}
else
{
if(substr($number, -1, 1)== "0" OR substr($number, -1, 1)== "5")
{
  print "Approved";
}
else
{
  print "Declined";
}
}
}
else
{
  print "No number is present";
  // note that a single 0 in $number will be seen as no number in this case
}
?>
[/code]
Link to comment
Share on other sites

Well that is pretty cool, would it help if I posted the code up? I'll do it anyways:

[code]
<?php
//
// Stats Calculator
// entity@entitys-arena.co.uk
// MWA HA HA
// Version 1.0
// Melee Attack Equation:
// (DEX / 16) + (STR / 16) + (LUK / 20)
// Ranged Attack Equation:
// (DEX / 8) + (LUK / 20)
// Magic Attack Equation:
// (DEX / 16) + (INT / 16) + (LUK / 20)
// Melee Attacks: STR / 8
// Ranged Attacks: (STR / 16) + (LUK / 20)
// Magic Attacks: INT / 8
//
$MStats = $str + $dex + $int + $end + $cha + $luck;
if(($str == "")||($dex == "")||($int == "")||($end == "")||($cha == "")||($luck == "")||($level == "")) {
echo("Please fill in all sections even if its just a zero ^_^\n");
}
elseif($level > "125") {
echo("You cannot go over the level of 125 at this time.\n");
}
elseif($account == "agx") {
    $account_type = "Adventurer/Guardian/X-Guardian";
    if(($str > "175")||($dex > "175")||($int > "175")||($end > "175")||($cha > "175")||($luck > "175")) {
    echo("Your stats do not go above 175, please go back and correct this.\n");
    }
    elseif($MStats > "625") {
    echo("You will not gain more than 625 stat points unless you are a staff member ¬_¬.\n");
    }
    else{
    // This section calculates your BtH for each weapon type
    // It will also work out BtH for pets ^_^
    // BtH - Str - Melee
    $SBtH = round(($dex / 16) + ($str / 16) + ($luck / 20));
    // BtH - Dex - Ranged
    $DBtH = round(($dex / 8) + ($luck / 20));
    // BtH - Int - Magic
    $IBtH = round(($dex / 16) + ($int / 16) + ($luck / 20));
    // BtH - Cha - Pets
    $CBtH = round($cha / 15 + 5);
    // This section calculates extra random damage gained for MRM & Pets
    // Xtra - Str - Melee
    $XStr = round($str / 8);
    // Xtra - Dex - Ranged
    $XDex = round($dex / 16 + $str / 16);
    // Xtra - Int - Magic
    $XInt = round($int / 8);
    // Xtra - Cha - Pets
    $XCha = round($cha / 15);
    // This part works out the chance you have to block with your current stats
    $CtB = round($dex / 10 + $luck / 20);
    // Now to work out the treasure chest you'll be getting!
    $WTcT = ($level + $luck / 5);
    if($WTcT < 30) {
    $TcT = "Small Treasure Chest - 125 Gold\n";
    }
    elseif(($WTcT >= 30)&&($WTcT <= 49)) {
    $TcT = "Treasure Chest - 275 Gold\n";
    }
    elseif(($WTcT >= 50)&&($WTcT <= 64)) {
    $TcT = "Big Treasure Chest - 425 Gold\n";
    }
    elseif(($WTcT >= 65)&&($WTcT <= 84)) {
    $TcT = "Huge Treasure Chest - 650 Gold\n";
    }
    elseif($WTcT >= 85) {
    $TcT = "Treasure Hoard - 800 Gold\n";
    }
    // Working out HP & MP
    $HP = round(($level * 5 + 100) * (1+($end / 100)));
    $MP = round(($level * 5 + 100) * (1+($int / 100)));
    // Working out weapon average
    $average = round(($base + $max) / 2);
    // Working out weapon random
    $random = $max - $base;
    echo("<table>");
    echo("<tr>");
    echo("<td colspan=\"2\">Account Details</td>");
    echo("</tr>");
    echo("<tr>");
    echo("<td><b>Account Type:</b></td>");
    echo("<td>$account_type</td>");
    echo("</tr>");
    echo("</table>");
    echo("<br /><br />");
    echo("<!-- BtH Start -->");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Bonus to Hit</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Melee BtH</b></td>\n");
    echo("<td>$SBtH%</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Ranged BtH</b></td>\n");
    echo("<td>$DBtH%</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Magic BtH</b></td>\n");
    echo("<td>$IBtH%</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Pet BtH</b></td>\n");
    echo("<td>$CBtH%</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<!-- BtH End -->\n");
    echo("<!-- Added Damage Section Start -->\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Added Damage</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Melee Damage</b></td>\n");
    echo("<td>+$XStr</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Ranged Damage</b></td>\n");
    echo("<td>+$XDex</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Magic Damage</b></td>\n");
    echo("<td>+$XInt</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Pet Damage</b></td>\n");
    echo("<td>+$XCha</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<!-- Added Damage Section End -->\n");
    echo("<!-- Random Section Start -->\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Chance to block</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Defence:</b></td>\n");
    echo("<td>$CtB%</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Treasure Chests</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>L Value:</b></td>\n");
    echo("<td>$level</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Treasure Chest:</b></td>\n");
    echo("<td>$TcT</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Weapon Averages and Random Damage</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Weapon Average:</b></td>\n");
    echo("<td>$max + $base / 2 = $average</td>\n");
    echo("</tr\n>");
    echo("<tr>\n");
    echo("<td><b>Weapon Random Damage:</b></td>\n");
    echo("<td>$max - $base = $random</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">HP & MP</td>\n");
    echo("</tr>\n");
    echo("<tr>");
    echo("<td><b>HP:</b></td>\n");
    echo("<td>$HP</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>MP:</b></td>\n");
    echo("<td>$MP</td>\n");
    echo("</tr>\n");
    echo("<!-- Random Section End -->\n");
    }
}
elseif($account == "staff") {
    $account_type = "Staff";
    // This section calculates your BtH for each weapon type
    // It will also work out BtH for pets ^_^
    // BtH - Str - Melee
    $SBtH = round(($dex / 16) + ($str / 16) + ($luck / 20));
    // BtH - Dex - Ranged
    $DBtH = round(($dex / 8) + ($luck / 20));
    // BtH - Int - Magic
    $IBtH = round(($dex / 16) + ($int / 16) + ($luck / 20));
    // BtH - Cha - Pets
    $CBtH = round($cha / 15 + 5);
    // This section calculates extra random damage gained for MRM & Pets
    // Xtra - Str - Melee
    $XStr = round($str / 8);
    // Xtra - Dex - Ranged
    $XDex = round($dex / 16 + $str / 16);
    // Xtra - Int - Magic
    $XInt = round($int / 8);
    // Xtra - Cha - Pets
    $XCha = round($cha / 15);
    // This part works out the chance you have to block with your current stats
    $CtB = round($dex / 10 + $luck / 20);
    // Now to work out the treasure chest you'll be getting!
    $WTcT = ($level + $luck / 5);
    if($WTcT < 30) {
    $TcT = "Small Treasure Chest - 125 Gold\n";
    }
    elseif(($WTcT >= 30)&&($WTcT <= 49)) {
    $TcT = "Treasure Chest - 275 Gold\n";
    }
    elseif(($WTcT >= 50)&&($WTcT <= 64)) {
    $TcT = "Big Treasure Chest - 425 Gold\n";
    }
    elseif(($WTcT >= 65)&&($WTcT <= 84)) {
    $TcT = "Huge Treasure Chest - 650 Gold\n";
    }
    elseif($WTcT >= 85) {
    $TcT = "Treasure Hoard - 800 Gold\n";
    }
    // Working out HP & MP
    $HP = round(($level * 5 + 100) * (1+($end / 100)));
    $MP = round(($level * 5 + 100) * (1+($int / 100)));
    // Working out weapon average
    $average = round(($base + $max) / 2);
    // Working out weapon random
    $random = $max - $base;
    echo("<table>");
    echo("<tr>");
    echo("<td colspan=\"2\">Account Details</td>");
    echo("</tr>");
    echo("<tr>");
    echo("<td><b>Account Type:</b></td>");
    echo("<td>$account_type</td>");
    echo("</tr>");
    echo("</table>");
    echo("<br /><br />");
    echo("<!-- BtH Start -->");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Bonus to Hit</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Melee BtH</b></td>\n");
    echo("<td>$SBtH%</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Ranged BtH</b></td>\n");
    echo("<td>$DBtH%</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Magic BtH</b></td>\n");
    echo("<td>$IBtH%</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Pet BtH</b></td>\n");
    echo("<td>$CBtH%</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<!-- BtH End -->\n");
    echo("<!-- Added Damage Section Start -->\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Added Damage</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Melee Damage</b></td>\n");
    echo("<td>+$XStr</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Ranged Damage</b></td>\n");
    echo("<td>+$XDex</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Magic Damage</b></td>\n");
    echo("<td>+$XInt</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Pet Damage</b></td>\n");
    echo("<td>+$XCha</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<!-- Added Damage Section End -->\n");
    echo("<!-- Random Section Start -->\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Chance to block</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Defence:</b></td>\n");
    echo("<td>$CtB%</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Treasure Chests</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>L Value:</b></td>\n");
    echo("<td>$level</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Treasure Chest:</b></td>\n");
    echo("<td>$TcT</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">Weapon Averages and Random Damage</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>Weapon Average:</b></td>\n");
    echo("<td>$max + $base / 2 = $average</td>\n");
    echo("</tr\n>");
    echo("<tr>\n");
    echo("<td><b>Weapon Random Damage:</b></td>\n");
    echo("<td>$max - $base = $random</td>\n");
    echo("</tr>\n");
    echo("</table>\n");
    echo("<br /><br />\n");
    echo("<table>\n");
    echo("<tr>\n");
    echo("<td colspan=\"2\">HP & MP</td>\n");
    echo("</tr>\n");
    echo("<tr>");
    echo("<td><b>HP:</b></td>\n");
    echo("<td>$HP</td>\n");
    echo("</tr>\n");
    echo("<tr>\n");
    echo("<td><b>MP:</b></td>\n");
    echo("<td>$MP</td>\n");
    echo("</tr>\n");
    echo("<!-- Random Section End -->\n");
}
?>
[/code]

It's pretty simple (and admittedly quite chunky) but it works well; I just need a little help with the finishing touches! ^_^
Link to comment
Share on other sites

[!--quoteo(post=373697:date=May 14 2006, 05:42 AM:name=entity)--][div class=\'quotetop\']QUOTE(entity @ May 14 2006, 05:42 AM) [snapback]373697[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi, I've only just joined; but I've been a part of the PHP phenomena for quite a while now. Well I've been scripting a code for an Online RPG (Adventure Quest); this code allows you to work out stats. Anyway, I've been working quite hard on this code but I have finally come to a full stop on it. My problem is that stats can only be in 5's so 5 all the way up to 175 (unless your a staff member you can get anything as long as it is a multiple of five), my problem is I don't know how to make a validation code that will only allow multiples of five. Any help on this would be greatly appriciated as this is the first code I've written without copying parts here and there.
Thank you very much.

- entity
[/quote]
Hey! I've played your game before. Pretty cool! So basically what you want to do is only want to have 5,10,15,20,25,30,35....175 ? how about this:

[code]
<?php
   if ($_POST['blah']) {
      if (is_numeric($_POST['blah'])){
         echo $_POST['blah'];  
           if (($_POST['blah'] % 5) == 0) {
            echo " is divisible by 5.";
           } else {
              echo " is NOT divisible by 5.";
         }
      } else {
         echo "Please enter in a valid number";
      }
   } else {
        echo "Please enter in a number";
     }    

   echo "<br><br>";
   echo "<form action='$PHP_SELF' method ='post'>";
   echo "<input type = 'text' name='blah' size ='5'>";
   echo "<input type = 'submit' value='check num'>";
   echo "</form>";
?>
[/code]

now it's not really that long. it's just an example of it in action. the only line that you really need to pay attention to is this:

[code]
if (($_POST['blah'] % 5) == 0) {
[/code]

this takes the number in question ($_POST['blah]) and divides it by 5 and returns the remainder. if the remainder is zero, then it echos 'this number is divisible by 5. otherwise, it is not divisible by 5.

Now, as far is only MAKING it divisible by 5, well you can just round up to the next divisible number. for example:

[code]
$num = 213;
$blah = ($num % 5);
if ($blah != 0) {
   $num = $num + $blah;
}
[/code]

I think you are probably php saavy enough to figure out how to make use of this spiffy little operator [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
Link to comment
Share on other sites

Sorry about the double post guys, but thing is I've just noticed something about my script and I've been working on this for aggggges; well I'm doing quite a few calculations in there, but quite a few seem to come out wrong,
[code]
$SBtH = round($dex / 16 + $str / 16 + $luck / 20);
[/code]
Well what is supposed to happen there
is this:
$dex, $str and $luck are all brought from a form, well their numbers are
$dex = 100
$str = 100
$luck = 20
so what happens is:
100 divided by 16 = 6.25
+
100 divided by 16 = 6.25
+
20 divided by 20 = 1

once added altogether this should equal
8.50 rounded up to 9 but what I get is 17 which is wrong but so is the nine... what it is supposed to be is 14... what is going on here? Can anyone give me a few hints please?
Link to comment
Share on other sites

[code]$dex = 100; // normally retrieved from the $_POST array
$str = 100;
$luck = 20;
$SBtH = round($dex / 16 + $str / 16 + $luck / 20);
echo $SBtH;[/code]
That produces the correct answer (14). If your code doesn't then there's either something tragically wrong with your code or maybe you're looking at an older version or it's not uploaded to the server or something.

If it really doesn't work - can we see some of the code that processes the form data
Link to comment
Share on other sites

Well, I'm still hving problems, I can't seem to find a way to implement Crayon Violent's idea, I'll post the code and could you try and see how it could be fixed? Cheers ^_^

PS: Sorry for all the double posting by the way!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.