JavaScript questions that don't deserve their own thread

jaykeith

Villager
Member
Joined
Jun 22, 2016
Messages
27
Reaction score
11
First Language
English
Primarily Uses
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?
 

Mordridakon

I am a dragon!
Veteran
Joined
Feb 6, 2019
Messages
90
Reaction score
177
First Language
English
Primarily Uses
RMMV
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/
 
Last edited:

luzi

Freelance Artist
Veteran
Joined
Mar 25, 2012
Messages
198
Reaction score
475
First Language
Thai
Primarily Uses
RMMV
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.
 

GoldenGemGames

Veteran
Veteran
Joined
Aug 28, 2018
Messages
73
Reaction score
9
First Language
English
Primarily Uses
RMMV
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!
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
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.
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
How do I check to see if an actor has a shield equipped?
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
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..
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
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>) {
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
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]
.
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
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.
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Oooh yes... Its a JS Function.. equips() makes sense.. xD
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Yeah and I forgot an underscore in the code :D But glad it works now.
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
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.
 

Narch

Veteran
Veteran
Joined
Jan 13, 2017
Messages
66
Reaction score
9
First Language
French
Primarily Uses
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!
 
Last edited:

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
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.)
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
@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.
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
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.
 
Last edited:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
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.
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
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!
 

Brandon Thomason

Dragon Rearling
Veteran
Joined
Oct 21, 2017
Messages
34
Reaction score
6
First Language
English
Primarily Uses
RMMV
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
 

Users Who Are Viewing This Thread (Users: 2, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,015
Messages
1,018,351
Members
137,801
Latest member
topsan
Top