boots Posted October 3, 2012 Share Posted October 3, 2012 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 Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 3, 2012 Share Posted October 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
sniko Posted October 3, 2012 Share Posted October 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
boots Posted October 3, 2012 Author Share Posted October 3, 2012 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 Quote Link to comment Share on other sites More sharing options...
Dave Posted October 3, 2012 Share Posted October 3, 2012 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? Quote Link to comment Share on other sites More sharing options...
sniko Posted October 3, 2012 Share Posted October 3, 2012 (edited) - forget this post - Edited October 3, 2012 by sniko Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 3, 2012 Share Posted October 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
sniko Posted October 3, 2012 Share Posted October 3, 2012 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. Yep, I just used $r as $result (from the query) if one was made... Quote Link to comment Share on other sites More sharing options...
tprice88 Posted October 3, 2012 Share Posted October 3, 2012 You most likely need to check the file iitemuse.php and see if theres a jailcheck that stops it from finding ids, then tell it to skip it if the id is 109 Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 3, 2012 Share Posted October 3, 2012 jailcheck..? Not got a clue what your talking about eh Quote Link to comment Share on other sites More sharing options...
tprice88 Posted October 3, 2012 Share Posted October 3, 2012 i haved used mccodes, yet but most games would have a jailcheck. i just noticed the link has a error looks like it should be [<a href='itemuse.php?ID=109'>use</a>] Quote Link to comment Share on other sites More sharing options...
sniko Posted October 3, 2012 Share Posted October 3, 2012 (edited) 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 October 3, 2012 by sniko Quote Link to comment Share on other sites More sharing options...
tprice88 Posted October 3, 2012 Share Posted October 3, 2012 Lol what is that, that coding looks so confusing. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 3, 2012 Share Posted October 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
tprice88 Posted October 3, 2012 Share Posted October 3, 2012 Maybe i think his link was bad also, not sure if he fixed it. Quote Link to comment Share on other sites More sharing options...
sniko Posted October 3, 2012 Share Posted October 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 3, 2012 Share Posted October 3, 2012 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. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 3, 2012 Share Posted October 3, 2012 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. You have " use an item in the inventory to release them out of jail" nothing to do with the gym. Quote Link to comment Share on other sites More sharing options...
boots Posted October 3, 2012 Author Share Posted October 3, 2012 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 Quote Link to comment Share on other sites More sharing options...
sniko Posted October 3, 2012 Share Posted October 3, 2012 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 This applies. http://prntscr.com/gq1li Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted October 4, 2012 Share Posted October 4, 2012 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 Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 4, 2012 Share Posted October 4, 2012 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 Quote Link to comment Share on other sites More sharing options...
newttster Posted October 5, 2012 Share Posted October 5, 2012 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. Quote Link to comment Share on other sites More sharing options...
sniko Posted October 5, 2012 Share Posted October 5, 2012 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; } } Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted October 5, 2012 Share Posted October 5, 2012 The has item would be better as a function in global_func so it can be used elsewhere. If your doing it might as well make the most of it! Otherwise good work Sniko.....your just too nice doing all the work for em :P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.