JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 129 of 171 View original ↗
  1. RMMV - is there a way to dynamically change the icon for an active state applied on a battler based on a property added to the battler? At some point i thought of a more efficient way to handle a set of states in my game. It would condense 8 states for each element into 1, but i want to be able to communicate to the player which element is active through the icon if i do this.
  2. Robro33 said:
    RMMV - is there a way to dynamically change the icon for an active state applied on a battler based on a property added to the battler?
    The way would be to write a plugin that changes how the icon is drawn. By default, it references the database entry for the state, so you'd have to modify that to look at, say, a notetag.

    If you're not sure how to do that, I think it definitely deserve its own thread.
  3. Is there a way to make the code wait for the animation?


    JavaScript:
                                  if (attackInstructions.CasterAnimID > 0) {
                                      $gameTemp.requestAnimation([$gamePlayer], attackInstructions.CasterAnimID);
                                  }
                                  if (attackInstructions.TargetAnimID > 0) {
                                      $gameTemp.requestAnimation([$gameMap.event(EnemyArray[target - 1].enemyEventId)], attackInstructions.TargetAnimID);
                                  }

    Or at least show one after another even without the code waiting for them to be done
  4. Ok, I need help converting a notetag with multiple values into an array, i.e. <drops: 4, 5, 6>. I modified a ChronoEngine item spawning script to spawn 1-3 loot items within a 0.5 radius of the enemy, except it spawns the same item 1-3 times because I don't know how to convert a multivalue notetag to an array to run scripts on.

    JavaScript:
    //Restart ChronoEngine Enemy Treasure Spawn (modded)
    Game_CharacterBase.prototype.makeTreasure = function(char,battler) {
       var treasures = battler.makeDropItems();
        if (treasures.length > 0) {
           var rt = Math.randomInt(treasures.length);
           var item = treasures[rt]
           if (item.id == 50)
           {
                var randomCount = Math.floor(Math.random() * 3) + 1; //randomly spawn between 1 and 3 items
                for (var i = 0; i < randomCount; i++) {
                    //spawn items in random location in .5 radius from death
                    Ritter.spawnEvent(39, $dataEnemies[char.battler()._enemyId].meta.drops, char.x +Math.random()-0.5, char.y +Math.random()-0.5, false);
               }
    
           }else
           {
               char._user.treasure = [item,false,0,0,20];     
               char._characterName = 'treasurebattlertool'
               $gameMap._treasureEvents.push(char);
           }
           char._user.collapse = [true,0];
          
       };
    };
  5. var drops = whatever_object.meta.drops.split(',') ?

    P.S. may want to use .trim afterwards as you iterate through the array to get rid of white spaces around.
  6. TESTOSTERONE said:
    var drops = whatever_object.meta.drops.split(',') ?

    P.S. may want to use .trim afterwards as you iterate through the array to get rid of white spaces around.
    Nice, it worked. Thanks for the quick reply.

    1692501655336.png

    Edit: Added the trim()
    Modded script
    Code:
    //Restart ChronoEngine Enemy Treasure Spawn (modded)
    Game_CharacterBase.prototype.makeTreasure = function(char,battler) {
       var treasures = battler.makeDropItems();
        if (treasures.length > 0) {
           var rt = Math.randomInt(treasures.length);
           var item = treasures[rt];
           if (item.id == 50)
           {
                var randomCount = Math.floor(Math.random() * 3) + 1; //randomly spawn between 1 and 3 items
                var dropArray = $dataEnemies[char.battler()._enemyId].meta.drops.split(',');
                for (var i = 0; i < randomCount; i++) {
                    var rd = Math.randomInt(dropArray.length);
                    var drop = dropArray[rd].trim();
                    //spawn items in random location in .5 radius from death
                    Ritter.spawnEvent(39, drop, char.x +Math.random()-0.5, char.y +Math.random()-0.5, false);
               }
    
           }else
           {
               char._user.treasure = [item,false,0,0,20];   
               char._characterName = 'treasurebattlertool'
               $gameMap._treasureEvents.push(char);
           }
           char._user.collapse = [true,0];
        
       };
    };
  7. Sorry for the basic question. I'm trying to make a conditional branch for a character repairing bridges and other devices on every map but needs a specific amount of items for it at the same time. I tried to make control variables but I'm not sure how to add several to a single branch.

    Say the party needs Logs x5 being game id 2; Nails x10 game id 3 and Hammer x1 game id 4. How can I type this in an If Script branch?

    Thanks again for the help.
  8. Ryousoo said:
    Sorry for the basic question. I'm trying to make a conditional branch for a character repairing bridges and other devices on every map but needs a specific amount of items for it at the same time. I tried to make control variables but I'm not sure how to add several to a single branch.

    Say the party needs Logs x5 being game id 2; Nails x10 game id 3 and Hammer x1 game id 4. How can I type this in an If Script branch?

    Thanks again for the help.
    If: Script: ($gameVariables.value(2)>=5 && $gameVariables.value(3)>=10 && $gameVariables.value(4)>=1)
  9. Ryousoo said:
    Say the party needs Logs x5 being game id 2; Nails x10 game id 3 and Hammer x1 game id 4. How can I type this in an If Script branch?
    Aside from making it shorter to read, there's really no reason to script this. You can simply set the three variables and then nest three conditional branches.

    If you are going to script it, I don't see any reason for you to be using any game variables at all. Just directly check whether the party has the items by item ID.

    Conditional Branch -> Script -> $gameParty.numItems($dataItems[X])>=5 && $gameParty.numItems($dataItems[Y])>=10 && $gameParty.numItems($dataItems[Z])>=1
    where X, Y, and Z are the database IDs of your three items.
  10. Hello, hoping someone can help with this.

    I'm trying to add a check if the target is an actor or not which will adjust the tick damage of the state. It works if I simply say "
    var damage = stacks * caster.mhp * 0.5", but when I add the if statement it doesn't work anymore.

    Code:
    var caster = target.stateOrigin();
    var damage = stacks * if (caster.isActor()) {
    caster.mhp * 0.5 }
     else {
    caster.mhp * 0.01 } ;
    target.gainHp(-damage);
  11. Code:
    var caster = target.stateOrigin();
    var damage = stacks * (caster.isActor() ? caster.mhp * 0.5 : caster.mhp * 0.01);
    target.gainHp(-damage);
  12. RCDunn said:
    I'm trying to add a check if the target is an actor...but when I add the if statement it doesn't work anymore.
    If statements are their own code statement - you can't embed them inline another. To use them, you'd have to do:
    Code:
    let damage=stacks;
    if (caster.isActor())
        damage*=caster.mhp*.5;
    else
        damage*=caster.mhp.01;

    One little efficiency note is that conditionals automatically apply to the next single statement. So if you're only doing one thing there's no need to create a code block with braces.

    Or you can use the ternary operator that @TESTOSTERONE demonstrated above. That, like all operators, can be used inline in the middle of a code statement (and technically doesn't even need the parentheses).
  13. Anyway to substitute 'down' with $gamePlayer.direction() in
    Input.isLongPressed('down')

    I want to check if the player has been holding down the button of the direction they're currently facing

    Edit: I ended up doing this although I can't help but feel there was a better way
    JavaScript:
    switch($gamePlayer.direction()){
    case 2: if(Input.isLongPressed('up')){$gameTemp.reserveCommonEvent(27);}break;
    case 4: if(Input.isLongPressed('left')){$gameTemp.reserveCommonEvent(27);}break;
    case 6: if(Input.isLongPressed('right')){$gameTemp.reserveCommonEvent(27);}break;
    case 8: if(Input.isLongPressed('down')){$gameTemp.reserveCommonEvent(27);}break;
    }
  14. AquaEcho said:
    I ended up doing this although I can't help but feel there was a better way
    Not really, because the game has no need to reverse engineer from the numeric direction to the button label.

    You could make it fewer lines of code this way:
    Code:
    [0, 1, 'down', 0, 'left', 0, 'right', 0, 'up'][$gamePlayer.direction()]
  15. im having this problem where upon opening the text box window/choice windows, the animation displays white(?) squares and its really annoying

    ill attach a gif, but does anyone have an idea on how to fix that? asking here because i do have GALV VN style choices and Visus message core plugins installed . ..

    id appreciate any help, thank you in advance

  16. pepiball said:
    im having this problem where upon opening the text box window/choice windows, the animation displays white(?) squares and its really annoying

    ill attach a gif, but does anyone have an idea on how to fix that? asking here because i do have GALV VN style choices and Visus message core plugins installed . ..

    id appreciate any help, thank you in advance


    I don't think this is a javascript issue so much as a plugin issue (compatibility). Does it still happen if you turn VisuStella off?
  17. AquaEcho said:
    I don't think this is a javascript issue so much as a plugin issue (compatibility). Does it still happen if you turn VisuStella off?
    it sadly both does - neither turning off VisuStella or the Galv plugins works :kaoeh:
  18. If this is happening when no plugins are active, it could be an outdated driver issue.
  19. pepiball said:
    im having this problem where upon opening the text box window/choice windows, the animation displays white(?) squares
    As @AquaEcho says, you're not really asking anything specific about JavaScript - from the first post of this thread, it's not for issues with plugins.

    You'll get better answers starting your own thread asking about this. Please include links to the plugins you're using and full details. For example, when I look up the Galv plugin you mention, it's for MV not MZ - if you're not modifying it in any way, that could cause problems by itself.

    Also include whether it happens in a brand new project, not using that customized windowskin in your GIF.
  20. ATT_Turan said:
    You could make it fewer lines of code this way:
    Code:
    [0, 'down', 0, 'left', 0, 'right', 0, 'up'][$gamePlayer.direction()]
    Okay I need some handholding... what exactly is being done here?