Thread: [PI/Any] Math Command

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 [PI/Any] Math Command 
    Registered Member
    Uavix's Avatar
    Join Date
    Apr 2011
    Posts
    360
    Thanks given
    72
    Thanks received
    173
    Rep Power
    117

    A friend of mine has a server, and his players wanted a math command. So I wrote this up relatively quick for him and though I would release to anyone who wants to use it. It's pretty neat.

    In your Misc class add this at the top:
    Code:
    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    Then somewhere else in the class add:
    Code:
    	private static ScriptEngineManager manager = new ScriptEngineManager();
    	private static ScriptEngine engine = manager.getEngineByName("JavaScript");
    	
    	public static int parse(String text){
    		try{
    		Double d = (Double) engine.eval(text);
    		return d.intValue();
    		}catch(Exception e){
    			throw new NumberFormatException(e.getLocalizedMessage());
    		}
    	}
    Then in your Commands class add:
    Code:
    	if(playerCommand.startsWith("math")){
    		String expression = playerCommand.substring(playerCommand.indexOf(' ') + 1);
    		c.sendMessage(expression + " = " + Misc.parse(expression));
    	}
    Thanks Matt123337 for the improved code above ^
    And you are done

    Quote Originally Posted by Blood View Post
    im 9 lol I can't get a job
    Rune-Server Userbase ^


    Vault proving what we have all known all along: he is a 9faggot.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Donator

    Join Date
    Jan 2011
    Posts
    54
    Thanks given
    4
    Thanks received
    23
    Rep Power
    35
    This is kinda neat, I'll put it in my server
    Reply With Quote  
     

  4. #3  
    Respected Member

    Revil's Avatar
    Join Date
    Nov 2010
    Age
    27
    Posts
    4,883
    Thanks given
    3,717
    Thanks received
    2,233
    Rep Power
    5000
    Cool
    Reply With Quote  
     

  5. #4  
    Registered Member
    Join Date
    Feb 2012
    Posts
    383
    Thanks given
    72
    Thanks received
    43
    Rep Power
    15
    Whats it do exactly?
    Reply With Quote  
     

  6. #5  
    Registered Member
    jordan641's Avatar
    Join Date
    Apr 2010
    Posts
    1,809
    Thanks given
    70
    Thanks received
    128
    Rep Power
    189
    Cute
    Reply With Quote  
     

  7. #6  
    Registered Member
    Uavix's Avatar
    Join Date
    Apr 2011
    Posts
    360
    Thanks given
    72
    Thanks received
    173
    Rep Power
    117
    Quote Originally Posted by Big D View Post
    Whats it do exactly?
    You could do something like: ::math ((4*3)+8)/2 in-game and get the answer; just sort of something fun to add.

    Quote Originally Posted by Blood View Post
    im 9 lol I can't get a job
    Rune-Server Userbase ^


    Vault proving what we have all known all along: he is a 9faggot.
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Feb 2012
    Posts
    383
    Thanks given
    72
    Thanks received
    43
    Rep Power
    15
    Quote Originally Posted by Kurt Cobain View Post
    You could do something like: ::math ((4*3)+8)/2 in-game and get the answer; just sort of something fun to add.
    Sick lol
    Reply With Quote  
     

  9. #8  
    Banned

    Join Date
    Mar 2011
    Posts
    4,064
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by Kurt Cobain View Post
    You could do something like: ::math ((4*3)+8)/2 in-game and get the answer; just sort of something fun to add.
    Shit, I got something like that on my komputair, really magical aint it:



    Reply With Quote  
     

  10. #9  
    Registered Member
    Uavix's Avatar
    Join Date
    Apr 2011
    Posts
    360
    Thanks given
    72
    Thanks received
    173
    Rep Power
    117
    Quote Originally Posted by relex lawl View Post
    Shit, I got something like that on my komputair, really magical aint it:



    It's just something cool/weird/fun to add; I never made any claims about this being magical, hard to do, or amazing. I simply said it was for fun. Don't like it, don't use it.

    Quote Originally Posted by Blood View Post
    im 9 lol I can't get a job
    Rune-Server Userbase ^


    Vault proving what we have all known all along: he is a 9faggot.
    Reply With Quote  
     

  11. #10  
    Registered Member Falco Fury's Avatar
    Join Date
    Jun 2010
    Posts
    118
    Thanks given
    440
    Thanks received
    14
    Rep Power
    18
    Good job. Could you please release a command that helps to correct a players spelling mistakes?
    Reply With Quote  
     

  12. Thankful users:


Page 1 of 2 12 LastLast

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. Need help in math ! :)
    By Programmer Jeff in forum Homework
    Replies: 2
    Last Post: 02-11-2011, 11:34 PM
  2. Its new math.
    By 2ndOfMay in forum Humor
    Replies: 4
    Last Post: 08-12-2009, 06:27 AM
  3. Math help!
    By Tzar in forum Homework
    Replies: 2
    Last Post: 01-28-2009, 02:16 AM
  4. Math help again..
    By Tzar in forum Homework
    Replies: 7
    Last Post: 12-13-2008, 07:01 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
  •