Script for plugin command

Discussion in 'Javascript/Plugin Support' started by Blaink, Jul 10, 2017.

  1. Blaink

    Blaink Villager Member

    Messages:
    18
    Likes Received:
    0
    First Language:
    Enlgish
    Primarily Uses:
    RMMV
    Hello!

    I'm hoping to execute this plugin command through Java script, so that I can replace the arguments (I think thats what theyr're called) with game variables. Correct me if I'm wrong, but I don't think plugin commands support java script or text-based variable calls...

    The plugin command I want to invoke is: CopyActor x y
    (I want x = variable1, while just using 4 for y)

    Plugin:
    Copy Actors
    Version 1.00
    SumRndmDde

    So, I tried the following :

    Script attempt at plugin command:
    CopyActor $gameVariables.value(1) 4

    Text attempt at plugin command:
    CopyActor \V[1] 4

    Both have failed... which is why I think using a script, instead of a plugin command would work better.

    Thank you a thousand times!!
     
    #1
  2. Andar

    Andar Veteran Veteran

    Messages:
    28,002
    Likes Received:
    6,327
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    you completely misunderstood what the plugin command does.

    If someone writes a plugin with a function, then he can include in that plugin an option to respond to plugin commands.
    The plugin command itself is nothing but a text line that is transfered to the plugin to be parsed and processed there.

    So if you want to change how the plugin command works, you need to rewrite the plugin itself.

    The alternative is using a script function, but again the plugin needs to provide that script function. It is nothing that would work on general purpose but only specific to each plugin.
    And if the plugin does not contain the script function you want, then it needs to be rewritten to give that option.
     
    #2
  3. Blaink

    Blaink Villager Member

    Messages:
    18
    Likes Received:
    0
    First Language:
    Enlgish
    Primarily Uses:
    RMMV
    Thanks for the quick response, Andar!

    So you're saying what I'm trying to do is essentially impossible for someone like me who knows nothing about Java script?

    Here's what I found on how to use script instead of a plugin command:

    var aliasPluginCommand = Game_Interpreter.prototype.pluginCommand;

    Game_Interpreter.prototype.pluginCommand = function(command, args) {
    aliasPluginCommand.call(this, command, args);
    if (command === 'plugincommandtextname') {
    dostuff(args);
    }
    };

    This doesn't mean anything to me... I've tried to deconstruct it, referencing SumRndmDde's code, but I just can't wrap my brain around it. I also found this website and tried to follow it, but failed again. https://rpgmakermv.co/threads/scripting-how-to-call-a-plugin-command-in-script.3307/

    Any guidance would be incredibly appreciated!

    Thank you!
     
    #3
  4. Andar

    Andar Veteran Veteran

    Messages:
    28,002
    Likes Received:
    6,327
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    it can be done, but as you realised yourself the person doing that needs to be able to read the code.

    In your example the next step would be to search for "dostuff(args)", because that would be the place where the command gets executed, and where the arguments of the plugin command are turned into scriptcode.
     
    #4
    Blaink likes this.
  5. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    That author is a member of this forum, and he probably has a thread here for the plugin. Why don't you just ask him if he can make it accept variables (or do an evaluation of the arguments)?
     
    #5
    Blaink likes this.
  6. Blaink

    Blaink Villager Member

    Messages:
    18
    Likes Received:
    0
    First Language:
    Enlgish
    Primarily Uses:
    RMMV
    @SumRndmDde, is there any way you could help me with this? I did a quick search of the forum for a thread dedicated to this plugin, but I didn't find one (I also checked the youtube thread for this plugin for any leads).
     
    #6
  7. Naveed

    Naveed Veteran Veteran

    Messages:
    314
    Likes Received:
    143
    First Language:
    English
    Primarily Uses:
    RMMV
    Well, you can instead use the script command directly to do what the plugin command would do.
    Use the following script call:

    Code:
    var id = $gameVariables.value(1);
    var currentIndex = $gameSystem.copyIndex;
    
    $gameParty.addActor(_.createCopy(id).id);
    
    $gameActors.actor(currentIndex).setup(currentIndex);
    
    $gameVariables.setValue(4, currentIndex);
    
     
    #7
    Blaink likes this.
  8. Blaink

    Blaink Villager Member

    Messages:
    18
    Likes Received:
    0
    First Language:
    Enlgish
    Primarily Uses:
    RMMV
    Thank you so much Naveed! I will try this out
     
    #8
  9. Blaink

    Blaink Villager Member

    Messages:
    18
    Likes Received:
    0
    First Language:
    Enlgish
    Primarily Uses:
    RMMV
    When I use this script, i get the error: "_ is undefined" do I need to replace "_" with something else?
     
    #9
  10. Blaink

    Blaink Villager Member

    Messages:
    18
    Likes Received:
    0
    First Language:
    Enlgish
    Primarily Uses:
    RMMV
    Does anyone have any additional opinions on this? I'm still trying to figure it out.
     
    #10
  11. Clock Out

    Clock Out Veteran Veteran

    Messages:
    92
    Likes Received:
    44
    First Language:
    English
    Primarily Uses:
    RMMV
    Try SRD.CopyActor.createCopy([your id here]);
     
    #11
    Blaink likes this.
  12. SumRndmDde

    SumRndmDde Follower of RNGesus Veteran

    Messages:
    224
    Likes Received:
    409
    Location:
    an alternate dimension.
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey, sorry for the late reply, but I made a plugin just for this kind of thing!
    First, install this plugin: http://sumrndm.site/plugin-command-evals/

    Then, within a plugin command, replace one of the parameters with ${ eval-here }
    Replace "eval-here" with a JavaScript eval.

    For example, for your issue, you would need to do:
    Code:
    CopyActor ${ $gameVariables.value(1) } 4
    
    The "${ $gameVariables.value(1) }" is the evaluated and the resulting value replaces it once the command is parsed in other plugins.
     
    #12
    Blaink and Kino like this.
  13. Blaink

    Blaink Villager Member

    Messages:
    18
    Likes Received:
    0
    First Language:
    Enlgish
    Primarily Uses:
    RMMV
    Thank you! Fantastic tutorials and plugins, btw
     
    #13

Share This Page