Original Source
- Original title: MZ Typescript and overriding Game_Actor class
- Original author: myarichuk
- Original date: October 12, 2021
- Source thread: https://forums.rpgmakerweb.com/threads/typescript-and-overriding-game_actor-class.141205/
- Source forum path: Game Development Engines > RPG Maker Javascript Plugins > Learning Javascript
Summary
Hey everyone, I am thinking of extending Game_Actor class like this; it seems to work in a simple play-testing project without any dependencies. However, being a noob in Javascript and in RPG Maker, I am a bit worried this would conflict with the way some plugins are "injecting" their code into core scripts. What do you think of this approach? Is this viable? Or perhaps I am overcomplicating things? (for the reference, I am using an awesome project template from here: https://github.com/xuyanwen2012/rmmz-plugins-starter)
Archived First Post
I am thinking of extending Game_Actor class like this; it seems to work in a simple play-testing project without any dependencies. However, being a noob in Javascript and in RPG Maker, I am a bit worried this would conflict with the way some plugins are "injecting" their code into core scripts.
What do you think of this approach? Is this viable? Or perhaps I am overcomplicating things?
(for the reference, I am using an awesome project template from here: https://github.com/xuyanwen2012/rmmz-plugins-starter)
export class Game_Actor_Ex extends Game_Actor {
constructor(actorId: number){
super(actorId);
var windowDynamic = (window as any);
//this is needed so JsonEx.makeDeepCopy() will be able to properly instantiate the derived class
if(!windowDynamic["Game_Actor_Ex"])
windowDynamic["Game_Actor_Ex"] = Game_Actor_Ex;
}
public changeEquip(slotId: number, item: RPG.EquipItem): void {
super.changeEquip(slotId, item);
if(item)
console.log('hello from change Equip! equip event, slotId = ' + slotId + ' item = ' + item.name);
else
console.log('hello from change Equip! unequip event, slotId = ' + slotId);
}
}
export class Game_Actors_Ex extends Game_Actors {
actor(actorId: number): Game_Actor {
if ($dataActors[actorId]) {
if (!this._data[actorId]) {
this._data[actorId] = new Game_Actor_Ex(actorId);
}
return this._data[actorId];
}
return null as any;
}
}
Game_Actors.prototype = Game_Actors_Ex.prototype;
Downloads / Referenced Files
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadCreator 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...