Original Source
- Original title: MZ RPG Maker MZ Javascript Show Choices Help
- Original author: icycold2367
- Original date: February 7, 2024
- Source thread: https://forums.rpgmakerweb.com/threads/rpg-maker-mz-javascript-show-choices-help.165548/
- Source forum path: Game Development Engines > RPG Maker Javascript Plugins > Learning Javascript
Summary
For those still searching in the future. I figured a solution. Not sure about why it's still a problem biut found a workaround that works. This allows items to add conditional branch just off of being in the inventory. It isn't complete but it works for what I needed it for. [CGMZ] Conditional Choices for RPG Maker MZ by Casper Gaming Add conditions to choices in the choice window casper-gaming.itch.io
Archived First Post
[CGMZ] Conditional Choices for RPG Maker MZ by Casper Gaming
casper-gaming.itch.io
This is also a valid option as well.
Caethyril's MZ Plugins
forums.rpgmakerweb.com
Thank you @Trihan
Little Backstory,
I was wondering if someone would be able to assist me in debugging why this function is not working? I'm not a master programmer and alot of this is written with ChatGPT's help on some things. My goal of this is that it will display the names of the seeds that are currently in your inventory and when selected perform the common event that the constant assigned to them.
Current Problem,
- Does not display any of the choices ingame. Just a blank menu I can exit out of.
How I call this is with a script in an event by just calling the function
function checkSeedAvailability() {
const seedCommonEvents = [
{ name: "Carrot Seeds", eventId: 125 },
{ name: "Corn Kernals", eventId: 123 },
{ name: "Potato Sprouts", eventId: 122 },
{ name: "Cabbage Seeds", eventId: 124 },
{ name: "Radish Seeds", eventId: 126 },
{ name: "Onion Seeds", eventId: 127 },
{ name: "Strawberry Seed", eventId: 128 },
{ name: "Pumpkin Seeds", eventId: 129 },
{ name: "Bean Seeds", eventId: 130 },
{ name: "Cashew Seeds", eventId: 131 },
{ name: "Tomato Seeds", eventId: 132 },
{ name: "Wheat Seeds", eventId: 133 },
{ name: "Zuchinni Seeds", eventId: 134 },
{ name: "Lettuce Seeds", eventId: 135 },
{ name: "Blueberry Seeds", eventId: 136 },
{ name: "Broccoli Seeds", eventId: 137 },
];
const isEquippedWithSeedBag = $gameParty.leader().equips().some(function (equip) {
return equip && equip.meta.SeedBag === 'true';
});
if (isEquippedWithSeedBag) {
const availableSeeds = $dataItems.filter(function (item) {
return item && $gameParty.numItems(item) > 0;
});
const seedChoices = availableSeeds.map(function (seed) {
return seed.name;
});
if (seedChoices.length > 0) {
$gameMessage.setChoices(seedChoices, 0, -2, 0);
$gameMessage.setChoiceCallback(function (choiceIndex) {
if (choiceIndex === -2) {
$gameTemp.reserveCommonEvent(20);
return;
}
const selectedSeed = availableSeeds[choiceIndex];
const selectedSeedName = selectedSeed.name;
const selectedEventId = seedCommonEvents.find(seed => seed.name === selectedSeedName)?.eventId;
if (selectedEventId) {
$gameTemp.reserveCommonEvent(selectedEventId);
} else {
$gameMessage.add(`You planted ${selectedSeedName}!`);
}
const selectedSeedId = selectedSeed.id;
$gameParty.gainItem($dataItems[selectedSeedId], -1);
});
} else {
$gameMessage.add("You don't have any seeds.");
}
} else {
$gameMessage.add("You need to equip a Seed Bag weapon to plant seeds.");
}
}
Downloads / Referenced Files
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadReferenced Images / Attachments
Creator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
Topic Summary
Loading summary...