Is this possible to achieve? I'd like to force use an item in battle on the last target the same way you can with a skill, but there's no option. Anyone have any ideas? Maybe if I could use a script call to consume the item?
MZ Is there a method or script to 'force action' for an item instead of a skill?
RPG Maker MZ SupportWell, you can just make all your items into skills. Make a new skill type called use item, put them in there. Additionally, you can the use a custom cost notetag to make the skill cost items. That way you got all the benefits of a skill and action sequencing while also being able to have 2 separate effects in and out of battle (For example, my potion heals over time in battle, but fully heals on the map.)
I will admit that may be a lot of work depending on where you're at with your project.
I will admit that may be a lot of work depending on where you're at with your project.
The action objects determine whether the contained action is an item or a skill, but they work identically. So as long as you set the forced action up as an item, you don't need to do anything else. (since Game_Battler.prototype.forceAction takes a skill ID, you'll have to set the action up manually as a new Game_Action and then push it to the _actions array)
The Force Action mechanism should work just as well for an item as for a skill. Unfortunately, the UI doesn't allow for that, but all you would need to do is copy-paste the code for Force Action and tweak it.
If this is for an enemy though, it would probably be easier for you to just make a copy of the item as a skill.
I'll explain how to do both, and then you can choose. These steps work in either MV or MZ, for the record.
To convert a skill into an item, take the following steps:
To force an action that's an item, paste the following into a text file, call it anything you want (for example, "SFG_ForceItem.js"), and enable it as a plugin (no need to credit me – I literally just copy-pasted the engine code and made a few small changes):
Now, you can use a script call like the following:
Note that this probably ignores the actual count of items the party has if you use it to force a party action. If that's an issue, you can use Conditional Branch and Gain Items to simulate the missing parts.
If this is for an enemy though, it would probably be easier for you to just make a copy of the item as a skill.
I'll explain how to do both, and then you can choose. These steps work in either MV or MZ, for the record.
To convert a skill into an item, take the following steps:
- Save your project and quit the editor.
- Open the file data/Items.json in a text editor. Turn off line wrapping, and search for the name of the item you want to copy.
- Select the entire line and copy it. Make sure it really is the entire line. There should be a
{at the beginning and a}at the end (and maybe a comma). - Make a copy of data/Skills.json so you can easily revert your changes, in case you mess something up.
- Open the file data/Skills.json in a text editor. Scroll down to the very bottom and add a blank line above the
]which is on a line by itself. - At the very end of the previous line (just above the blank line), add a comma
, - Paste in the line that you copied from Items.json. If it ends with a comma, delete it.
- Open your project. Scroll down to the bottom of your skills list, and you'll see the new skill which is a duplicate of the item.
- Set the skill type to anything, and then set it back to None (or any other skill type you desire). Do the same with MP cost - change it to 1, then back to 0. You can also do the required weapons in the same way. If you don't do this, there's a possibility that the game may crash in some cases because the skill type and costs are not set.
- Click the "uses *!" button to set the use message, which will make it look exactly like if the party used an item.
To force an action that's an item, paste the following into a text file, call it anything you want (for example, "SFG_ForceItem.js"), and enable it as a plugin (no need to credit me – I literally just copy-pasted the engine code and made a few small changes):
JavaScript:
Game_Interpreter.prototype.forceItem = function(params) {
this.iterateBattler(params[0], params[1], battler => {
if (!battler.isDeathStateAffected()) {
battler.forceActionItem(params[2], params[3]);
BattleManager.forceAction(battler);
this.setWaitMode("action");
}
});
return true;
};
Game_Battler.prototype.forceActionItem = function(itemId, targetIndex) {
this.clearActions();
const action = new Game_Action(this, true);
action.setItem(itemId);
if (targetIndex === -2) {
action.setTarget(this._lastTargetIndex);
} else if (targetIndex === -1) {
action.decideRandomTarget();
} else {
action.setTarget(targetIndex);
}
if (action.item()) {
this._actions.push(action);
}
};
Now, you can use a script call like the following:
JavaScript:
this.forceItem([A, B, C, D]);
- Replace A with 0 if you want to force an enemy action, or 1 for a party action.
- Replace B with the index of the enemy or the ID of the actor.
- Replace C with the ID of the item to use.
- Replace D with the index of the target - if it's targeting a party member, this is the member's place in the formation, starting from 0. You can also use -1 for a random target or -2 to use the most recent target. (Note: -2 only works in MZ.)
Note that this probably ignores the actual count of items the party has if you use it to force a party action. If that's an issue, you can use Conditional Branch and Gain Items to simulate the missing parts.
Alternatively you may find this thread helpful:
forums.rpgmakerweb.com
I haven't tested, but I think there's a decent chance of that script call working in MZ as well. Just replace
How to use a item in eventing?
Hi, I can't figure out how to use a item in the eventing window. I want this to happen on a main map on player touch Hero consume item 1 .. must i 'change items' and make a eventing of the items effect and restore?
forums.rpgmakerweb.com
YOUR_ITEM_ID_HERE with a number, e.g. 5.The force action script would be great, however the script call doesn't seem to do anything, I've even tested it in a new project. Is something missing? Thank you for your help!
Hmm. I found an error in the code I posted and edited a fix. I wouldn't expect that error to result in nothing happening, but… perhaps there are some circumstances where that would be a possible outcome. Try the revised version and let me know if that works.
It's still the same. What I'm doing is using a new project with only this plugin enabled, activating an event that lowers everyone's HP to 1 and gives the player a potion (ID 7), and then activating an event which has a script of: this.forceItem([1, 1, 7, 0]); and nothing else. Is this correct or is the script missing something?
That looks right, unless I misunderstood the meaning of one of the 4 parameters. Did you try any other values? For example, what if the 4th parameter is 1?
It's still the same like that.
Is the issue with the script call this.forceItem? I don't know much about javascript but will the engine know what 'this' is referring to?
Ah I've figured it out, the script call has to be ran in battle to work (of course) sorry for not realising, thank you for your help!
It should actually possible to make Force Action work outside of battle, I believe, but that would be a whole separate issue. I'm not too surprised that the way I posted doesn't work.
In an event script call, including Control Variables and Conditional Branch scripts, "this" is always the current event interpreter, in other words, the Game_Interpreter object. (This is not true for other scripts, such as movement routes or damage formulas.)
Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-method-or-script-to-force-action-for-an-item-instead-of-a-skill.180631/