Canjucks Posted August 22, 2023 Posted August 22, 2023 I found this issue while back but now up to trying to plug this whole. I thought I had found a solution but really it wasn't. Looked good an all lol. Anyway so when you use an item if you have say maximum health or energy and the item effect is to increase the amount, what I'd like is a message that says don't do that, you're on the maximum and not allow the item to be used at all (not removed from inventory). this is what I have where I shove it in the item use function on inventory.inc file: if ($this->user->info->US_energy >= $this->user->info->US_maxEnergy) { return $this->error('You have enough energy go use some before loading up again'); } if ($this->user->info->US_brave >= $this->user->info->US_maxbrave) { return $this->error('You have enough brave go use some before loading up again'); } I think it will be a good one to fix up now as anyone who runs a game on GL currently they'll find this to be an issue. Quote
Ishraq Posted August 22, 2023 Posted August 22, 2023 This would only work when the users energy is equal to the max energy or brave is equal to max brave. You can just use == instead. As the energy will always be equal to or smaller, not bigger. To take it a step further, grab the items addition and see if there's space for it. So someone with 99 energy out of 100 won't waste an item if the use gives 50 as an example. If energy +50 > maxenergy then go use some first. Quote
Canjucks Posted August 22, 2023 Author Posted August 22, 2023 22 minutes ago, Ishraq said: This would only work when the users energy is equal to the max energy or brave is equal to max brave. You can just use == instead. As the energy will always be equal to or smaller, not bigger. To take it a step further, grab the items addition and see if there's space for it. So someone with 99 energy out of 100 won't waste an item if the use gives 50 as an example. If energy +50 > maxenergy then go use some first. I tried == but nit the result I was after. Not sure how to write the energy +50. It is a decent idea. I fear that my code is wrong in that its not doing the right thing in that its not checking the item for the effect used to be sure to go through any if statements of seeing if it is maxed out. so something like if item[effect] == energy and energy >= maxenergy then error else continue. Is it possible to give an error in the effects? like if ($new > $max) { $new = $max; return error "display stop"} Quote
newttster Posted August 22, 2023 Posted August 22, 2023 (edited) If ($itemid=Y) {$new=50} if ( $current == $max) {"You're wasting your time. You can't have more than the maximum"} if ( ($current + $new) > $max) {"The amount you're trying to add would carry you over the maximum, which is not allowed"} if ( ($current + $new) <= $max) {"You're good to go. You now have X amount of whatever"} Edited August 22, 2023 by newttster Quote
Ishraq Posted August 22, 2023 Posted August 22, 2023 46 minutes ago, newttster said: If ($itemid=Y) {$new=50} if ( $current == $max) {"You're wasting your time. You can't have more than the maximum"} if ( ($current + $new) > $max) {"The amount you're trying to add would carry you over the maximum, which is not allowed"} if ( ($current + $new) <= $max) {"You're good to go. You now have X amount of whatever"} Try this @Canjucks Quote
Canjucks Posted August 23, 2023 Author Posted August 23, 2023 18 hours ago, newttster said: If ($itemid=Y) {$new=50} if ( $current == $max) {"You're wasting your time. You can't have more than the maximum"} if ( ($current + $new) > $max) {"The amount you're trying to add would carry you over the maximum, which is not allowed"} if ( ($current + $new) <= $max) {"You're good to go. You now have X amount of whatever"} do I need to replace $max with column name i was to be checked? or assign it at least might be dull question but how does $itemid=Y equal the item Id? Quote
Ishraq Posted August 23, 2023 Posted August 23, 2023 The Y is just the value, if you call the column, the value would be on it. $this->item->effect or whatever its called. max would be your $this->user->info->US_maxEnergy Quote
newttster Posted August 23, 2023 Posted August 23, 2023 (edited) 7 hours ago, Canjucks said: do I need to replace $max with column name i was to be checked? or assign it at least might be dull question but how does $itemid=Y equal the item Id? I should have made it clearer. Call the information from the columns required from your db. In this case you would call item id 25 (I'm just using a random numer). In the same query you would be asking for the value of item id 25. I'm using 50 as the value pulled when you did the query. Therefore the if $itemid=25 then the value is 50. Leaving you with If ($itemid=Y) {$new=50}. Your query would look like somethig like this; $q=$db->query("SELECT `inv_qty` FROM `inventory` WHERE `inv_itemid`='25' AND `inv_userid`='{$ir['userid']}'"); $r=$db->fetch_row($q); If ($r[inv_qty'] <=0) {"You don't have any. Use another item"}; // Always verify if there is any in the inventory and always exit the page. exit($h->endpage()); If ($r['inv_itemid']=25) {$new=$r['value']} $new will be the value of whichever item you've chosen. In this example it would be 50. In the query inv_itemid would be the item from which you want to pull the value. I hope that helps make it clearer. Edited August 23, 2023 by newttster Quote
Canjucks Posted August 23, 2023 Author Posted August 23, 2023 thank you for the explanation it makes more sense to me now 🙂 Quote
newttster Posted August 23, 2023 Posted August 23, 2023 14 minutes ago, Canjucks said: thank you for the explanation it makes more sense to me now 🙂 You're welcome. Quote
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.