Jump to content
MakeWebGames

Item Use issue


Canjucks

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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"}
Link to comment
Share on other sites

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 by newttster
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

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