Check how many items free space & available weight in inventory

Zirius

New member
Messages
261
Points
0
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!

 
Code:
*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.
 
You can also use these player-based variables to know about the weight of the player:

Code:
Weight - Amount of weight the character currently carries. Display as in Weight/10.MaxWeight - Maximum weight the character can carry.
 
*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?

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

Code:
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;
 
Last edited by a moderator:
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.

 
Back
Top