Jump to content
MakeWebGames

My first mod attempt


boionfire81

Recommended Posts

Attempting a fishing mod that will require the player to own a boat, a rod, and bait. Upon fishing 1 bait would be removed from their inventory. They would then receive 1-2 fish in their inventory upon success, or lose their rod and/or boat upon failure. But right now I can't even seem to get past the item check. Anyone care to take a look and let me know where I'm messing up at?

 

<?php

require('globals.php');


if($ir['hospital'] || $ir['jail']) {
   echo "This page can't be accessed while in jail or hospital.";

}
global $db;
   $query  = $db->query("SELECT `inv_qty` FROM inventory WHERE inv_userid = {$userid} AND `inv_itemid` = 40");
   $query  = $db->query("SELECT `inv_qty` FROM inventory WHERE inv_userid = {$userid} AND `inv_itemid` = 7");
   $query  = $db->query("SELECT `inv_qty` FROM inventory WHERE inv_userid = {$userid} AND `inv_itemid` = 51");

if($inv_qty == 0) {            
       echo "You are missing one of the required items. <a href='fishingshop.php' class='button'>Shop</a>";
       $h->endpage();
   exit;
           }


else
{

switch(mt_rand(1,10)) {
   case 1:

       if(mt_rand(1,3) ==1)  {

               item_remove(40,$userid,1);
           echo "You did not find any fish while fishing this turn.";
       }

   case 2:
   if(mt_rand(1,8) == 1) {
                      echo "Your rod broke in the water.";
                      item_remove(40,$userid,1);
                      item_remove(7,$userid,1);
           }
   case 3:     
   if(mt_rand(1,3) == 1) {
       $item = `inv_itemid`;
               item_add(50,$userid,1);
               item_remove(40,$userid,1);
               echo "You managed to catch a fish.";
           }

   case 4:
           if(mt_rand(1,6) ==1) {
           item_add(50,$userid,2);
       item_remove(40,$userid,1);
       echo "You grabbed 2 fish this time woa nice one.";


   }
   case 5:
           if(mt_rand(1,10) ==1) {
       item_remove(40,$userid,1);
       item_remove(7,$userid,1);
       item_remove(51,$userid,1);
       $hospital = mt_rand(1,3 * $ir['level']);
       $hospreason = $db->escape('Boat sunk while fishing.');
       $db->query("UPDATE `users` SET `hospital` = `hospital` + {$hospital},`hospreason` = '{$hospreason}' WHERE `userid` = {$ir['userid']}");
       echo "You're boat sunk while fishing you lost everything and landed in hospital for {$hospital} minutes.";


   }
}
}
/* Item ID Numbers
*bait = 40
*rod = 7
*fish = 50
*boat = 51
*/
$h->endpage();
exit;
Link to comment
Share on other sites

few things

1. why global the $db variable this is already done and should work in any files that has globals.php includes in.

2. Your 3 queries can be turned into 1

3. if($inv_qty == 0) you have to call for this. look into $db->num_rows($yourvariable) == 0)

4. you have the variables mixed up prob due to me being my mistake yesterday hehe

item_remove(userid,itemid,qty);
Link to comment
Share on other sites

  • You don't need to global $db - the scope hasn't changed from when it was instantiated.
  • Hardcoded item id's are grim. define() these, or put them into variables.
  • Your queries to check inventory are overwriting each other.
    • Assign them to different variables, or
    • Create 1 call to the database with 3 subqueries.

    [*]With your mt_rand() logic, you'll get cases with a blank outcome.

    [*]You don't need exit; at the end of the script - it may cause some weird errors with the header class (or a modified version of mccodes)

    [*]Your indentation is a mess. Set your IDE up to conform to PSR-2 standards.

Link to comment
Share on other sites

Ok so for the pull

 

require('globals.php');

$query = $db->query("SELECT `inv_qty` FROM inventory WHERE inv_userid = {$userid} AND `inv_itemid` = array('7','40','50','51')");

 

Keep in mind guys that php 5.6 has to be used with mccodes.

 

You could go

 

$fiems = array_unique(array(12,15,17,15));
$itemcheck = $db->query("SELECT `inv_qty` FROM `inventory` WHERE `inv_userid` = {$userid} AND `inv_itemid` = IN(".implode(',', $fiems)");
if(!$db->num_rows($itemcheck)) {
   echo "You are missing a required item.
   $h->endpage();
   exit;
}
Link to comment
Share on other sites

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.   Paste as plain text instead

  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...