[RMMZ] PLUGIN TO CALL COMMON EVENT ON SKILL USE (COMBAT)

Posts

Pages: 1
Hi all!

I wanted to use a totally different Combat System compared to MZ's standard BS, to do so while keeping the normal combat HUD I thought about calling a CE during the skill use with two variables, one storing the skill ID and one storing the target. Then the Common Event would handle everything (it's a dice rolling system a la Chronicle Of Darkness)

Problem is that the CE doesn't show up DURING combat but after, having looked to the forum it seem that reserveCommonEvent doesn't allow the CE to start instantly

Anyone knows a workaround?

Here is the code!


//=============================================================================
// Plugin Name: Combat Event Trigger
// Author: Winthorp Darkrites (Winter Dream Games Creator)
// Description: Triggers a Common Event during combat actions and sets variables.
// Use: Feel free to use for private and commercial projects. Feel free to edit. Please give credits.
//=============================================================================

/*:
* @target MZ
* @plugindesc Triggers a Common Event during combat actions and sets variables for Skill ID and Target ID.
* @author Winthorp Darkrites
*
* @help WD_CombatEventTrigger.js
*
* This plugin calls a Common Event on skill use.
*
* It does not provide plugin commands.
*/

(function() {
// Register a new Game_Action prototype method
Game_Action.prototype.executeAction = function(target) {
// Call the original executeAction method
this.executeActionOrig(target);

// Check if the action is performed in battle
if ($gameParty.inBattle()) {
// Trigger a Common Event ID when a combat action is executed
var commonEventId = 1; // Replace 1 with the Common Event ID you want to trigger if different

// Check if the Common Event ID is valid
if (commonEventId > 0) {
$gameTemp.reserveCommonEvent(commonEventId);

// Set a variable equal to the skill ID used
var skillIdVariable = 1; // Replace 1 with the Variable ID to store the skill ID if different
if (skillIdVariable > 0) {
$gameVariables.setValue(skillIdVariable, this.item().id);
}

// Set a variable equal to the target's actor or enemy ID
var targetIdVariable = 2; // Replace 2 with the Variable ID to store the target's ID if different
if (targetIdVariable > 0) {
$gameVariables.setValue(targetIdVariable, target.isActor() ? target.actorId() : target.enemyId());
}
}
}
};
})();


Please be kind, I'm a newbie with coding ^^'
Marrend
Guardian of the Description Thread
21781
I'm not sure how much this helps, but, there's a few functions in Game_Interpreter listed under "Common Event" in rmmz_objects.js

// Common Event
Game_Interpreter.prototype.command117 = function(params) {
    const commonEvent = $dataCommonEvents[params[0]];
    if (commonEvent) {
        const eventId = this.isOnCurrentMap() ? this._eventId : 0;
        this.setupChild(commonEvent.list, eventId);
    }
    return true;
};

Game_Interpreter.prototype.setupChild = function(list, eventId) {
    this._childInterpreter = new Game_Interpreter(this._depth + 1);
    this._childInterpreter.setup(list, eventId);
};


Saying that, there should be an option, possibly under "Other", to call a Common Event in the Skills tab. I dunno if each skill has it's own Common Event in your game, but, that might cut down on the need to keep track of Skill ID through $gameVariables. As for keeping track of target ID, and using a dice-system... I feel that doesn't need a Common Event at all, and could be done with a simpler script?

// Rolls "n" number of "d"-sided dice, then adds "b".
function roll(n, d, b) = {
	if (b === undefined) { b = 0 };
	total = 0;
	for (let i=0; i<n; i++) {
		total += Math.randomInt(d);
	}
	total += b;
	return total;
};

*Edit: I might know how to make an optional parameter in Ace, but, I've yet to learn how to make an optional parameter in MZ.
My Common Event would handle every skill, for example if the SkillID Variable is 1 it would process a "Basic Attack" against a given enemy.

Since I would like to use a system heavily inspired to Chronicles of Darkness it would be a simple dice roll, the CE would check on the PG stats versus the enemy stats and creates a poll of D10 dice. Then roll them and every 8, 9 and 10 is a success, 7- is a failure. Plus the 10 result generate another dice roll. Then comes up with the results ^^'
Pages: 1