Thread: [Basics]How to use Hyperions Javascript Plugin System

Results 1 to 4 of 4
  1. #1 [Basics]How to use Hyperions Javascript Plugin System 
    Java Developer

    Celty's Avatar
    Join Date
    Aug 2013
    Age
    27
    Posts
    355
    Thanks given
    94
    Thanks received
    91
    Rep Power
    173
    I recently learned how to use this and its very helpful so lets get started.

    1. Locating The Script Folder
    ___
    First thing you need to know is the location of the scripts folder.
    Code:
    ./data/scripts/
    Within this folder you will find a plugin Graham placed in there when he released the source of course it isn't invoked and its not really useful it just a hello world plugin. I suggest you delete it as it isn't needed.

    2. The Plugins Bare Format
    ___
    This is how you will set up a plugin using a Javascript function which is similar to a void.
    Code:
    function myPlugin() {
    	
    }
    3. Importing Java Classes
    ___
    To import a java class to use in your plugin you will need to use "importClass(#classPath.#className);" which you place at the top of your class.

    Ex.
    Code:
    importClass(org.hyperion.rs2.model.player.Player);
    
    function myPlugin() {
    	
    }
    4. Using Parameters And Class Methods.
    ___
    Okay so this part is a little different from java but not much it is still pretty simple. First off parameters say your want to create a plugin for a player action you would need to import the Player class and add the Player parameter which will look like this.
    Code:
    importClass(org.hyperion.rs2.model.player.Player);
    
    function myPlugin(Player) {
    	
    }
    If you take notice unlike in java parameters don't have labels which means you will only be using the class name. Now lets call upon the the "sendMessage(String message)" packet for this plugin.
    Code:
    importClass(org.hyperion.rs2.model.player.Player);
    
    function myPlugin(Player) {
    	Player.getActionSender().sendMessage("You just triggered a plugin.");
    }
    Pretty simple : D.

    5. Statements
    ___
    Using simple statements are just as easy as using them in java. So for this instance we will be making a plugin that will let a player with a certain combat level get some gold upon logging in.
    Code:
    importClass(org.hyperion.rs2.model.player.Player);
    importClass(org.hyperion.rs2.model.item.Item);
    
    function myPlugin(Player) {
    	if(Player.getSkills().getCombatLevel() > 5) {
    		Player.getInventory().add(new Item(995, 100));
    	} else {
    		Player.getActionSender().sendMessage("You aren't a high enough level to obtain a login gold bonus.");
    	}
    }
    And seeing as you used the Item type you will need to import that class as well.

    6. Invoking your script.
    ___
    The process of invoking your plugin is what will make it run. Lets break down the invoke method.
    Code:
    	public void invoke(String identifier, Object... args) {
    		Invocable invEngine = (Invocable) jsEngine;
    		try {
    			invEngine.invokeFunction(identifier, args);
    		} catch (NoSuchMethodException ex) {
    			logger.log(Level.WARNING, "No such method: " + identifier, ex);
    		} catch (ScriptException ex) {
    			logger.log(Level.WARNING, "ScriptException thrown!", ex);
    		}
    	}
    When declaring the method you will need to first fill in the String identifier which is the name of the javascript function() so in this particular instance it would be "myPlugin".
    Code:
    ScriptManager.getScriptManager().invoke("myPlugin", Object... args);
    Now we need to add are arguments or the parameters you used. In this instance we used "Player" so we need to create an instance of "Player player" in the java class you are declaring the invoke method and add that instance label to the args parameter of the invoke method like so.
    Code:
    ScriptManager.getScriptManager().invoke("myPlugin", player);
    Now when you use more then one argument you can simple add a comma after the first delared argument so on and so fourth like so.
    Code:
    ScriptManager.getScriptManager().invoke("myPlugin", player, item);
    with

    Code:
    importClass(org.hyperion.rs2.model.player.Player);
    importClass(org.hyperion.rs2.model.item.Item);
    
    function myPlugin(Player, Item) {
    	if(Player.getSkills().getCombatLevel() > 5) {
    		Player.getInventory().add(new Item(995, 100));
    	} else {
    		Player.getActionSender().sendMessage("You aren't a high enough level to obtain a login gold bonus.");
    	}
    }
    These are just the basics I'm still learning my way around I though this may be helpful to anyone who would like to start using the plugin system or didn't have an idea of where to start.
    Watched Anime List

    A Certain Magical Index A Certain Scientific Railgun A Certain Scientific Railgun S Sword Art Online Dragon Ball Dragon Ball Z Dragon Ball GT Deadman Wounderland Elfen Lied Eureka Seven Eureka Seven AO
    K-ON Clannad Clannad After Story Baka & Test Ouran Host Club One Peice InuYasha Kaze No Stigma Okami-San & Her Seven Companions Accel World Angel Beats
    Guilty Crown Cowboy Bebop Full Metal Alchemist Full Metal Alchemist: Brotherhood Soul Eater Madoka Magica Fairy Tail Yu Yu Hakusho Chrome Shelled Regios
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jan 2014
    Posts
    311
    Thanks given
    115
    Thanks received
    57
    Rep Power
    0
    Nice job
    Spoiler for Charlie Sheen ft Lil B:

    Every derep I ever got was from a butthurt bitch I shut down.
    Reply With Quote  
     

  3. #3  
    Banned Market Banned Market Banned


    Join Date
    Jan 2011
    Age
    23
    Posts
    3,115
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    thanks i guess lol somone could have just googled tutorials on the basics of javascript though
    Reply With Quote  
     

  4. #4  
    Theory Wins?
    Greyfield's Avatar
    Join Date
    Nov 2008
    Age
    29
    Posts
    1,585
    Thanks given
    61
    Thanks received
    265
    Rep Power
    310
    It is not a plugin system. If it was, you wouldn't be directly invoking the script.



    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 12
    Last Post: 10-27-2014, 02:07 AM
  2. Replies: 2
    Last Post: 09-13-2012, 01:10 AM
  3. [562]RS2HD: How to use the Npc Dialogue System
    By xJames in forum Tutorials
    Replies: 11
    Last Post: 03-21-2012, 04:13 PM
  4. [Renamed] basic text input prompt tut [how to use]
    By Robin Spud in forum Tutorials
    Replies: 9
    Last Post: 08-18-2011, 07:45 AM
  5. Replies: 2
    Last Post: 05-23-2009, 11:35 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •