From The Mana World
m (Gumi moved page User:Meko/CheckInventory to User:Gumi/CheckInventory: Automatically moved page while renaming the user "Meko" to "Gumi")
 
(No difference)

Latest revision as of 19:42, 15 June 2020

(shamelessly skips the introductory blah blah)

Example Usage

get an item

setarray @getitem$, "Acorn";
setarray @getitem, 1;
callfunc "CheckInventory";

remove an item

setarray @delitem$, "Acorn";
setarray @delitem, 1;
callfunc "CheckInventory";

remove 2 items and get an item

setarray @delitem$, "Acorn", "Root";
setarray @delitem, 1, 1;
setarray @getitem$, "RedApple";
setarray @getitem, 1;
callfunc "CheckInventory";

remove an item and zeny and get another item

setarray @delitem$, "SnakeSkin";
setarray @delitem, 1;
setarray @getitem$, "LeatherPatch";
setarray @getitem, 1;
set @delzeny, 500;
callfunc "CheckInventory";

The zeny transaction will ONLY occur if all the items can be added/removed. You can also use @getzeny to add zeny.


Error handlers

If a problem happens, @check_fail will be a non-0 value. You can either choose to use the default error handlers or to set your own.

0 = no error
1 = missing required items
2 = overweight
3 = no room in inventory
4 = not enough zeny

default handlers

catch-all handler

if (@check_fail)
    close;

This code will use the default handlers and stop the script if an error is found.

custom handlers

to use custom handlers, you need to set a special variable to disable the default handlers.

@silent  = use custom handlers for all errors
@silent1 = use custom handler for error 1 and default handlers for the others
@silent2 = use custom handler for error 2 and default handlers for the others
@silent3 = use custom handler for error 3 and default handlers for the others
@silent4 = use custom handler for error 4 and default handlers for the others

The @silentX variables can be combined but if you want to handle all four errors please use @silent. You do not need to handle weight, zeny and inventory if you just want to delete items so you can use @silent and just handle error 1.

handle all

setarray @delitem$, "SnakeSkin", "Root", "GreenApple";
setarray @delitem, 1, 5, 20;
setarray @getitem$, "ReedBundle", "CottonCloth";
setarray @getitem, 12, 1;
set @delzeny, 500;
set @silent, 1;
callfunc "CheckInventory";

if (@check_fail == 1) goto L_Items;
if (@check_fail == 2) goto L_Weight;
if (@check_fail == 3) goto L_Inventory;
if (@check_fail == 4) goto L_Zeny;

mes "Transaction successful";
close;

L_Items:
    mes "You do not have the required items.";
    close;

L_Weight:
    mes "You need to drop some weight.";
    close;

L_Inventory:
    mes "You are carrying too much items.";
    close;

L_Zeny:
    mes "You do not have enough zeny. Go sell your house and try again.";
    close;

handle only some errors

setarray @delitem$, "SnakeSkin", "Root", "GreenApple";
setarray @delitem, 1, 5, 20;
setarray @getitem$, "ReedBundle", "CottonCloth";
setarray @getitem, 12, 1;
set @delzeny, 500;
set @silent3, 1;
set @silent4, 1;
callfunc "CheckInventory";

if (@check_fail == 3) goto L_Inventory;
if (@check_fail == 4) goto L_Zeny;

mes "Transaction successful";
close;

L_Inventory:
    mes "You are carrying too much items.";
    close;

L_Zeny:
    mes "You do not have enough zeny. Go sell your house and try again.";
    close;