Every now and then I'm using a plugin and it doesn't work quite the way I want it to, so I put in a little tweak to do what I want. Sometimes it's a bugfix, sometimes it's just changing things to be easier for me to work with. Since I'm not the only person using these plugins, I figured I'd put up a thread for these so other people can try them if they want.
I'll be sporadically updating this whenever I have something I think other people might find useful.
These are not optimized or cleaned up in any way, so it's almost certain there are better ways to do all of these things.
Terms of Use: Do whatever you like.
YEP_X_ExtDoodadPack1:
Switching Doodads 'on' puts them at the beginning of their animation cycle.
Yanfly's extended doodad plugin with switches is great to use, but when you switch an animated doodad on, it's at essentially random part of its animation cycle. That's because the doodads are silently going through each frame while transparent.
I wanted animated doodads to be at the start of their animation cycle when switched on. This tweak does that by resetting the frame to 0 whenever the plugin refreshes a hidden doodad.
Spoiler Code:
- //from YEP_X_ExtDoodadPack1
- //
- Sprite_Doodad.prototype.updateCustomEDP1Z = function() {
- if ($gameTemp._modeGFD) return;
- // Party
- var length = this.partyHave.length;
- for (var i = 0; i < length; ++i) {
- var actorId = this.partyHave[i];
- if (!$gameParty._actors.contains(actorId)) {
- this.opacity = 0;
- this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
- return;
- }
- }
- var length = this.partyMiss.length;
- for (var i = 0; i < length; ++i) {
- var actorId = this.partyMiss[i];
- if ($gameParty._actors.contains(actorId)) {
- this.opacity = 0;
- this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
- return;
- }
- }
- // Switches
- var length = this.switchOn.length;
- for (var i = 0; i < length; ++i) {
- var switchId = this.switchOn[i];
- if (!$gameSwitches.value(switchId)) {
- this.opacity = 0;
- this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
- return;
- }
- }
- var length = this.switchOff.length;
- for (var i = 0; i < length; ++i) {
- var switchId = this.switchOff[i];
- if ($gameSwitches.value(switchId)) {
- this.opacity = 0;
- this._index = 0;//reset the animation state so long as opacity is off, thus allowing for us to play doodad animations once.
- return;
- }
- }
- };
复制代码
MOG_ChronoEngine Item Core Compatibilty
Chrono Engine is not compatible with yanfly's item core by default. This fixes that.
Spoiler Code:
- var _mog_toolSys_gmap_setup = Game_Map.prototype.setup;
- Game_Map.prototype.setup = function(mapId) {
- //console.log("Game_Map.prototype.setup");
- _mog_toolSys_gmap_setup.call(this,mapId);
- this._treasureEvents = [];
- this._battlersOnScreen = [];
- this._enemiesOnScreen = [];
- this._actorsOnScreen = [];
- $gameSystem._toolsOnMap = [];
- $gameTemp.clearToolCursor();
- //console.log($gameSystem._toolsData);// with itemcore, this always returns an empty array []
- //without itemcore, it returns 'null', then an the proper item list, so clearly _toolsdata isn't getting set right
- //I assume the 'null' gets overridden by one of yanfly's blanket definitions, and since I can't find that
- // I'm just testing to see if the list is empty. If it is, grab the tools again
- // it seems to work!
- //if (!$gameSystem._toolsData) {this.dataMapToolClear()};
- if (!$gameSystem._toolsData) {this.dataMapToolClear()
- }else{ if ($gameSystem._toolsData.length == 0) {this.dataMapToolClear()};
- }
- for (var i = 0; i < $gameParty.members().length; i++) {
- var actor = $gameParty.members()[i];
- actor.clearActing();
- $gameSystem._toolHookshotSprite = [null,null,0];
- };
- };
复制代码
MOG_ActorHud Meter Angle Fix
Mog's actorhud converts from radians to degrees twice by default, which means if you set an angled bar the background
won't be at the same angle as the filled bar. This typo is in all the different meters, but once you see the hp meter fix you can change whatever other ones you want.
Spoiler Code:
- //==============================
- // * Create HP Meter
- //==============================
- Actor_Hud.prototype.create_hp_meter = function() {
- if (String(Moghunter.ahud_hp_meter_visible) != "true") {return};
- this.removeChild(this._hp_meter_blue);
- this.removeChild(this._hp_meter_red);
- if (!this._battler) {return};
- this._hp_meter_red = new Sprite(this._hp_meter_img);
- this._hp_meter_red.x = this._pos_x + Moghunter.ahud_hp_meter_pos_x;
- this._hp_meter_red.y = this._pos_y + Moghunter.ahud_hp_meter_pos_y;
- this._hp_meter_red.rotation = Moghunter.ahud_hp_meter_rotation * Math.PI / 180;
- this._hp_meter_red.setFrame(0,0,0,0);
- this.addChild(this._hp_meter_red);
- this._hp_meter_blue = new Sprite(this._hp_meter_img);
- this._hp_meter_blue.x = this._hp_meter_red.x;
- this._hp_meter_blue.y = this._hp_meter_red.y;
- this._hp_meter_blue.rotation = this._hp_meter_red.rotation; //this was incorrectly converting to radians twice
- this._hp_meter_blue.setFrame(0,0,0,0);
- this.addChild(this._hp_meter_blue);
- this._hp_old_ani[0] = this._battler.hp - 1;
- if (String(Moghunter.ahud_hp_meter_flow) === "true") {this._hp_flow[0] = true;
- this._hp_flow[2] = this._hp_meter_img.width / 3;
- this._hp_flow[3] = this._hp_flow[2] * 2;
- this._hp_flow[1] = Math.floor(Math.random() * this._hp_flow[2]);
- };
- };
复制代码
MOG_CharacterPoses+Mog_ChronoEngine Rotation Around Center + Set Sprite Rotations
By default in rpgmaker, sprite rotation is around the base of a sprite. That's bad if you're rotating projectiles, since you end up with your hitbox being displaced off from where the sprite actually is.
This function uses trig to identify where the sprite needs to be displaced so that it's rotated around the hitbox. (This requires that you center your sprite using mog's displacement tools to start with).
Above: My Version (approximate hitbox in blue)
Below: Default version
In addition, I have added a few functions for rotating character sprites smoothly. Set a target angle and a rotation rate, and it will update each frame until it reaches the target angle.
If you don't set a target angle, it will rotate at that speed forever.
You can also set it to go in whichever direction is closer, ignoring the sign on the angle speed.
Spoiler Code:
- Game_CharacterBase.prototype.setTargetAngle = function(targetAngle) {
- var ag = targetAngle * Math.PI / 180;
- this._user.targetAngle = [ag,targetAngle];
- };
- Game_CharacterBase.prototype.setRotationRate = function(rotationSpeed) {
- var ag = rotationSpeed * Math.PI / 180;
- this._user.rotationSpeed = [ag,rotationSpeed];
- };
- Game_CharacterBase.prototype.setRotationFlexible = function() {
- //flag to say we can go clockwise OR counterclockwise, whichever is closer
- this._user.rotationFlexible= true;
- };
- Game_CharacterBase.prototype.clearRotationRate = function() {
- this._user.targetAngle =null;
- this._user.rotationSpeed = null;
- this._user.rotationFlexible= false;
- };
- Sprite_Character.prototype.updateCharPosesPosition = function() {
- //honestly I don't understand what this is supposed to be doing, and a
- //constant offset for the x displacement fits what I want to do,
- //I've removed the x-offset shifting, to make way for my stuff
- //sorry if this breaks stuff for you!
-
- //if (this._character.direction() === 4 || this._character.direction() === 6) {
- // var ex = this._character.direction() === 6 ? this._character._frames.x : -this._character._frames.x;
- //} else {
- // var ex = 0;
- //};
- var ex = this._character._frames.x;
- var ey = this._character._frames.y;
-
- // add on additional rotation specified in tool
- if (this._character._tool)
- {
- if(this._character._tool.offsetX)
- {
- ex+=this._character._tool.offsetX;
- }
- if(this._character._tool.offsetY)
- {
- ey+=this._character._tool.offsetY;
- }
- if(this._character._tool.diagonalAngle)
- {
- this._character._user.rotation = [this._character._tool.diagonalAngle,Math.degrees(this._character._tool.diagonalAngle)];
- }
- }
-
- ag=0;
- angle=0;
- thisHasRotationUser=false;
- thisHasRotationChar=false;
- //technically this isn't the 'correct' way of checking to see
- //if we have this trait, but there shouldn't be any edge cases that matter
- //since if rotation has a value but it resolves as 'false' we don't want to
- //rotate after all
- if (this._character._user.rotation)
- {
- thisHasRotationChar=true;
- [ag,angle] = this._character._user.rotation;
- }else{
- if ($gameMap.event(3)._user.rotation[0] =undefined)
- {
- $gameMap.event(3)._user.rotation[0]=0;
- $gameMap.event(3)._user.rotation[1]=0;
- }
-
- }
-
- if (thisHasRotationChar)
- {
- var isSpinning=false;
- var hasTargetAngle=false;
- if(thisHasRotationChar)
- {
- if (this._character._user.rotationSpeed)
- {
- [agSpeed,angleSpeed] = this._character._user.rotationSpeed;
- isSpinning=true;
- }
- if (this._character._user.targetAngle || this._character._user.targetAngle ==0 )
- {
- [agTarget,angleTarget] = this._character._user.targetAngle;
- hasTargetAngle=true;
-
- }
- if (isSpinning){
- if(hasTargetAngle){
- //if our target angle is within a single step, snap to it.
- if(Math.abs(((((angleTarget+360) % 360)-((angle+360) % 360))/angleSpeed))<1){
- this._character.setAngle(angleTarget);
- }else{
- //if we are allowed to go in either direction, pick the shorter distance
- if(this._character._user.rotationFlexible)
- {
- if (((((angleTarget+360) % 360)-((angle+360) % 360) +360) % 360)>180)
- this._character.setAngle(angle-Math.abs(angleSpeed));
- else
- this._character.setAngle(angle+Math.abs(angleSpeed));
- }else{
- this._character.setAngle(angle+angleSpeed);
- }
- }
- }else{
- //if we don't have a target angle, but do have a rotation speed, keep spinning without limit!
- this._character.setAngle(angle+angleSpeed);
- }
- }
- }else if(thisHasRotationUser){
- if (this._user.rotationSpeed)
- {
- [agSpeed,angleSpeed] = this._user.rotationSpeed;
- isSpinning=true;
- }
- if (this._user.targetAngle)
- {
- [agTarget,angleTarget] = this._user.targetAngle;
- hasTargetAngle=true;
- }
- if (isSpinning){
- if(hasTargetAngle){
- //if our target angle is within a single step, snap to it.
- if(Math.abs(((((angleTarget+360) % 360)-((angle+360) % 360))/angleSpeed))<1){
- this.setAngle(angleTarget);
- }else{
- if(this._user.rotationFlexible)
- {
- if (((((angleTarget+360) % 360)-((angle+360) % 360) +360) % 360)>180)
- this.setAngle(angle-Math.abs(angleSpeed));
- else
- this.setAngle(angle+Math.abs(angleSpeed));
- }else{
- this.setAngle(angle+angleSpeed);
- }
- }
- }else{
- //if we don't have a target angle, but do have a rotation speed, keep spinning without limit!
- this.setAngle(angle+angleSpeed);
- }
- }
- }
-
- //update ag and angle
- if (this._character._user.rotation || (this._character._user.rotation==0))
- {
- [ag,angle] = this._character._user.rotation;
- }
- }
- if (ag==0)
- {
- this.x += ex;
- this.y += ey;
-
- }else{
- //I have altered this code to
- //rotate events around the displacement point by default,
- //instead of the base of the sprite
- //technically this rotation is only off by a pixel or two, but w/e, close enough.
- baselength=Math.sqrt(ex*ex + ey*ey);
-
- this.x += ex*Math.cos(ag) - ey * Math.sin(ag);
- this.y += ex*Math.sin(ag) + ey * Math.cos(ag);
- }
-
- };
- //one problem with the above is that animations end up vertically displaced
- //from their targets! And animations are attached to a single point on the
- //sprite, which means if it spins, they spin!
- //this restores normal animation location on rotating objects
- _cross_sprite_animation_update_position=Sprite_Animation.prototype.updatePosition;
- Sprite_Animation.prototype.updatePosition = function()
- {
- _cross_sprite_animation_update_position.call(this);
- if (this._target._character)
- {
- //if we're targeting a sprite on a character
- //then
- var ex =0;
- var ey =0;
-
- if (this._target._character._frames.x)
- {
- ex+=this._target._character._frames.x;
- }
- if (this._target._character._frames.y)
- {
- ey+=this._target._character._frames.y;
- }
- if (this._target._character._tool)
- {
- if(this._target._character._tool.offsetX)
- {
- ex+=this._target._character._tool.offsetX;
- }
- if(this._target._character._tool.offsetY)
- {
- ey+=this._target._character._tool.offsetY;
- }
- }
- var ag=0;
- var angle=0;
- if (this._target._character._user.rotation || (this._target._character._user.rotation==0))
- {
- [ag,angle] = this._target._character._user.rotation;
- }
-
- this.x -= ex*Math.cos(ag) - ey * Math.sin(ag) -ex;
- this.y -= ex*Math.sin(ag) + ey * Math.cos(ag) -ey*1.5;
- }
-
- }
复制代码
本贴来自国际rpgmaker官方论坛作者:Restart处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/notes-to-self-little-tweaks-mostly-chrono-engine.112155/