MV Checking for no weapons

Let's assume there's only 2 possible weapons in my game - 15 and 16. I made this little test event:

1597948055046.png


What's wrong with it?
It works always. When I gave myself weapons 15 and 16 with different event, the event still returns "you have no weapons"
Script call is direct javascript code.

"hasWeapon(15) == false"

Would just be a string at that point, and any non-empty string evaluates to true. Which is why the condition is met and your message is shown.

Where is the hasWeapon function defined? Who are you checking has the weapon?
Ah, yeah, I forgot it's not standard MV. I'm doing it with this little script:

1597956164624.png


So I'm guessing the correct thing would be

1597956280469.png


but that gets me an error as soon as I get into the map with that test event, without even executing that event:
1597956365969.png


Which is weird, because the function works just fine in other events.

I guess some new plugin work made a bit of a mess in my project...

By the way, your hidden choices is one of my favourite plugins, Hime - thank you for it!
Let's assume there's only 2 possible weapons in my game - 15 and 16.
It works always. When I gave myself weapons 15 and 16 with different event, the event still returns "you have no weapons"
On Discord I sent you a patched version of "UsefulFunctions"...

You want to check if anyone has the weapon equipped?
...or if it is anywhere in the party inventory at all including equipped?
...or if it is anywhere in the party inventory at all but NOT including equipped?

Basically I rewrote those functions to this...
Spoiler
Code:
// Check Types:
//     0: All Inventory
//     1: Only Equipped
//     2: All Inventory EXCEPT equipped

    function hasWeapon(id, checkType) {
        checkType = checkType || 0;
        if (checkType === 2) {return $gameParty.hasItem($dataWeapons[id]);}
        if (checkType === 0) {return $gameParty.hasItem($dataWeapons[id], true);}
        for (actorId in $gameParty._actors) {
            if ($gameActors.actor($gameParty._actors[actorId])) var bool = $gameActors.actor($gameParty._actors[actorId])._equips[0]._itemId == id;
            if (bool) {return true;}
        }
        return false;
    }

    function hasArmor(id, checkType) {
        if (checkType === 2){return $gameParty.hasItem($dataArmors[id]);}
        if (checkType === 0){return $gameParty.hasItem($dataArmors[id], true);}
        for (actorId in $gameParty._actors) {
            if ($gameActors.actor($gameParty._actors[actorId])) {
                var bool = bool || $gameActors.actor($gameParty._actors[actorId])._equips[1]._itemId == id;
                bool = bool || $gameActors.actor($gameParty._actors[actorId])._equips[2]._itemId == id;
                bool = bool || $gameActors.actor($gameParty._actors[actorId])._equips[3]._itemId == id;
                bool = bool || $gameActors.actor($gameParty._actors[actorId])._equips[4]._itemId == id;
                if (bool) {return true;}
            }
        }
        return false;
    }
This allows to check for (0) All Inventory, (1) Only Equipped, or (2) All Inventory EXCEPT equipped.
Example: if you set the "checkType" to 2 it will only check the weapons/armors that are equipped in the party. 😉
Does that help?


Edit:
Also now creating my own Inventory Checking Plugin for more advanced usage for those interested...

Original thread: https://forums.rpgmakerweb.com/threads/checking-for-no-weapons.125497/