JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 111 of 171 View original ↗
  1. Hello all! I hope I can find some help for my issue. I would like to make a script in which there is a quick check if the player character is X Tiles / Steps away from a certain Region tile specified, similar to a check in which the player is X Tiles / Steps away from an event.

    What I got so far and what it does:

    Spoiler
    if($gameMap.regionId($gamePlayer.x, $gamePlayer.y) < 105)
    {
    DO SOMETHING HERE LIKE SHOW A MESSAGE OR WHATEVER ELSE.
    }
    else if($gameMap.regionId($gamePlayer.x, $gamePlayer.y) >= 105)
    {
    DO NOTHING HERE OR MAYBE BLOCK MOVEMENT OR DISABLE SOMETHING
    }

    If the player x and y coordinates are on any region below 105 it is supposed to allow whatever action

    ''Else if'' works ONLY IF the player steps on any Region tile with the number 105 or above. However I want something where the script (or coordinates) easily check if the Player is 1 or more Tiles / Steps away from specified Regions in both x and y directions as well as diagonal if possible!

    So why I wish to do this? To have more freedom with certain Skills I do for my game using Chrono Engine.

    It also would come in handy making a Skill in which you use the ''through'' option where the player can walk through everything. So to prevent the player walking through specified Regions, I need this check before the player is actually on top of that Region already!

    I hope my English isn't too terrible! Anyways thanks in advance.

    EDIT: Made my own thread for this! Thanks for the help tho.
  2. Manjini said:
    I would like to make a script in which there is a quick check if the player character is X Tiles / Steps away from a certain Region tile specified
    If you already know the coordinates of the tile you're checking, you can just use the distance() method:

    If you're trying to do something like scan around the player to find the nearest instance of a given region ID, you'll have to write a function for that. If that's what you want but you don't know how to do that, you should start a new thread for assistance.
  3. ATT_Turan said:
    I don't really understand your description of what you're trying to do. Are you trying to edit images within RPG Maker?

    If you're saying you've edited the image while the game is open and you want to refresh that...I'm not super knowledgeable about how the caching system works, but you could try changing the bitmap using the same filename to reload it. But I suspect there are better ways to go about whatever it is (like using a screenshot for the game as a lower layer in your image editor).


    Thanks for getting back to me! Yeah that's pretty much it. I'm using a plugin to edit the bitmap I take from a file and am trying to work with just that bitmap so I can still reference the original file I need later untouched.

    I can add the new bitmap to a Sprite_Picture but I haven't found any way of actually adding it to a Game_Picture which is what has the functionality I need
  4. Terrannus said:
    Thanks for getting back to me! Yeah that's pretty much it. I'm using a plugin to edit the bitmap I take from a file and am trying to work with just that bitmap so I can still reference the original file I need later untouched.

    I can add the new bitmap to a Sprite_Picture but I haven't found any way of actually adding it to a Game_Picture which is what has the functionality I need
    I think you should start your own thread, this solution is going to be more complex than a single function call.

    Good luck!
  5. I found a thread describing the script in VX for offset animation but I can't seem to find a script to do that in MV, anyone know what it is?

    Untitled.png

    ^ This but for MV.
  6. FrozenFacade said:
    I found a thread describing the script in VX for offset animation but I can't seem to find a script to do that in MV, anyone know what it is?

    View attachment 242003

    ^ This but for MV.
    That isn't a default VX function. It's a script Shaz wrote, and you'll find the entirety of it in the Spoiler tags in that post. The bit you quoted does nothing by itself, and as it didn't come with VX there's also no MV equivalent.

    You should make a post in Plugin Requests with more detail on how you want this to work and see if anyone can suggest an existing plugin or write a quick one for you.
  7. ATT_Turan said:
    That isn't a default VX function. It's a script Shaz wrote, and you'll find the entirety of it in the Spoiler tags in that post. The bit you quoted does nothing by itself, and as it didn't come with VX there's also no MV equivalent.

    You should make a post in Plugin Requests with more detail on how you want this to work and see if anyone can suggest an existing plugin or write a quick one for you.
    Thanks, yeah I saw the rest of it and just posted that bit to not fill up my post with an entire other post.
  8. Hello!

    Writing a little plugin that is by no means good code haha, but just wanted a little help.

    I've created window that makes use of Scene_MenuBase and that's all find and dandy as it works just great, but does anyone know how to disable the blur & darken effect that happens when you push the scene? The same effect that happens when you open the default menu, just to be clear.

    I mean specifically remove it for the custom scene/window I've made, without touching or changing anything else (like disabling the effect for everything, which I don't want).

    RMMZ 1.5.0
  9. I have a dumb JS question - it involves a custom plugin I wrote for MZ, but I'm not sure it deserves its own thread.

    Basically I have a small script that modifies the menu to show an actor and an objective, sort of like a dialogue box in the menu:

    SS1
    1665837507590.png

    It's a bit janky (the "objective" is reading off an item description set by a variable), but it works. Except for when the game first loads, or upon entering a new map...
    SS2
    1665837492100.png

    The face won't load. It will load normally after the 2nd time opening the menu, but never the first time.

    I've tried using this code before the menu opens:

    Code:
    ImageManager.loadFace('faces');

    But it doesn't help. I've had this issue persist across multiple games using the same script and I've never been able to figure out how to make the faces load properly.

    Is there a line of code that'll solve the problem, or something deeper I need to look into?
  10. jkweath said:
    I've had this issue persist across multiple games using the same script and I've never been able to figure out how to make the faces load properly.
    Where's the actual code you have now for creating that objective window? I only see in-game screenshots.
  11. ATT_Turan said:
    Where's the actual code you have now for creating that objective window? I only see in-game screenshots.
    Here's the block of code that draws the face and text:

    Code:
    Window_Objective.prototype.refresh = function() {
        this.contents.clear();
        this.updateHelp();
        var x = this.itemPadding();
        var width = this.contents.width - this.itemPadding() * 2;
        var actor = $gameActors.actor($gameVariables.value(1));
        ImageManager.loadFace(actor.faceName());
        this.drawActorFace(actor, actor.faceIndex(), 0, 128, 128);
        this.changeTextColor(ColorManager.textColor(6));
        this.drawText(actor.name() + ":", this.itemPadding() + 150, 6, width);
        //this.drawText("Current Objective:", this.itemPadding() + 160, 0, width, 'left');
        this.resetTextColor();
        this.drawTextEx(this._text, this.itemPadding() + 150, this.lineHeight() + 6);
    };
  12. jkweath said:
    Here's the block of code that draws the face and text:
    So you're misusing loadFace - you're just calling it, but that doesn't do anything. If you look at the function in the code, it returns the actual face image.

    Additionally, it's not necessary there because - again, doing a search for it - it's already being called as a part of drawActorFace (it's how it gets the image to draw).

    So that line isn't doing anything, and you definitely don't need to call it more times/in different places.

    I think your problem is you're calling drawActorFace incorrectly. Looking it up in the code, the arguments it's expecting are "actor, x, y, width, height." Then, inside of it, it's referencing the actor.faceIndex().

    But you're passing the faceIndex() as the x coordinate to draw it at - so I think it is trying to draw, but the x coordinate is, like, the top pixel of your screen where it doesn't fit and you can't see it.

    Try changing that to a number near the bottom of your screen.
  13. Yeah, I was fiddling around with that line and must've misread what's supposed to go there. I changed it back to the original:

    Code:
    this.drawActorFace(actor, 5, 0, 128, 128);

    Still doesn't work. Just to clarify, upon opening the menu a second time in the same map, the face will load correctly and in the correct spot. It's only the first time that the face won't load.
  14. jkweath said:
    Still doesn't work.
    You should probably start a thread about it. I remember a plugin that had similar issues and someone identified the fix, but I don't recall which plugin it was to look up the thread.
  15. jkweath said:
    Yeah, I was fiddling around with that line and must've misread what's supposed to go there. I changed it back to the original:

    Code:
    this.drawActorFace(actor, 5, 0, 128, 128);

    Still doesn't work. Just to clarify, upon opening the menu a second time in the same map, the face will load correctly and in the correct spot. It's only the first time that the face won't load.
    What class does Window_Objective use as its prototype? Because if it's not a Window_StatusBase, the face images won't be preloaded. If you look at the initialisation code for Window_StatusBase, it preloads party face graphics by calling ImageManager.loadFace for each member of the party, so that in status menus the faces will be visible immediately when you open them.

    What you can do alternatively, though, is add a load listener to the graphic so that it only draws after it loads.

    JavaScript:
    const bmp = ImageManager.loadFace(actor.faceName());
    bmp.addLoadListener(() => this.drawActorFace(actor, 5, 0, 128, 128));
  16. Trihan said:
    What class does Window_Objective use as its prototype? Because if it's not a Window_StatusBase, the face images won't be preloaded. If you look at the initialisation code for Window_StatusBase, it preloads party face graphics by calling ImageManager.loadFace for each member of the party, so that in status menus the faces will be visible immediately when you open them.

    What you can do alternatively, though, is add a load listener to the graphic so that it only draws after it loads.

    JavaScript:
    const bmp = ImageManager.loadFace(actor.faceName());
    bmp.addLoadListener(() => this.drawActorFace(actor, 5, 0, 128, 128));
    Thank you very much Trihan! This solved the problem, and I feel like I've learned a little more about how images load. :kaojoy:
  17. Hello,
    not sure if i'm in the right thread, but i have a little question.
    i used this to my events (no trigger):


    if $gameParty.lastItem().itemId() == 2
    Control Variable 0003 xy = 1

    but when i use the Item with ID 2 the Variable is sill on 0 (query about \V[1])
    what am I doing wrong ?
  18. @Dustin2022 Never use the leading zeros with a switch number. It should be plain 3, not 0003.
    Is this a one off or do you intend to increase the variable by one each time that item is used? At the moment you are setting it to one.

    Try something like this
    Code:
    $gameVariables.setValue(3, 1)
  19. Kes said:
    @Dustin2022 Never use the leading zeros with a switch number. It should be plain 3, not 0003.
    Is this a one off or do you intend to increase the variable by one each time that item is used? At the moment you are setting it to one.

    Try something like this
    Code:
    $gameVariables.setValue(3, 1)
    I think he was copying from the event command list rather than doing it as a script. In the event itself it shows leading zeroes (which is usually why people get so confused about it when referencing them in code).

    @Dustin2022 You say you're setting variable 3 but using \v[1] in your message, which would show the value of variable 1. Could that be why it's showing a 0?

    What's your aim in setting variable 3 to the value 1 if the player used item 2 anyway?
  20. Edit:
    [Redacted] Outdated info.