JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 56 of 171 View original ↗
  1. Disclaimer: I'm new to coding and self taught so not very good and generally don't understand what I'm looking at.

    I'm trying to get a random encounter script going that pulls from a certain region list on the map if desired (e.g. I have bats only show up in region 8).

    For instance I have this script working to make a random encounter, but it only takes into account the players current location as it stands:
    Code:
    var troopId;
    
    troopId = $gamePlayer.makeEncounterTroopId();
    
    BattleManager.setup(troopId, true, true);
    
    $gamePlayer.makeEncounterCount();
    
    SceneManager.push(Scene_Battle);

    I've tried a couple things like spoofing my players location and trying to figure out $gamePlayer.meetsEncounterConditions() but I don't think I'm using it right because it doesn't work.

    Can I get some help?
  2. Hello, I am using Yanfly's Battle AI core and I have a character whose primary job is to debuff. I want bosses to be able to counter act that with a skill, but I am not sure how to code that within the plugin. I'm basically looking for a script to use in that plugin that if a stat is debuffed use skill x.
    I have no knowledge of any javascript.
    Thanks.
    edit: Here is the plug in: http://yanfly.moe/2015/10/19/yep-16-battle-a-i-core/
  3. Hello there guys, I'm using Yanfly's Attachable Augment plugin. Thing is, I need to unequip and remove the weapon equipped by the character at some point then equip them with another weapon. If that weapon has augments attatched, it'll disappear along with the removed weapon.

    I'd like to ask if there's any method or plugin command to force remove the augments on such weapon automatically.
  4. YEP CoreEngine uses a console but i don't know what to type. For testing purposes I want to manually add items to inventory or obtain certain equipment without buying it and other stuff like that. Any help would be appreciated!
  5. It's not yep core engine console, but whatever.

    In order to gain extra items I use this (gives me all items 99x):

    Code:
    for (var i = 1; i < $dataItems.length; i++) $gameParty._items[i] = 99
    For weapons and armors it's the same, just replace itens with weapons or armors.
  6. How do I check to see if an actor has a shield equipped?
  7. try

    Code:
    if ($gameActors[id].equips[1])
    
    or maybe
    
    if ($gameActors[id].equips[1] != nil)

    But if you are dual wielding and has a sword in the second slot, this might also be true..
  8. Engr. Adiktuzmiko said:
    try

    Code:
    if ($gameActors[id].equips[1])
    
    or maybe
    
    if ($gameActors[id].equips[1] != nil)

    But if you are dual wielding and has a sword in the second slot, this might also be true..

    Hmm. I still can't seem to get it to work. I tried doing it that way, and when that didn't work, I also tried altering it a bit, but nothing seems to work. it's in Lunatic Mode of a Yanfly plugin, and here is the context it would be in:

    Code:
    if (user.isStateAffected(13) && <CODE GOES HERE>) {
  9. No wonder it didn't work, the code was wrong.
    It would be correct if it was
    $gameActors.actor(id) or $gameActors._data[id]. Nevertheless, in your case you can just use
    Code:
    user.equips[1]
    .
  10. Poryg said:
    No wonder it didn't work, the code was wrong.
    It would be correct if it was
    $gameActors.actor(id) or $gameActors._data[id]. Nevertheless, in your case you can just use
    Code:
    user.equips[1]
    .

    I actually had tried user.equips[1] without success too. But I just figured out the primary problem, which is that I had something else screwed up with my passive states. Once I fixed that, the following seems to be working:

    Code:
    user.equips()[1].etypeId !== 2

    (I'm actually checking to see that the character doesn't have a shield equipped, although I phrased the question the other way.)

    That looks messier than the suggestions, but it's the only one working.
  11. Oooh yes... Its a JS Function.. equips() makes sense.. xD
  12. Yeah and I forgot an underscore in the code :D But glad it works now.
  13. Hi all,

    I'm making an event to run at the beginning of battle, which needs to set each actor and enemy's MRG to = (Math.randomInt(20) + 1). The random number needs to be determined for each individual--ie, they can't all use the same result. (It's okay, though not ideal, if all enemies of a type, or even all enemies use the same number if it's too difficult to do it the other way, but actors absolutely have to have their own numbers.)

    Unfortunately, I haven't yet figured out how to set that ex-parameter, or how to run the same command for all battlers.

    Thanks for any help.
  14. Hey all.

    Any idea how to get the current map size in a script or variable?

    The only solution I found so far is to past an Event in the bottom right, and get it from it.

    Cheers.

    Edit: looks like I can use "$gameMap.width()" and "$gameMap.height()" to retreive them!
  15. Question from a JavaScript Idiot.

    This works in a damage formula:

    Code:
    if(Math.randomInt(20) + 1 + (a.mev/0.1) + Math.floor((a.atk-10)/2) > Math.randomInt(20) + 1 + (b.mev/0.1) + Math.max(Math.floor((b.atk-10)/2), Math.floor((b.def-10)/2))) {b.addState(50);} else {0;}

    But this doesn't:
    Code:
    if(Math.randomInt(20) + 1 + {if(a.isStateAffected(81)) {a.mev/0.025;} else {0;}} + Math.floor((a.atk-10)/2) > Math.randomInt(20) + 1 + (b.mev/0.1) + Math.max(Math.floor((b.atk-10)/2), Math.floor((b.def-10)/2))) {b.addState(50);} else {0;}

    Nor this:
    Code:
    if(Math.randomInt(20) + 1 + (if(a.isStateAffected(81)) {a.mev/0.025;} else {0;}) + Math.floor((a.atk-10)/2) > Math.randomInt(20) + 1 + (b.mev/0.1) + Math.max(Math.floor((b.atk-10)/2), Math.floor((b.def-10)/2))) {b.addState(50);} else {0;}

    What is the correct way to nest if/else in the damage formula for it to work? (I've probably just made some sort of basic syntax error, but I've been messing around with it for a while now and haven't been able to determine what it would be.)
  16. @Sword of Spirit Yeah, it's multiple syntax issues. I highly encourage you to write the Javascript in a text editor that checks the syntax for you, or to use an online syntax checker. You can also write it over multiple lines to see it easily before shortening to one line for the damage formula.

    Code:
    if(Math.randomInt(20) + 1 + {
        if(a.isStateAffected(81)) {
            a.mev/0.025;
        } else {
            0;
        }
    }
    + Math.floor((a.atk-10)/2) > Math.randomInt(20) + 1 + (b.mev/0.1) + Math.max(Math.floor((b.atk-10)/2), Math.floor((b.def-10)/2))) {
        b.addState(50);
    } else {
        0;
    }
    1. The first "if" statement is never completed.
    2. Using addition after an "if" block won't work
    3. There's a "greater than" symbol thrown in the middle of a bunch of addition
    4. There's an "else" without a corresponding "if"

    I can't really tell what you're trying to do, I would suggest writing out in pseudo-code first to get the logic down, then trying a very simplified example to get the syntax correct and add more to it later.
  17. Okay, here's what I'm trying to do with it:

    Code:
    If it is true that:
    (
    
    (
    Math.randomInt(20) + 1
    +
    (if the character has state 81, then include a.mev/0.025)
    +
    (if the character doesn't have that state, then include 0)
    +
    Math.floor((a.atk-10)/2)
    )
    
    is greater than
    
    (
    Math.randomInt(20) + 1
    +
    b.mev/0.1
    +
    (if the character doesn't have that state, then include 0)
    +
    Math.max(Math.floor((b.atk-10)/2), Math.floor((b.def-10)/2))
    )
    
    )
    
    Add state 50 to b
    
    Otherwise do 0 damage

    It's actually more complex than that (b.mev/0.1 is replaced by something more like the conditional state check on the other side of the > sign, and checks are made for 2 states in each instance before defaulting to adding 0 if neither state exists), but this was the first complication that stopped the formula from working, so I figured I should start there and then add each part individually.
  18. Sometimes it's best to break it down into sections and have temporary values to compare with. I think this would work for you based on that pseudo-code:
    Code:
    var userAmount = Math.randomInt(20) + 1 + Math.floor((a.atk-10)/2);
    if (a.isStateAffected(81)) { userAmount += a.mev / 0.025; }
    
    var targetAmount = Math.randomInt(20) + 1 + Math.max(Math.floor((b.atk-10)/2), Math.floor((b.def-10)/2));
    if (b.isStateAffected(81)) { targetAmount += b.mev / 0.1; }
    
    if (userAmount > targetAmount) { b.addState(50); }
    0;
    You can combine it into 1 line to fit in the damage formulas. The semi-colons are important to separate each statement.
  19. Thank you! It works. In case you're interested, here is the final code that includes the other parts:

    Code:
    var userResult = Math.randomInt(20) + 1 + Math.floor((a.atk-10)/2);
    if (a.isStateAffected(81)) { userResult += a.mev / 0.025; }
    if (a.isStateAffected(82)) { userResult += a.mev / 0.05; }
    var targetResult = Math.randomInt(20) + 1 + Math.max(Math.floor((b.atk-10)/2), Math.floor((b.def-10)/2));
    if (b.isStateAffected(81) || b.isStateAffected(75)) { targetResult += b.mev / 0.025; }
    else if (b.isStateAffected(82) || b.isStateAffected(76)) { targetResult += b.mev / 0.05; }
    if (userResult > targetResult) { b.addState(50); } 0;

    For the attacker, they can only benefit from State 81 or 82, but the same actor would only ever have one of those. For the defender, they get to use the best of 81 or 75, or the best of 82 or 76. It is possible for them to have both 81 and 76, or 75 or 82, so I needed the else in there. I'm not running into any problems with it, but if you see one jump out at you, let me know, thanks!
  20. Hello. Newbie question: Where do I put the plugins gotten from the official downloads from purchasing RPGmaker MV? There is no readme in any of the files, and the only readme is in japanese