Jump to content
  • 0
Sign in to follow this  
Zirius

Check how many items free space & available weight in inventory

Question

Hello! I am going to create an NPC that gives non stackable items and afraid that if the player has no free space, he might not get them all.

 

What function can give me something like 

 

if (freespace() > 5 && freeweight() > 3000 ) {

    //give 5 items with sum of 3000 weight

}

 

is there a function that gives freespace and free weight already?

 

Thanks!

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0
*checkweight(<item id>,<amount>{,<item id>,<amount>,<item id>,<amount>,...});*checkweight("<item name>",<amount>{,"<item name>",<amount>,"<item name>",<amount>,...});*checkweight2(<id_array>,<amount_array>);These functions will compute and return 1 if the total weight of the specified number of specific items does not exceed the invoking character's carrying capacity, and 0 otherwise. It is important to see if a player can carry the items you expect to give them, failing to do that may open your script up to abuse or create some very unfair errors.The second function will check an array of items and amounts, and alsoreturns 1 on success and 0 on failure.The functions, in addition to checking to see if the player is capable of holding a set amount of items, also ensure the player has room in their inventory for the item(s) they will be receiving.Like 'getitem', this function will also accept an 'english name' from the database as an argument.

Share this post


Link to post
Share on other sites
  • 0

You can also use these player-based variables to know about the weight of the player:

 

Weight - Amount of weight the character currently carries. Display as in Weight/10.MaxWeight - Maximum weight the character can carry.

Share this post


Link to post
Share on other sites
  • 0

 

 

*checkweight(<item id>,<amount>{,<item id>,<amount>,<item id>,<amount>,...});*checkweight("<item name>",<amount>{,"<item name>",<amount>,"<item name>",<amount>,...});*checkweight2(<id_array>,<amount_array>);These functions will compute and return 1 if the total weight of the specified number of specific items does not exceed the invoking character's carrying capacity, and 0 otherwise. It is important to see if a player can carry the items you expect to give them, failing to do that may open your script up to abuse or create some very unfair errors.The second function will check an array of items and amounts, and alsoreturns 1 on success and 0 on failure.The functions, in addition to checking to see if the player is capable of holding a set amount of items, also ensure the player has room in their inventory for the item(s) they will be receiving.Like 'getitem', this function will also accept an 'english name' from the database as an argument.

 

 

Sorry, got lost on:

 

*checkweight2(<id_array>,<amount_array>);

 

Why is this an array?

 

Do you have example bro?

Share this post


Link to post
Share on other sites
  • 0

If I understand it right, it's for when you have an array with ItemIDs to give and another array with amounts, like this:

setarray .itemIDs[0],512,7049,4001,985; // Apple, Stone, Poring Card, Eluniumsetarray .itemAmount[0],10,20,1,15;if ( checkweight2(.itemIDs,.itemAmount) ) {    for ( .@i = 0; .@i < getarraysize(.itemIDs); .@i++) {        getitem .itemIDs[.@i],.itemAmount[.@i];    }} else {    dispbottom "You don't have enough space in your inventory to get the items!";}end;
Edited by Garr

Share this post


Link to post
Share on other sites
  • 0

 

If I understand it right, it's for when you have an array with ItemIDs to give and another array with amounts, like this:

setarray .itemIDs[0],512,7049,4001,985; // Apple, Stone, Poring Card, Eluniumsetarray .itemAmount[0],10,20,1,15;if ( checkweight2(.itemIDs,.ItemAmount) ) {    for ( .@i = 0; .@i < getarraysize(.ItemIDs); .@i++) {        getitem .ItemIDs[.@i],.ItemAmount[.@i];    }} else {    dispbottom "You don't have enough space in your inventory to get the items!";}end;

 

Sweet! Thanks man, will try that.

Share this post


Link to post
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
Answer this question...

×   Pasted as rich text.   Restore formatting

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.