JavaScript questions that don't deserve their own thread

Riazey

Master of None
Veteran
Joined
Feb 27, 2014
Messages
142
Reaction score
169
First Language
English
Primarily Uses
RMMV
@SeaPhoenix :kaopride:

This is very very helpful thank you SO MUCH! Part of it is I am trying to learn scraps here and there as I go, trying to avoid using too many heavy scripty bois since I've got a lot going on haha! It was a great informational post and I feel like I understand the scenes a bit better now too :kaoblush: If you ever figure out the line spacing just for the message window I am all ears <3
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Hi, I am trying to find out, what is the code to position battlers x and y position during battle? The reason I am asking, is because I have a summoning system using common event, as Summon Core conflicts with with Animated SV Battler.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Hi, I am trying to find out, what is the code to position battlers x and y position during battle? The reason I am asking, is because I have a summoning system using common event, as Summon Core conflicts with with Animated SV Battler.
During battle check:

JavaScript:
//Accesses the enemy sprite array. That's where you can change the x and y parameters
SceneManager._scene.children[0]._enemySprites;

//OR
SceneManager._scene._spriteset._enemySprites
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
During battle check:

JavaScript:
//Accesses the enemy sprite array. That's where you can change the x and y parameters
SceneManager._scene.children[0]._enemySprites;

//OR
SceneManager._scene._spriteset._enemySprites
Hi, thanks for the reply, but I don't think that is what I am looking for. As it is for a summoning system, I need to place actors, not enemies, in battle, and I want to be able to customize the x and y position of the summoned actors.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Hi, thanks for the reply, but I don't think that is what I am looking for. As it is for a summoning system, I need to place actors, not enemies, in battle, and I want to be able to customize the x and y position of the summoned actors.
Is this what you meant?

JavaScript:
SceneManager._scene._spriteset._actorSprites[0].x = yourXvalue // change x here
SceneManager._scene._spriteset._actorSprites[0].y = yourYvalue // change y here

//Continue with other actors 
SceneManager._scene._spriteset._actorSprites[1].x = yourXvalue // change x here
SceneManager._scene._spriteset._actorSprites[1].y = yourYvalue // change y here

//etc
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Is this what you meant?

JavaScript:
SceneManager._scene._spriteset._actorSprites[0].x = yourXvalue // change x here
SceneManager._scene._spriteset._actorSprites[0].y = yourYvalue // change y here

//Continue with other actors
SceneManager._scene._spriteset._actorSprites[1].x = yourXvalue // change x here
SceneManager._scene._spriteset._actorSprites[1].y = yourYvalue // change y here

//etc
Thanks Lanzy, but I think this script calls the troop ID. Is there a version that can be applied to actor ID?
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Thanks Lanzy, but I think this script calls the troop ID. Is there a version that can be applied to actor ID?
Just saw one mistake I made:
If you want to move the actor sprite, you have to change the ._homeX and ._homeY property, otherwise if u just change the x and y property, it will always reset the actor back to the home coordinates within 1 fps of time.

SceneManager._scene._spriteset._actorSprites[0] is the sprite of actor id 1, ._actorSprites[1] is sprite of actor id 2, etc.

JavaScript:
//You can call the sprite of any actor id
SceneManager._scene._spriteset._actorSprites[actorId - 1]._homeX = yourXvalue // change x here
SceneManager._scene._spriteset._actorSprites[actorId - 1]._homeY = yourYvalue // change y here
Would someone be able to help me make a small tweak to one of Yanfly's Tips and Tricks, Reverence? http://www.yanfly.moe/wiki/Reverence_(MV_Plugin_Tips_&_Tricks)

All I'm hoping to change is to make the healing effect only happen 10% of the time, instead of every time the user spends MP.
Can you post the script-code for that effect?
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Just saw one mistake I made:
If you want to move the actor sprite, you have to change the ._homeX and ._homeY property, otherwise if u just change the x and y property, it will always reset the actor back to the home coordinates within 1 fps of time.

SceneManager._scene._spriteset._actorSprites[0] is the sprite of actor id 1, ._actorSprites[1] is sprite of actor id 2, etc.

JavaScript:
//You can call the sprite of any actor id
SceneManager._scene._spriteset._actorSprites[actorId - 1]._homeX = yourXvalue // change x here
SceneManager._scene._spriteset._actorSprites[actorId - 1]._homeY = yourYvalue // change y here
Hi Lanzy, thanks. Unfortunately, I am not able to use this code because this assumes that the actor will always be in the same troop position. I have actors coming and going constantly, so this does not work. I guess I just have to live with the way they are currently drawn.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Hi Lanzy, thanks. Unfortunately, I am not able to use this code because this assumes that the actor will always be in the same troop position. I have actors coming and going constantly, so this does not work. I guess I just have to live with the way they are currently drawn.
Try this function, put it anywhere in your plugin files. This allows you to move a specific
actor sprite according to the actorId.

JavaScript:
//use this function for the battle scene to move actor
moveActor = function(actorId, x, y) {
    let actors = SceneManager._scene._spriteset._actorSprites;
    let actor = actors.filter((i) => i._actor._actorId === actorId)[0];
    actor._homeX = x; //changes the actors x position
    actor._homeY = y; //changes the actors y position

//Example: moveActor(2, 20, 50);

}
 

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Can you post the script-code for that effect?
Sure thing, here's the code used for the state:

Code:
<Custom Action Start Effect>
// Get the user's current HP.
user._reverenceMp = user.mp;
</Custom Action Start Effect>

<Custom Initiate Effect>
// Check if the stored MP value exists.
if (user._reverenceMp !== undefined) {
  // If it does, calculate the difference between the user's initial MP and the user's current MP after the cost.
  var difference = user._reverenceMp - user.mp;
  // Check if the difference is greater than zero...
  if (difference > 0) {
    // If it is, calculate the amount of HP healed.
    var hp = Math.ceil(difference * 20.00);
    // Make the user gain that HP.
    user.gainHp(hp);
    // Play a damage popup.
    user.startDamagePopup();
    // Clear the damage results.
    user.clearResult();
  }
  user._reverenceMp = undefined;
}
</Custom Initiate Effect>
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Try this function, put it anywhere in your plugin files. This allows you to move a specific
actor sprite according to the actorId.

JavaScript:
//use this function for the battle scene to move actor
moveActor = function(actorId, x, y) {
    let actors = SceneManager._scene._spriteset._actorSprites;
    let actor = actors.filter((i) => i._actor._actorId === actorId)[0];
    actor._homeX = x; //changes the actors x position
    actor._homeY = y; //changes the actors y position

//Example: moveActor(2, 20, 50);

}
Hi Lanzy, thanks for the prompt reply. Unfortunately, it still does not work. I created a plugin using the exact code above and then used the script call "moveActor(25, 712, 482);" as I am summoning Actor ID 25, but it still appeared in the same position as before. Below is a screenshot of the common event I used to summon the Actor:
Summon.png
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Sure thing, here's the code used for the state:

Code:
<Custom Action Start Effect>
// Get the user's current HP.
user._reverenceMp = user.mp;
</Custom Action Start Effect>

<Custom Initiate Effect>
// Check if the stored MP value exists.
if (user._reverenceMp !== undefined) {
  // If it does, calculate the difference between the user's initial MP and the user's current MP after the cost.
  var difference = user._reverenceMp - user.mp;
  // Check if the difference is greater than zero...
  if (difference > 0) {
    // If it is, calculate the amount of HP healed.
    var hp = Math.ceil(difference * 20.00);
    // Make the user gain that HP.
    user.gainHp(hp);
    // Play a damage popup.
    user.startDamagePopup();
    // Clear the damage results.
    user.clearResult();
  }
  user._reverenceMp = undefined;
}
</Custom Initiate Effect>
I wasn't sure if you wanted to have the 20% chance every time MP is used or just outright 20% chance
regardless of MP use. So I did both.

Ok so this will execute the effect 20% of the time

Code:
<Custom Action Start Effect>
</Custom Action Start Effect>

<Custom Initiate Effect>
    // checking probability of 20%
if (Math.random() <= 0.2) {
    // Calculate the amount of HP healed.
    var hp = Math.ceil(difference * 20.00);
    // Make the user gain that HP.
    user.gainHp(hp);
    // Play a damage popup.
    user.startDamagePopup();
    // Clear the damage results.
    user.clearResult();
}
</Custom Initiate Effect>
And this one will execute the effect if the 20% chance applies AND MP is used.

Code:
<Custom Action Start Effect>
// Get the user's current HP.
user._reverenceMp = user.mp;
</Custom Action Start Effect>
<Custom Initiate Effect>
// Check if the stored MP value exists and probability of 20%
if (user._reverenceMp !== undefined && Math.random() <= 0.2) {
  // If it does, calculate the difference between the user's initial MP and the user's current MP after the cost.
  var difference = user._reverenceMp - user.mp;
  // Check if the difference is greater than zero...
  if (difference > 0) {
    // If it is, calculate the amount of HP healed.
    var hp = Math.ceil(difference * 20.00);
    // Make the user gain that HP.
    user.gainHp(hp);
    // Play a damage popup.
    user.startDamagePopup();
    // Clear the damage results.
    user.clearResult();
  }
  user._reverenceMp = undefined;
}
</Custom Initiate Effect>
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Hi Lanzy, thanks for the prompt reply. Unfortunately, it still does not work. I created a plugin using the exact code above and then used the script call "moveActor(25, 712, 482);" as I am summoning Actor ID 25, but it still appeared in the same position as before. Below is a screenshot of the common event I used to summon the Actor:
View attachment 164560
Sorry, I should've tested the code. Forgot to make a check to look if the actor exists, before
moving it. Otherwise there is just gonna be an error and nothing happens. This should work now.
I tested it.

JavaScript:
//use this function for the battle scene to move actor
moveActor = function(actorId, x, y) {
    let actors = SceneManager._scene._spriteset._actorSprites;
    let actor = actors.filter((i) => i._actor && i._actor._actorId === actorId)[0];
    actor._homeX = x; //changes the actors x position
    actor._homeY = y; //changes the actors y position

//Example: moveActor(2, 20, 50);

}
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Sorry, I should've tested the code. Forgot to make a check to look if the actor exists, before
moving it. Otherwise there is just gonna be an error and nothing happens. This should work now.
I tested it.

JavaScript:
//use this function for the battle scene to move actor
moveActor = function(actorId, x, y) {
    let actors = SceneManager._scene._spriteset._actorSprites;
    let actor = actors.filter((i) => i._actor && i._actor._actorId === actorId)[0];
    actor._homeX = x; //changes the actors x position
    actor._homeY = y; //changes the actors y position

//Example: moveActor(2, 20, 50);

}
Hi Lanzy, thanks for the prompt reply. Unfortunately, I am not sure why, but it still does not work, and I wonder if there could be a plugin compatibility issue. I tried inserting the code into Common Event as well, but it still doesn't work.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Hi Lanzy, thanks for the prompt reply. Unfortunately, I am not sure why, but it still does not work, and I wonder if there could be a plugin compatibility issue. I tried inserting the code into Common Event as well, but it still doesn't work.
Try this:
Put the .js file into your plugins folder and add it to your plugins.
Then use the moveActor function just like before in common events.
Then press F8 to open the developer tools and make sure the "console" tab is selected.
Make a screenshot of the console window and show me please.
 

Attachments

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Try this:
Put the .js file into your plugins folder and add it to your plugins.
Then use the moveActor function just like before in common events.
Then press F8 to open the developer tools and make sure the "console" tab is selected.
Make a screenshot of the console window and show me please.
Hi Lanzy, please find the screenshot below. I totally forgot about the Console. Looks like there is some conflict with YEP. Also, should we move this discussion to the Plugin section instead?
Console.png
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Hi Lanzy, please find the screenshot below. I totally forgot about the Console. Looks like there is some conflict with YEP. Also, should we move this discussion to the Plugin section instead?
View attachment 164568
Turn off all other plugins and try it again, same procedure. That way you will know right away if it has to do with YanFly, which I doubt.

Also use the .js file I attached to my last message please, it has some console calls that gives more detail to whats happening.
 

zelanius

Everyman
Veteran
Joined
Apr 29, 2020
Messages
50
Reaction score
4
First Language
English
Primarily Uses
RMMV
Turn off all other plugins and try it again, same procedure. That way you will know right away if it has to do with YanFly, which I doubt.

Also use the .js file I attached to my last message please, it has some console calls that gives more detail to whats happening.
Hi Lanzy, I did use your JS file, but not sure why the functions are not showing up. I tried turning off all plugins other than the ones I need to make my summon work, and below is the console view.Console with some plugins.png
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
128
Reaction score
54
First Language
English
Primarily Uses
RMMV
Hi Lanzy, I did use your JS file, but not sure why the functions are not showing up. I tried turning off all plugins other than the ones I need to make my summon work, and below is the console view.View attachment 164571
Ok, the plugin seems to be working. So for some reason, when it checks the actor sprites, the actor with the id you are looking for is not in that list. Make sure, that the script call takes place, when the actor is already on the battlefield and then move the actor. That's all I can tell looking at it from here. Maybe test it with other actor ids just to make sure it works if there is an actor on the battle field.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 5)

Latest Threads

Latest Posts

Latest Profile Posts

Oh no. That moment when you try to fix something you modified in your game, like, a year ago but didn't want to fix then, and you now have no idea what you even did. Me right now, trying to figure out why my gold window is over stretched?
LittlePIGGY wrote on atreyoray's profile.
Where are you TT^TT
We need ARP_InGameManual for MZ
Oh my gosh. Thank you, Macy's! Thank you so much! You have made me very happy!
Happy Thanksgiving everyone! What are you thankful for? I'm thankful that I no longer have PTSD, and that I get to enjoy a good meal with my mom and stepdad! It might not be the same as before COVID, but at least I still get to enjoy the holiday!

Forum statistics

Threads
105,548
Messages
1,014,548
Members
137,226
Latest member
Eryndor
Top