Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

[Plugin] Need help for a plugin

Status
Not open for further replies.

David FoxFire

Adventurer
Xy$
0.00
I have a script that, instead of improving on an existing feature, has it's own need for number-crunching. It basically simulates a d20 roll from table top RPGs, where a modifier is tallied up based on attributes and is added to a d20 roll. The result is given back to the event that calls the roll.

I can easily code in the d20 roll, setting up the attributes, and adding up the modifiers with the coding skill I have now, barring noobie syntax errors of course. It's getting it into a plugin format that I can use with MV that is the problem, and it's the part I need the most help with.

Any and all assistance will be apprecaited. Thanks in advance.

Revision List...

Revision 1: Updated my script to show the correct syntax to deal with $gameVariables and $gameSwitches . Thanks go to eivl for this. I still need to find out how to check whatever a certain character is in the party. Right now I have "$game_party.members.include?(3)" and I know for sure that I'm way off. Of course the big problem is converting this into a plugin so I can make the plugin calls, which is the main omission in this script.

I do need to put in more functions, but I want to make sure that the script is in plugin form before I do that, so I'll know what to add to the file.

Revision 2: Added some documentation and adjusted the code around. Now all the variables going in and out of the script are stored in $gameVariables and $gameSwitches for easy transition between the script and RMMV's event editor. Now you set the variables and switches and just run the plugin command (once it become a plug-in, that is)

A list of the used $gameVariables and $gameSwitches used is in the documentation.

Revision 3: Now I'm in the process of learning Object Oriented Programming, and turning these formulas into Methods. Since I'm still starting off with this, it's still feeling like pulling teeth to understand this part.

Revision 4: Added a function that helped deal with two needs at once: Find out whatever someone is in the party, and if so, what's that character's level. Also started on creating the Script Calls, but they still don't work.

Revision 5: After seeing how other plug-ins are doing it, and recognizing the patters in the more important Plug-In Command Section of the codes, I was finally able to get this plug-in to work. At this incarnation, I was able to use a Plugin Command to install the array, which is a very important step in the right direction. There might be some more debuging for the other two commands, but at this point, I'm very satisfied with the current success of this plug-in, and now that I know how to make one, I can work now on perfecting the code (and dealing with all the bugs) for the completed game.

I'd like to thank @eivl for all of his assistance, he's been a great tutor on how to make plugins. And without him, I would've never gotten my head around Object-Oriented Computing.
 

Attachments

Last edited:

LTN Games

Master Mind
Resource Team
Xy$
0.01
Thank you very much for the move. Sometimes I just don't know where to put a question in, and appreciate the correction without having my face bit off over it.
No worries I know it happens, plus I don't bite heads off, not my style lol Though I do like memes once in a while.
 

David FoxFire

Adventurer
Xy$
0.00
Updated to show my progression in JS calls in MV.

And you can't go wrong with Picture Memes. I'll refrain from flooding the forum with 'em.
 
Last edited:

eivl

Local Hero
Xy$
0.00
I still need to find out how to check whatever a certain character is in the party
Is this your next task? and since I am having difficulty following all threads now, just link my name with the @ char + eivl

@eivl and i will see it! =)

There is Javascript thread, Resource request thread and MV Support... kinda hard to find everything! ;)
Now there is some good feedback @LTN Games ;)
[doublepost=1446033870,1446032243][/doublepost]you should also look how other plugins hook up their code, how do you plan on interacting with this? custom menu? or something else?
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
There is Javascript thread, Resource request thread and MV Support... kinda hard to find everything! ;)
Now there is some good feedback @LTN Games ;)
I know lol. Javascript is for talking about javascript so learning about the language itself, Resource Request is for requesting plugins, pixel art, portrait art etc, and MV Support is technical support for everything MV, including plugins. I'f that helps anything lol.
 

eivl

Local Hero
Xy$
0.00
I know lol. Javascript is for talking about javascript so learning about the language itself, Resource Request is for requesting plugins, pixel art, portrait art etc, and MV Support is technical support for everything MV, including plugins. I'f that helps anything lol.
I see... well.. no it did not help ;) ill just write everywhere, level up my avatar and get all the powerlevels! =)
 

David FoxFire

Adventurer
Xy$
0.00
I know lol. Javascript is for talking about javascript so learning about the language itself, Resource Request is for requesting plugins, pixel art, portrait art etc, and MV Support is technical support for everything MV, including plugins. I'f that helps anything lol.
Well, it looks like you tried to simplify things @LTN Games , but Mr. Murphy came and screwed things up.

Meanwhile, I did some changes to the two main "Script Command" funcitons so that it uses $gameVariables instead of javascript Formula Arguments and Returns, and provided some more documentation.

@eivl you should also look how other plugins hook up their code, how do you plan on interacting with this? custom menu? or something else?
Like I said, I'd set some Variables and Switches by an Event, make a Plugin Command for either INDIVIDUAL_CHECK or TEAM_CHECK, and have the resulting dice roll put into another Variable for the event to use. I added some documentation that I hope explains matters.
 

eivl

Local Hero
Xy$
0.00
How do you plan on calling your function? and how are you going to output the information.



There are also a few errors, what IDE are you using?

And if someone else comes along and write a plugin that uses the function Roll20 you will get stumped.
You should use one of two in my hones opinion.
  1. Use an anonomous function without global variables
  2. Use a prefix object and store everything inside that.
  3. combination of both ;)
as an axample.
you have a function called LoadCharArray()
It is in your code unused, but guessing this is a work in progress.

You could store it in the already existing DataManager class, that manages the database and game objects.
JavaScript:
DataManager.LoadCharacterArray = function() {

var Attribute_Array = [ [0, 1, 1, 3, 3, 2],  //Florence
[3, 1, 3, 0, 1, 3],  //Minsc
[0, 2, 0, 1, 1, 3],  //Delina
[2, 2, 1, 2, 1, 1],  //Krydle
[1, 3, 0, 2, 1, 2] ]; //Shandie

for (var a=0, a<5, a++) {
for (var b=0, b<6, b++) {
var c = 100 + (a * 6) + b;
var d = Attribute_Array[a,b];
$gameVariables.setValue(c, d);
}


}
And then you can call this function inside the DataManager.isDatabaseLoaded
and since you are then reffering to the object, you call it with
this.LoadCharacterArray();

makes sense?
 

David FoxFire

Adventurer
Xy$
0.00
This will show what kind of level of coder you're working with, @eivl : IDE? What's that?

LoadCharacterArray would be a third plug-in Command I haven't mentioned yet. This is the function that loads that array into the $gameVariables.

So I can revise the script like you have here, and it would load up okay and I can use in the Event: Plugin Command: this.LoadCharacterArray(); and it'll work?
 

David FoxFire

Adventurer
Xy$
0.00
Ide : what text editor are you using

And you do not call function with this. Outside of a metoder.
I'm using Sublime Text for my code editor. Excellent color coding.

And not being able to call a function outside of a medoder, whatever that is (yep, I'm a nooblet) is something I thought would be the case. I might have to google what a metoder is.
 

eivl

Local Hero
Xy$
0.00
Damn you autocorrect.. Method! =)

You can call a method outside, but then you use the name of the method. "this." refers to the object the code is writen in.
 

David FoxFire

Adventurer
Xy$
0.00
Now then, how to turn a funciton into a method. Better hit those books.

Later.....

I think I might have found something @eivl .
I looked around for some tutorials and might need someone to talk me through this.

I first have to set up a global object. Like this:

JavaScript:
var Imported = Imported || {};
Imported.ElministerEngine001 = "0.10";

var Elminister = Elminister || {};
That first part is found on just about every plugin out there, might as well put that in. The second part is the Global Object.

Now then, most of the funcitons here are self-contained, there's no really dependent parts. So I should have the functions start like this....

Elminister.prototype.LoadCharacterArray = function() { .....
Elminister.prototype.callAttributeModifier = function (pcNumber, pcAttribute) { .....
Elminister.prototype.FifthEDRoll20 = function (modifier, advantage) {.......

....and so on, and I can still call on functions while in the same script with something like "this.callAttributeModifier (a, b)" .

Am I in the right direction?
 
Last edited:

eivl

Local Hero
Xy$
0.00
On mobile, but i will start a new thread on DEV den talking about javascript objects. It will be use full for you :)

But yeah, you are going in the right direction :)
 

David FoxFire

Adventurer
Xy$
0.00
On mobile, but i will start a new thread on DEV den talking about javascript objects. It will be use full for you :)

But yeah, you are going in the right direction :)
That's good to hear. I've updated the script in the opening post for you to review. I got everything in the methods I listed above. Now to get them connected to PluginCommands. I've seen something in a Yanfly Plugin that might be of some help:

JavaScript:
Yanfly.SEL.Game_Interpreter_pluginCommand =
    Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
  Yanfly.SEL.Game_Interpreter_pluginCommand.call(this, command, args)
    if (command === 'ResetAllEventLocations') $gameMap.resetAllEventLocations();
};
If that's the case, maybe adding this at the end of the script will enable the plugin commands on my script:

JavaScript:
Elminister.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args){
    Elminister.Game_Interpreter_pluginCommand.call(this, command, args)
        if (command === 'El_LoadAttributeArray') this.LoadCharacterArray();
        if (command === 'El_IndividualCheck')    this.individual_check();
        if (command === 'El_TeamCheck')          this.Team_Check();
};
Third Post: (Note that I'm keeping editing this one and not Double or Triple Posting. You're welcome admins)

The previous script might be far off, or at least, there shouldn't be 'Elminister' in there. This might be where the proverbial rubber meeting the road.

Also, while looking at other people's plugins, I came across someting I feel is missing in mine. Most of the plug-ins that have commands have a header like:

var Imported = Imported || {};
var Elminister = Elminister || {};
Elminister.Fifty = {};
"use strict";
(function ($) {

and ends with this funny-looking tag:

})(Elminister.Fifty);

Of course, I edited these parts to show how they might appear in my script. Object-based code is still giving me a headache, I have to admit, although your tutorials @eivl , are a big help.
 
Last edited:
Status
Not open for further replies.
Top