JavaScript questions that don't deserve their own thread

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,593
Reaction score
2,934
First Language
English
Primarily Uses
RMMV
Is there a simple way to hide the item command in battle if it is sealed? Would I need a script for that?
You would need a plugin (scripts are for the earlier RPG Makers that use Ruby) such as Victor Engine's Command Replace.
 

Willibab

The Lord of Whackery
Veteran
Joined
Jun 22, 2017
Messages
540
Reaction score
1,363
First Language
Norwegian
Primarily Uses
RMMZ
So this is prolly a simple thing for many, but im bad at this stuff.

Using Himeworks weapon damage and the suggested formula is something like
10 * (Math.randomInt(5) + 1) which is fine ofc, but I tried to find an even simpler way for my simple brain and ended up with Math.randomInt(5) + 15. I tested it and it seems fine.

So the question is really just, is this an ok way to do 15-20 damage? Is the suggested way superior in some way I'm not aware of?

Would suck to have to go back and change it all in the long run :p
 

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
754
Reaction score
1,137
First Language
German
Primarily Uses
RMMV
@Willibab
The suggested formula will give you either 10, 20, 30, 40 or 50 damage.

If you want to deal 15-20 damage, you actually came close, but
its actually
"Math.randomInt(6) + 15"
instead of
"Math.randomInt(5) + 15"

Otherwise you'll end up with 15-19 damage instead.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
149
Reaction score
69
First Language
English
Primarily Uses
RMMV
When I first started using RPG Maker MV a couple of years ago, I wanted to put an external array in a variable. @Lanzy graciously wrote me a plugin that would do that. Essentially there are 2 lines, no parameters.
Code:
var $dataList = null;
DataManager._databaseFiles.push({name: '$dataList', src: 'List.json'});
Then all it needs is a simple assignment to a variable
◆Control Variables:#0001 arrayFromFile = $dataList

and a dialogue box will verify the contents
Contents of variable01 = \v[1]
shows
Contents of variable01 = dog,bird,cat,bird,horse

For reference, here's a link to Lanzy's Code plugin posted earlier in this same thread.

The plugin works great in MV, but not in MZ. Turning the plugin on in MZ prevents MZ from loading, giving this error (Note, this is a vanilla project, one map, one event, no plugins except Lanzy's.)

View attachment 220810

Console shows

View attachment 220811

Since I'm using the exact same plugin and .json file from MV, I have to assume MZ either doesn't support this or that the MZ terminology is slightly different.

tldr: Can someone translate MV's
Code:
var $dataList = null;
DataManager._databaseFiles.push({name: '$dataList', src: 'List.json'});
to MZ? As always, thank you to any and all who respond.

As an aside, I was loading the external file within the game itself using
Code:
var fs = require('fs');
:      :var wordList = fs.readFileSync("./data/wordListAbridged.dat", 'utf-8');
:      :$gameVariables.setValue(1, wordList);
but, apparently, if I deploy for web, the browser refuses to load the file and this is for a game I made for my grandchildren who use Chrome tablets, not Windows, so I really want to go the .json route if I can.

Edit-I was able to accomplish loading the word list by copying and pasting the file contents using variable = script, then running that event with autorun when the game starts. Works well enough, seems that the variable had no trouble holding 1700+ words, but I'd still like to know if there's an equivalent of DataManager._databaseFiles for MZ. Thanks again.
Hey there,

since I recently bought MZ I thought I'd give it a try and see if my script still works the way it did in MV. And so far I didn't have any issues. MZ uses exactly the same DataManager structure as in MV.

The error occurs when you use a primitive data type like strings or numbers. That means that something might be wrong with the json file you stored in the data folder. Can you post the json file your are using? That is, if you haven't solved the problem already.
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
149
Reaction score
69
First Language
English
Primarily Uses
RMMV
Is there a simple way to hide the item command in battle if it is sealed? Would I need a script for that?

During battle calls this script and the item command disappears.

JavaScript:
SceneManager._scene._actorCommandWindow._list.pop();
SceneManager._scene._actorCommandWindow.clearItem(3);

If you want it to return use:

JavaScript:
SceneManager._scene._actorCommandWindow.refresh();

You can also have it check if item command is enabled and if not, then have it removed

JavaScript:
let actorWindow = SceneManager._scene._actorCommandWindow;
actorWindow.refresh();

if (!actorWindow._list[3].enabled) {
    actorWindow._list.pop();
    actorWindow.clearItem(3);
}

Edit:
Sorry for double post, was too tired to realize
 

FarOutFighter

Veteran
Veteran
Joined
Sep 20, 2021
Messages
117
Reaction score
76
First Language
English
Primarily Uses
RMMZ
During battle calls this script and the item command disappears.

JavaScript:
SceneManager._scene._actorCommandWindow._list.pop();
SceneManager._scene._actorCommandWindow.clearItem(3);

If you want it to return use:

JavaScript:
SceneManager._scene._actorCommandWindow.refresh();

You can also have it check if item command is enabled and if not, then have it removed

JavaScript:
let actorWindow = SceneManager._scene._actorCommandWindow;
actorWindow.refresh();

if (!actorWindow._list[3].enabled) {
    actorWindow._list.pop();
    actorWindow.clearItem(3);
}

Edit:
Sorry for double post, was too tired to realize
Thank you. I will try those. I guess i would run those in troops?
 

Fionn23

Veteran
Veteran
Joined
Dec 11, 2021
Messages
85
Reaction score
44
First Language
Filipino
Primarily Uses
RMMZ
Script that let an event face the player's direction?
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
149
Reaction score
69
First Language
English
Primarily Uses
RMMV
Thank you. I will try those. I guess i would run those in troops?
I didn't test this, but try this plugin. It should run the script every time you reached the input phase of the battle.

The plugin looks like this
JavaScript:
BattleManager_alias_startInput = BattleManager.startInput;
BattleManager.startInput = function() {
    BattleManager_alias_startInput.call(this);
    let actorWindow = SceneManager._scene._actorCommandWindow;
   
    actorWindow.refresh();
    if (actorWindow._list[3] && !actorWindow._list[3].enabled) {
        actorWindow._list.pop();
        actorWindow.clearItem(3);
    }
}

Script that let an event face the player's direction?
You don't need a script for that. Just go to the event -> Route... -> Turn Toward Player
 

Attachments

  • RemoveItemCommand.js
    369 bytes · Views: 0

rpgLord69

Veteran
Veteran
Joined
Oct 23, 2021
Messages
248
Reaction score
220
First Language
Finnish
Primarily Uses
RMMZ
Can someone tell me what is wrong with this script code. I searched the forums and found this in a similar topic (I only edited some numbers and names). The idea is trying to use it in a battle script to get random skills at the start of the turn. In this testing phase I tried to set it to randomly select 3 skills out of 5 possilbe.

EDIT: I'm using MZ

JavaScript:
var skills = [12, 13, 14, 15, 16], vIds = [1, 2, 3];
for (var n = 0; n < vIds.length; n++) {
  if (skills.length === 0) break;
  var ix = Math.randomInt(skills.length);
  $gameParty.leader().learnSkill(vIds[n], skills.splice(ix, 1)[0]);
}
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
149
Reaction score
69
First Language
English
Primarily Uses
RMMV
Can someone tell me what is wrong with this script code. I searched the forums and found this in a similar topic (I only edited some numbers and names). The idea is trying to use it in a battle script to get random skills at the start of the turn. In this testing phase I tried to set it to randomly select 3 skills out of 5 possilbe.

EDIT: I'm using MZ

JavaScript:
var skills = [12, 13, 14, 15, 16], vIds = [1, 2, 3];
for (var n = 0; n < vIds.length; n++) {
  if (skills.length === 0) break;
  var ix = Math.randomInt(skills.length);
  $gameParty.leader().learnSkill(vIds[n], skills.splice(ix, 1)[0]);
}

Don't know what exactly isn't working, but one thing that does stick out is the learnSkill method.
If you look at it:
JavaScript:
Game_Actor.prototype.learnSkill = function (skillId) {
    if (!this.isLearnedSkill(skillId)) {
        this._skills.push(skillId);
        this._skills.sort(function (a, b) {
            return a - b;
        });
    }
};

It only takes one argument. But in your code it takes 2. What are the vIds for? And why splice skills? Are they supposed to be assigned only once? Also in your example you are missing a curly bracket at the end. Probably copy&paste mistake.
 

rpgLord69

Veteran
Veteran
Joined
Oct 23, 2021
Messages
248
Reaction score
220
First Language
Finnish
Primarily Uses
RMMZ
Don't know what exactly isn't working, but one thing that does stick out is the learnSkill method.
If you look at it:
JavaScript:
Game_Actor.prototype.learnSkill = function (skillId) {
    if (!this.isLearnedSkill(skillId)) {
        this._skills.push(skillId);
        this._skills.sort(function (a, b) {
            return a - b;
        });
    }
};

It only takes one argument. But in your code it takes 2. What are the vIds for? And why splice skills? Are they supposed to be assigned only once? Also in your example you are missing a curly bracket at the end. Probably copy&paste mistake.

Not working as in my character isn't gaining the skills. And I don't know anything about coding :D

I just copied that code from a different topic where it was talking about picking something out of an array (and using it for some other purpose than gaining skills). But since the purpose was kind of similar, I just thought that I could stick that learnSkill thing inside there (obviously not, haha).

Some of that code is meant for making sure that if it picks something, it can't be picked again. So for example if it picks skill number 13, then that number is taken out of the array when it picks the next one (or that's what I read).
 

Lanzy

Veteran
Veteran
Joined
Feb 29, 2020
Messages
149
Reaction score
69
First Language
English
Primarily Uses
RMMV
Not working as in my character isn't gaining the skills. And I don't know anything about coding :D

I just copied that code from a different topic where it was talking about picking something out of an array (and using it for some other purpose than gaining skills). But since the purpose was kind of similar, I just thought that I could stick that learnSkill thing inside there (obviously not, haha).

Some of that code is meant for making sure that if it picks something, it can't be picked again. So for example if it picks skill number 13, then that number is taken out of the array when it picks the next one (or that's what I read).
Oh ok, gotcha.

Try this:
JavaScript:
var skills = [12, 13, 14, 15, 16]
var randomSkillId = 0;

for (var n = 1; n <= $gameParty.size(); n++) {
    if (skills.length === 0) break;
    randomSkillId = Math.randomInt(skills.length);
    $gameActors._data[n].learnSkill(skills[randomSkillId]);
    skills.splice(randomSkillId, 1);
}
 

rpgLord69

Veteran
Veteran
Joined
Oct 23, 2021
Messages
248
Reaction score
220
First Language
Finnish
Primarily Uses
RMMZ
Oh ok, gotcha.

Try this:
JavaScript:
var skills = [12, 13, 14, 15, 16]
var randomSkillId = 0;

for (var n = 1; n <= $gameParty.size(); n++) {
    if (skills.length === 0) break;
    randomSkillId = Math.randomInt(skills.length);
    $gameActors._data[n].learnSkill(skills[randomSkillId]);
    skills.splice(randomSkillId, 1);
}

EDIT:
Ok, I think I got it to work now. So I changed that n <= $gameParty.size() to n <= 3 (and changed that gameActors part to party leader). Thanks for the help!

/////////////

Now (after changing that gameActors part to party leader thing) I'm getting one skill per turn. Maybe I wasn't clear enough, when I said pick 3 skills out of 5, I meant pick all 3 skills for just one character. So I'm testing a solo battle with just 1 character, and she is getting a number (3) of random skills from a pool (5 for test purposes) at the beginning of a turn. As I said, I don't understand code, but I see your code uses something called gameParty.size, so maybe that code would allocate skills to multiple party members?
 
Last edited:

Lady_JJ

Veteran
Veteran
Joined
May 6, 2019
Messages
417
Reaction score
306
First Language
English
Primarily Uses
RMMZ
Hey there,

since I recently bought MZ I thought I'd give it a try and see if my script still works the way it did in MV. And so far I didn't have any issues. MZ uses exactly the same DataManager structure as in MV.

The error occurs when you use a primitive data type like strings or numbers. That means that something might be wrong with the json file you stored in the data folder. Can you post the json file your are using? That is, if you haven't solved the problem already.
I tried it again with the same error. I replaced the file with a simple ["dog","bird","cat"] file and it loaded as expected, so I'm sure you're right that there's something wrong with my new text file. Hardcoding the file contents into the variable works really well, so it's not a huge deal. To make this new file, I took a 5 letter word list with a few thousand words, manually removed uncommon and/or obscure words, added quotes around each word, inserted commas, etc. It's entirely likely I corrupted the file in some way.
Thanks for weighing in. :)
 

alltheyuriz

The one the only Cat Dad
Veteran
Joined
Sep 18, 2020
Messages
750
Reaction score
541
First Language
English
Primarily Uses
RMMZ
One of my plugins supports javascript and I was wondering if there was a piece of code I could use to make the gab window smaller it's too big and there isn't a setting for it
 

Otacon6530

Veteran
Veteran
Joined
Apr 12, 2022
Messages
32
Reaction score
20
First Language
English
Primarily Uses
RMMV
Has anyone made an Object to Object mapping of RPG Maker MZ or any other quick reference resources that I can use for plugin development. It would expedite my development process.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,593
Reaction score
2,934
First Language
English
Primarily Uses
RMMV
EDIT:
Ok, I think I got it to work now. So I changed that n <= $gameParty.size() to n <= 3 (and changed that gameActors part to party leader). Thanks for the help!

/////////////

Now (after changing that gameActors part to party leader thing) I'm getting one skill per turn.
Yeah, looks like there was a misunderstanding with the replacement code you were given.
Code:
var skills = [12, 13, 14, 15, 16];
var randomSkillId;

for (var n = 1; n <= 3; n++) {
    randomSkillId = Math.randomInt(skills.length);
    $gameParty.leader().learnSkill(skills[randomSkillId]);
    skills.splice(randomSkillId, 1);
}

I have no idea what's going on in that original snippet you posted, but this one will make the party leader learn 3 skills randomly chosen from the 5 (or however many) you type into the skills array on the first line.

One of my plugins supports javascript and I was wondering if there was a piece of code I could use to make the gab window smaller it's too big and there isn't a setting for it
This should be its own thread in Plugin Support, wherein you provide a link to the plugin in question. Just referencing a "gab window" doesn't mean anything, code-wise, and it's a little pointless to toss suggestions at you without seeing the code that makes the window in the first place.
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
773
Reaction score
276
First Language
English
Primarily Uses
RMMV
Hey, quick question. Is there a script call I can use to set Actor X (ID equal to a variable) to party slot 2? The actor is already in the party.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,593
Reaction score
2,934
First Language
English
Primarily Uses
RMMV
Is there a script call I can use to set Actor X (ID equal to a variable) to party slot 2?
No, you can't directly set an actor to a place in the party - what would happen to any actor already in that spot? And the rest of the party?

There is a $gameParty.swapOrder() function, so you have to use a little logic with it. The easiest thing to do would be:
Code:
$gameParty.swapOrder(1, $gameParty.members().indexOf($gameActors.actor(X)));
where X is the ID of the actor you want to move. That will swap that actor with whichever was already in position 2.
 

Vis_Mage

Wisp Charmer
Veteran
Joined
Jul 28, 2013
Messages
773
Reaction score
276
First Language
English
Primarily Uses
RMMV
where X is the ID of the actor you want to move. That will swap that actor with whichever was already in position 2.
Ah, I probably didn't phrase that very clearly. Swapping the actor in the second slot with actor X is what I was hoping to do, and the script call works like a charm. Thank you! :kaothx:
 

Latest Threads

Latest Posts

Latest Profile Posts

No matter how long it takes, the cliches of modern humanization still enrage me. :(

Also...

Random Person: Looks are superficial. It doesn't matter what a hero looks like.

Same Person: EVERY hero NEEDS to look like a human even if they're not supposed to be and it makes no sense for them to look human.
Happy treason day, Colonial friends <3

I am officially amused. One of the NPCs in my project is basically meant as the guy you check in with to point you where you should go next, including if you’ve been away for a bit and have forgotten.

I can conclusively say he does his job nicely. I was out of town over the weekend. I had forgotten what I was working on, so I checked what I had last done with him for a reminder. ^.^
While talking about anime with a friend got the idea of doing this. :kaopride:
4m6nhlF.jpg

Character: Mirajane Strauss from Fairy Tail.

Forum statistics

Threads
123,345
Messages
1,155,924
Members
161,772
Latest member
katgamer666
Top