Jump to content
MakeWebGames

Help needed


boots

Recommended Posts

I have been trying to make a link in the jail so players can just click the link and use an item in the inventory to release them out of jail.the item works well but they have to go to the ivntory to use it

this is what i have

[<a href='itemuse.php?ID=109]}'>use</a>]

the name of the item is lock pick, the itemid is 109

iam no coder so maybe this is a easy one for you guys but ive been playing around with it for hours

Link to comment
Share on other sites

Not being funny but why are you trying to make a php web browser game when you cannot code?

Each player has an inventory of which the item id, quantity and userid is stored in the inventory database.

So you will need to reference that table to see if they have any of the item if they do then continue and display the link to use the item.

Reduce the qty by 1 or delete if its their last one.

Perform the appropriate action.

Thats the structure of the code why not try and create it.

Link to comment
Share on other sites

Not being funny but why are you trying to make a php web browser game when you cannot code?

Each player has an inventory of which the item id, quantity and userid is stored in the inventory database.

So you will need to reference that table to see if they have any of the item if they do then continue and display the link to use the item.

Reduce the qty by 1 or delete if its their last one.

Perform the appropriate action.

Thats the structure of the code why not try and create it.

 

I believe that's already been done through the item use and user edit attributes in creating an item.

To address the issue you have, Try looking for something like this in the source of inventory.php

<a href="itemuse.php?ID={$r['itmid']}"]}">Use</a>

Or something similar.

Link to comment
Share on other sites

iam trying to learn how to code but find it hard,

[<a href='itemuse.php?ID=109'>lock pick</a>]

i know this is the itemid, but it tells me Invalid item ID !

the item id changes for each player ???

i will keep ploding along untill i work it out

Link to comment
Share on other sites

iam trying to learn how to code but find it hard,

[<a href='itemuse.php?ID=109'>lock pick</a>]

i know this is the itemid, but it tells me Invalid item ID !

the item id changes for each player ???

i will keep ploding along untill i work it out

Does the item have any use effects? Have you double checked the item ID against the database?

Link to comment
Share on other sites

I believe that's already been done through the item use and user edit attributes in creating an item.

To address the issue you have, Try looking for something like this in the source of inventory.php

<a href="itemuse.php?ID={$r['itmid']}"]}">Use</a>

Or something similar.

r['itmid']

is not a global so where is the OP going to get that value from?

Hence why it works on the inventory page but not elsewhere.

Link to comment
Share on other sites

jailcheck..?

Not got a clue what your talking about eh

 

if($r['effect1_on'])
{
 $einfo=unserialize($r['effect1']);
 if($einfo['inc_type']=="percent")
 {
   if(in_array($einfo['stat'],array('energy','will','brave','hp')))
   {

     $inc=round($ir['max'.$einfo['stat']]/100*$einfo['inc_amount']);
   }
   else
   {
     $inc=round($ir[$einfo['stat']]/100*$einfo['inc_amount']);
   }
 }
 else
 {
   $inc=$einfo['inc_amount'];
 }
 if($einfo['dir']=="pos")
 {
   if(in_array($einfo['stat'],array('energy','will','brave','hp')))
   {
     $ir[$einfo['stat']]=min($ir[$einfo['stat']]+$inc, $ir['max'.$einfo['stat']]);
   }
   else
   {
     $ir[$einfo['stat']]+=$inc;
   }
 }
 else
 {

     $ir[$einfo['stat']]=max($ir[$einfo['stat']]-$inc, 0);

 }
 $upd=$ir[$einfo['stat']];
 if(in_array($einfo['stat'], array('strength', 'agility', 'guard', 'labour', 'IQ')))
 {
   $db->query("UPDATE `userstats` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}");
 }
 else
 {
   $db->query("UPDATE `users` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}");
 }
}

 

This.

Edited by sniko
Link to comment
Share on other sites

if($r['effect1_on'])
{
 $einfo=unserialize($r['effect1']);
 if($einfo['inc_type']=="percent")
 {
   if(in_array($einfo['stat'],array('energy','will','brave','hp')))
   {

     $inc=round($ir['max'.$einfo['stat']]/100*$einfo['inc_amount']);
   }
   else
   {
     $inc=round($ir[$einfo['stat']]/100*$einfo['inc_amount']);
   }
 }
 else
 {
   $inc=$einfo['inc_amount'];
 }
 if($einfo['dir']=="pos")
 {
   if(in_array($einfo['stat'],array('energy','will','brave','hp')))
   {
     $ir[$einfo['stat']]=min($ir[$einfo['stat']]+$inc, $ir['max'.$einfo['stat']]);
   }
   else
   {
     $ir[$einfo['stat']]+=$inc;
   }
 }
 else
 {

     $ir[$einfo['stat']]=max($ir[$einfo['stat']]-$inc, 0);

 }
 $upd=$ir[$einfo['stat']];
 if(in_array($einfo['stat'], array('strength', 'agility', 'guard', 'labour', 'IQ')))
 {
   $db->query("UPDATE `userstats` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}");
 }
 else
 {
   $db->query("UPDATE `users` SET {$einfo['stat']} = '{$upd}' WHERE userid={$userid}");
 }
}

 

This.

 

Point out the jailcheck there then as I do not see it.

I believe he was referring too

if($ir['jail'])

Which wouldnt throw a invalid ID anyway it would simply state you cannot access this page.

Its more likely the OP isnt referring to the correct ID. Get the inv_itemid number.

Link to comment
Share on other sites

Point out the jailcheck there then as I do not see it.

I believe he was referring too

if($ir['jail'])

Which wouldnt throw a invalid ID anyway it would simply state you cannot access this page.

Its more likely the OP isnt referring to the correct ID. Get the inv_itemid number.

If you've used this, then there is a jail check: http://prntscr.com/gpyms

To be honest, I think I've read this whole topic wrong... Ahaha.

Link to comment
Share on other sites

Nope link is fine. Invalid item ID is what it says

The $_GET['ID'] has passed which is the first check in the itemuse file

Next is a query for the item number and userid if that fails you get Invalid item id and that doesnt appear anywhere else in that file.

So either the item id is incorrect OR the user id isnt.

Link to comment
Share on other sites

the item id is correct it works fine when uesed from the inventory but when i place a link in jail.php i get Invalid item ID

the id is 109

<a href='itemuse.php?ID=109'>lock pick</a>

I dont understand it i think i will have to learn a lot more,so for now the item can be used from the inventory

i give up

Link to comment
Share on other sites

You can maybe try something like this

if ($ir['jail'])
{
echo "<b>NB:</b> You are currently in jail for {$ir['jail']} minutes.<br />";
}

and I replaced it with this:

$key=$db->query("SELECT * FROM inventory WHERE inv_itemid = *2* && inv_userid = {$ir['userid']}");
while($jk=$db->fetch_row($key))
if ($ir['jail'])
{
echo '<b>NB:</b> You are currently in jail for {$ir['jail']} minutes.<br />';
if ($db->num_rows($jkey)
{
echo'
You currently have {$jk['inv_qty']} Jail Key(s)<br />
Use your <a href="itemuse.php?ID={$jk['inv_itemid']}">Jail Key</a> to get out<br />';
}	
}

Also, if you want you can make this change to itemuse.php

Find:

echo $r['itmname'] . ' used successfully!'

and replace it with:

echo $r['itmname'] . ' used successfully!<br />';
        echo 'Return <a href="index.php">Home<a/>;

 

Change it to your *item id* number for your jail keys

Also if you wanted to you could make the same edits in the header to work for an item that gets you out of the hospital too

Link to comment
Share on other sites

Barking up the wrong tree.

The OP wishes to use an item to get the player out of jail. The itemuse code does not have nor has it ever had if your in jai lalalalal. Could we please move along from jailcheck (shoots the person that mentioned it).

Moving along......what mcc version 2.x.x? which if I remember correctly could be more the issue at hand.

The inventory query code posted by Kylemassacre bring us all the way back to what I told you to try and code yourself in the first reply of which you didnt try. Yay 3 pages of efficiency lol

Link to comment
Share on other sites

As Kyle and ruler said ... the easiest way to do this is to use the actual ID number from the items table. The other thing you may have to do is do a time check as well for how long the user is in jail. This of course is assuming that you are talking about using a release item for you as the player, not another player release. For that there is the bail and bust systems.

Link to comment
Share on other sites

or

 


/*
 -- We are in jail.php
 -- This portion will show the link to use the jail key
  -- Change the value of $jailkey to match the correct item id
*/
      $jailkey = 109;

if( has_item($jailkey) ) {
    echo '<a href="?use_key=TRUE">Use Jail Key</a>';
}

/*
  -- We are in jail.php
  -- Somewhere near the top, or bottom.... you decide.
*/

$_GET['use_key'] = filter_var($_GET['use_key'], FILTER_VALIDATE_BOOLEAN) ? $_GET['use_key'] : FALSE;
if( $_GET['use_key'] == TRUE ) {
      /*
           -- Not sure if you want a success rate of the key, for example; 70% of the time the key works...
           -- If so, use mt_rand() and an if() statement
     */
      if( !has_item($jailkey) ) {
          echo 'You don\'t have a jail key!';
      } else {
          echo 'The door unlocks when you used the jail key!';
          item_remove($userid, $jailkey, 1);
          $db->query("UPDATE `users` SET `jail`=0 WHERE `userid`={$userid}");
      }
}

function has_item($itemid) {
global $db, $userid;
     $item = $db->query("SELECT `inv_id` FROM `inventory` WHERE (`inv_itemid`={$itemid}) AND (`inv_userid`={$userid}) AND (`inv_qty` > 0)");
     if( $db->num_rows($item) ) {
        return TRUE;
     } esle {
        return FALSE;
     } 
}
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...