JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 28 of 171 View original ↗
  1. DreamX said:
    user.weapons()[1] returns true if a weapon is equipped in that slot.



    Thanks a bunch! That is working. 
  2. I asked this earlier for a different reason, and found a pretty easy workaround that worked for that particular reason, but I find I need the answer to it now.


    Is there a way to reference properties of a skill, from inside that skills note box?


    For example, if I wanted to get the skill's id, and use it in a calculation in the note box, is there a way to do that dynamically?
  3. ramza said:
    I asked this earlier for a different reason, and found a pretty easy workaround that worked for that particular reason, but I find I need the answer to it now.


    Is there a way to reference properties of a skill, from inside that skills note box?


    For example, if I wanted to get the skill's id, and use it in a calculation in the note box, is there a way to do that dynamically?



    Yes, but that depends on what information is available at the time the calculation is being evaluated. If you can post the plugin you're using I can help out.
  4. I'm using yanfly's action sequences. I am making a calculation during the sequence that if the user has a certain state, it performs some extra damage (with a second animation, all fancy like). I can get that part working. The problem is that the extra damage should be magical, while the skill itself is usually physical. I can get around that by changing the skill mid-action sequence ($gameSkills[x].hitType = 2), and then changing it back to physical after the second hit lands.


    Since this state is supposed to be active  a lot, and I want it to affect all physical skills, I will need to add that the all of the action sequences for my physical skills. If I could reference the skill ID dynamically, then I wouldn't have to change the number in the $gameSkills[x] box for every skill I change, less human error, less chance of bugs, faster copypasta, all around better. And more importantly, I have some skills that are copying their action sequences from another skill, which won't work by manually entering the number, because the skill they're copied from would have one ID, not the one I'm looking for. So I'd have to manually copy the action sequence from the copied skill, then change the number, etc.


    So is it possible to read parameters on the skill, from a note tag on the skill (this.whatever doesn't seem to work).


    edit: also, if skillId can be read somehow, then hitType should be able to be read directly as well, so I should be able to change that even more easily.
  5. ramza said:
    I'm using yanfly's action sequences. I am making a calculation during the sequence that if the user has a certain state, it performs some extra damage (with a second animation, all fancy like). I can get that part working. The problem is that the extra damage should be magical, while the skill itself is usually physical. I can get around that by changing the skill mid-action sequence ($gameSkills[x].hitType = 2), and then changing it back to physical after the second hit lands.


    Since this state is supposed to be active  a lot, and I want it to affect all physical skills, I will need to add that the all of the action sequences for my physical skills. If I could reference the skill ID dynamically, then I wouldn't have to change the number in the $gameSkills[x] box for every skill I change, less human error, less chance of bugs, faster copypasta, all around better. And more importantly, I have some skills that are copying their action sequences from another skill, which won't work by manually entering the number, because the skill they're copied from would have one ID, not the one I'm looking for. So I'd have to manually copy the action sequence from the copied skill, then change the number, etc.


    So is it possible to read parameters on the skill, from a note tag on the skill (this.whatever doesn't seem to work).

    Let's take a look at the function that evaluates action sequences.


    BattleManager.actionEval = function(actionArgs) {
    if (actionArgs.length < 1) return true;
    var subject = this._subject;
    var user = this._subject;
    var target = this._targets[0];
    var targets = this._targets;
    var action = this._action;
    var item = this._action.item();
    var text = String(actionArgs[0]);
    for (var i = 1; i < actionArgs.length; ++i) {
    text = text + ', ' + String(actionArgs);
    }
    eval(text);
    return false;
    };


    The variable item is the skill/item being used.


    Therefore, to reference the id of the skill you use item.id


    You can use whatever else you want from this variable too, of course...try using console.log(item) in your script to learn more about the object's properties.
  6. Perfect, thanks.


    Here's another thing you might randomly know the answer to, that's been bugging me all morning:


    Using yanfly's buffs/states core, I can play an animation on a battler when it becomes inflicted with a state, but if I do anything else in the same section, it all happens on the same frame, without waiting for the animation to finish playing.


    I am calling an animation with: target.startAnimation(171, false, 0);


    I can't seem to find a similar call for waiting for the animation to finish playing. The script call spreadsheet shows another set of calls to use, but they don't work in battle.


    For example, I have a state very similar to the one I was talking about in my other post, if you have the state active, when you hit an opponent with a physical attack, it plays an animation and does extra damage.


    <Custom Conclude Effect>
    if (target.result().isHit() && this.isHpEffect() && this.isPhysical()) {
    var input = Math.floor(target.lastHitDmg / 4)
    target.startAnimation(171, false, 0);
    var total = RamzaDoTMath(input, 8, 20, target)
    target.gainHp(-total);
    target.startDamagePopup();
    if (target.isDead()){
    target.performCollapse();
    }
    }
    </Custom Conclude Effect>


    While it works with no errors, the damage popup for the state happens at the same frame as the damage popup for the attack that caused the state, while the animation plays for several frames after the popup is gone.


    Any ideas?
  7. ramza said:
    Perfect, thanks.


    Here's another thing you might randomly know the answer to, that's been bugging me all morning:


    Using yanfly's buffs/states core, I can play an animation on a battler when it becomes inflicted with a state, but if I do anything else in the same section, it all happens on the same frame, without waiting for the animation to finish playing.


    I am calling an animation with: target.startAnimation(171, false, 0);


    I can't seem to find a similar call for waiting for the animation to finish playing. The script call spreadsheet shows another set of calls to use, but they don't work in battle.


    For example, I have a state very similar to the one I was talking about in my other post, if you have the state active, when you hit an opponent with a physical attack, it plays an animation and does extra damage.



    <Custom Conclude Effect>
    if (target.result().isHit() && this.isHpEffect() && this.isPhysical()) {
    var input = Math.floor(target.lastHitDmg / 4)
    target.startAnimation(171, false, 0);
    var total = RamzaDoTMath(input, 8, 20, target)
    target.gainHp(-total);
    target.startDamagePopup();
    if (target.isDead()){
    target.performCollapse();
    }
    }
    </Custom Conclude Effect>


    While it works with no errors, the damage popup for the state happens at the same frame as the damage popup for the attack that caused the state, while the animation plays for several frames after the popup is gone.


    Any ideas?

    Yes, use setTimeout with a callback function. Example:


    <Custom Conclude Effect>
    var animId = 80;

    // you can use this to add a delay so it doesn't so immediately after the animation. 60 frames = 1 second
    var extraFramesToWaitFor = 15;

    var animFrames = ($dataAnimations[animId].frames.length * 4) + 1 + extraFramesToWaitFor;
    var waitSeconds = (animFrames/60) * 1000;

    target.startAnimation(animId, false, 0);
    setTimeout(function () {
    target.gainHp(-100);
    target.startDamagePopup();
    if (target.isDead()) {
    target.performCollapse();
    }
    }, waitSeconds);
    // have battle wait for anim completion
    BattleManager._logWindow._waitCount += animFrames;
    </Custom Conclude Effect>


    We're using setTimeout here. The first parameter is the callback function, the second is the time in milliseconds to wait for.


    We calculate the frames by multiplying the number of frames in the animation by the default animation rate, which is 4, then add 1 and then some extra frames so it's a little more natural to the eye.


    We calculate the seconds by converting to seconds (1 second = 60 frames) and convert to millseconds.


    Anything within the callback function will wait for waitSeconds time to execute.


    We also add a wait to the battle log so that the battle won't keep going on until the animation is done.
  8. That'll do it. Thanks for your help again. You are a gentleman and a scholar.
  9. Can you remove the four pixel offset globally? I still want bush tiles to effect my characters but don't want the offset to be enabled, it looks weird with our character graphics.
  10. Prescott said:
    Can you remove the four pixel offset globally? I still want bush tiles to effect my characters but don't want the offset to be enabled, it looks weird with our character graphics.



    You could prefix each character graphics file with an exclamation mark, or edit the following code to remove the six pixel shift.


    Game_CharacterBase.prototype.shiftY = function() {
    // Change the 6 to 0.
    return this.isObjectCharacter() ? 0 : 6;
    };


    EDIT: Ah, I guess using the exclamation mark stops the bush tile effect. Nevermind!
  11. @Exhydra where is that code located so that I can change it?
  12. Prescott said:
    @Exhydra where is that code located so that I can change it?



    Ah, sorry.


    /js/rpg_objects.js - line 6451
  13. I find its extremely useful to have all of the base scripts open in a text editor like notepad++ so you can search through all at once. It's an easy way to find what you want.
  14. DreamX said:
    I find its extremely useful to have all of the base scripts open in a text editor like notepad++ so you can search through all at once. It's an easy way to find what you want.



    Yeah, that's me right now, heh. Whenever I start up RPG Maker, I open Notepad++ with rpg_core, rpg_objects, rpg_managers, rpg_scenes, rpg_sprites, and rpg_windows open.
  15. How could I force an item to be used on the last target instead of a skill?
  16. Alright, I want to know if there's a script command similar to $game_actors[x].name.capitalize from VX Ace in MV
  17. trakpichu said:
    Alright, I want to know if there's a script command similar to $game_actors[x].name.capitalize from VX Ace in MV

    $gameActors.actor(x).name().toUpperCase()
  18. I have a question about date classes. Are date classes that uses the new Date() function still get followed for mobile users or is it only accessible for PC systems?
  19. DreamX said:
    $gameActors.actor(x).name().toUpperCase()

    Huh, for some reason, it's not making any changes....
    The name still stays all caps "AAAAAA"
    or all lower case "aaaaaa"


    I swore it worked the other day, but maybe I'm just losing my mind.
  20. trakpichu said:
    Huh, for some reason, it's not making any changes....
    The name still stays all caps "AAAAAA"
    or all lower case "aaaaaa"


    I swore it worked the other day, but maybe I'm just losing my mind.

    If you actually want to change the name you'll need assign the value.

    Code:
    $gameActors.actor(x)._name = $gameActors.actor(x).name().toUpperCase()