Thread: 55x2 NPC

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 55x2 NPC 
    Registered Member anaxonda's Avatar
    Join Date
    Jan 2017
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    11
    I'm trying to create an NPC in my 317 rsps that will function as follows:

    player uses item on NPC.

    NPC generates a number between 1-100.

    If 55 or over the item gets doubled.

    if 54 or under the item gets taken.

    ----------------------------------------------------------------------------------------


    I am pretty new to working with java, but i can make the system to generate the numbers, and say you win, you lose, with the roll outcome.

    I would however, appreciate a little help in figuring out how to add that to my npc and actually get him to double or take the item.

    Thanks anyone who helps in advance.
    I love you. - Dizzy Rascal
    Reply With Quote  
     

  2. #2  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    @handleItemOnNPC method or whatever it is called..
    Code:
    NPC npc & Item item should already be carried on by the method arguments so those are not necessary to be defined.
    int random = (int)(Math.random() * 100);
    if (random < 55) {
    player.getInventory().removeItem(item);
    player.sendMessage("You've lost..");
    } else {
    player.getInventory().addItem(item);
    player.sendMessage("You've won.");
    }
    That's honestly all there is to it. Of course I left out all checks, proper messaging, syntaxes etc. Just wrote this to give an idea how to pull this off.
    Reply With Quote  
     

  3. #3  
    Registered Member anaxonda's Avatar
    Join Date
    Jan 2017
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    11
    Cheers again mate!
    This is what i had on my own so, almost...
    Code:
    int random = (int) (Math.random()*100);
    		System.out.println(random);
    		if (random > 55) player.sendMessage("You win!");
    		if (random < 55) player.sendMessage("You Lose!");
    		
    	}

    Pretty blatant to see the parts i needed to add now i looked. lol.
    I love you. - Dizzy Rascal
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Sep 2014
    Posts
    300
    Thanks given
    122
    Thanks received
    91
    Rep Power
    158
    Code:
              int random = (int) (Math.random()*100);
    		if (random > 55)  {
                          player.sendMessage("You win!");
                          player.addInventory().addItem(item, item.getAmount() * 2);
                   } else if (random < 55) {
                             player.sendMessage("You Lose!");
    		         player.getInventory().deleteItem(item);
    	}
    }
    Have fun. I hope this is what you needed.
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Sep 2014
    Posts
    300
    Thanks given
    122
    Thanks received
    91
    Rep Power
    158
    Quote Originally Posted by Ultimate_ View Post
    what about if the number actually is 55 ?
    You can use this if you want 55 to be a lose:
    Code:
              int random = (int) (Math.random()*100);
    		if (random > 55)  {
                          player.sendMessage("You win!");
                          player.addInventory().addItem(item, item.getAmount() * 2);
                   } else if (random <= 55) {
                             player.sendMessage("You Lose!");
    		         player.getInventory().deleteItem(item);
    	}
    }
    Or this if you want it to be a win:
    Code:
              int random = (int) (Math.random()*100);
    		if (random >= 55)  {
                          player.sendMessage("You win!");
                          player.addInventory().addItem(item, item.getAmount() * 2);
                   } else if (random < 55) {
                             player.sendMessage("You Lose!");
    		         player.getInventory().deleteItem(item);
    	}
    }
    Reply With Quote  
     

  6. #6  
    Registered Member anaxonda's Avatar
    Join Date
    Jan 2017
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Banners View Post
    You can use this if you want 55 to be a lose:
    Code:
              int random = (int) (Math.random()*100);
    		if (random > 55)  {
                          player.sendMessage("You win!");
                          player.addInventory().addItem(item, item.getAmount() * 2);
                   } else if (random <= 55) {
                             player.sendMessage("You Lose!");
    		         player.getInventory().deleteItem(item);
    	}
    }
    Or this if you want it to be a win:
    Code:
              int random = (int) (Math.random()*100);
    		if (random >= 55)  {
                          player.sendMessage("You win!");
                          player.addInventory().addItem(item, item.getAmount() * 2);
                   } else if (random < 55) {
                             player.sendMessage("You Lose!");
    		         player.getInventory().deleteItem(item);
    	}
    }


    okay so, with me poking around and trying to get it all to work, i have come up with this:


    Code:
     if (random >= 55) {
                          c.getDH().sendPlayerChat1("I won!");
                          c.getItems().addItem(itemId, +1);
                   } else if (random < 55) {
                	   c.getDH().sendPlayerChat1("I Lose!");
                	   c.getItems().deleteItem(itemId, 1);
    The part where it adds item "+1" I get an error when making that "* 2" "*2" and everything of the sort.
    Just need that sorted and then everything will work.

    I can gamble, lose and win, i just need it to double the item not add one.
    I love you. - Dizzy Rascal
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Sep 2014
    Posts
    300
    Thanks given
    122
    Thanks received
    91
    Rep Power
    158
    Quote Originally Posted by anaxonda View Post
    okay so, with me poking around and trying to get it all to work, i have come up with this:


    Code:
     if (random >= 55) {
                          c.getDH().sendPlayerChat1("I won!");
                          c.getItems().addItem(itemId, +1);
                   } else if (random < 55) {
                	   c.getDH().sendPlayerChat1("I Lose!");
                	   c.getItems().deleteItem(itemId, 1);
    The part where it adds item "+1" I get an error when making that "* 2" "*2" and everything of the sort.
    Just need that sorted and then everything will work.

    I can gamble, lose and win, i just need it to double the item not add one.
    Try using *=, If that doesnt work, then try linking it to an int. Im not sure in your case since ive never developed a 317 RSPS.

    For the linking to an int, this is an example.
    Code:
    int amount = itemId.getAmount();
    int k = 2;
    int doubledAmount = amount * k;
    then replace c.getItems().addItem(itemId, +1); with c.getItems().addItem(itemId, doubledAmount);
    Reply With Quote  
     

  8. #8  
    Registered Member anaxonda's Avatar
    Join Date
    Jan 2017
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    11
    Ill give it a go, cheers.

    Quote Originally Posted by Banners View Post
    Try using *=, If that doesnt work, then try linking it to an int. Im not sure in your case since ive never developed a 317 RSPS.

    For the linking to an int, this is an example.
    Code:
    int amount = itemId.getAmount();
    int k = 2;
    int doubledAmount = amount * k;
    then replace c.getItems().addItem(itemId, +1); with c.getItems().addItem(itemId, doubledAmount);
    ---------------------------------------------------------------------------------------------------------------------------------

    Getting "Cannot invoke getAmount() on the primitive type int"

    thats the only error
    I love you. - Dizzy Rascal
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Aug 2014
    Posts
    259
    Thanks given
    2
    Thanks received
    6
    Rep Power
    11
    Quote Originally Posted by Kris View Post
    @handleItemOnNPC method or whatever it is called..
    Code:
    NPC npc & Item item should already be carried on by the method arguments so those are not necessary to be defined.
    int random = (int)(Math.random() * 100);
    if (random < 55) {
    player.getInventory().removeItem(item);
    player.sendMessage("You've lost..");
    } else {
    player.getInventory().addItem(item);
    player.sendMessage("You've won.");
    }
    That's honestly all there is to it. Of course I left out all checks, proper messaging, syntaxes etc. Just wrote this to give an idea how to pull this off.
    put on npchandler.java right?
    Owner of ThamenX
    Reply With Quote  
     

  10. #10  
    Registered Member anaxonda's Avatar
    Join Date
    Jan 2017
    Posts
    28
    Thanks given
    0
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by blaxe View Post
    put on npchandler.java right?

    No this is in ItemOnNpc.java so that all npc's have the feature whenever a player uses an item on any.

    it's all in the right place, and it all works fine. I just cant get it to.. as an example:

    i use 40 noted shark and win; i still only get 1 extra back
    and lose; i still only lose 1 of the items.

    I want it so that it takes the entire 40 shark, or gives 40 shark extra. I just can't get it to do that. the *2 * 2 doesnt work, and i cant set up the int for "int amount = itemId.getAmount()" that part because it says the get.Amount part is wrong. So i can't use ints to make my own double int.


    all of my relevent code looks like this:

    Code:
     int random = (int) (Math.random() * 100);
                int amount = item.getAmount();
    		int a = 2;
    		int dx2 = amount * a;
                  
                    UseItem.ItemonNpc(c, itemId, npcId, slot);
    		if (random >= 55) {
                          c.getDH().sendPlayerChat1("I won!");
                          c.getItems().addItem(itemId, dx2);
                   } else if (random < 55) {
                	   c.getDH().sendPlayerChat1("I Lost!");
                	   c.getItems().deleteItem(itemId, dx2);
    I love you. - Dizzy Rascal
    Reply With Quote  
     

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. [tut]Poison Npcs (With green splat)..
    By Santa Clause in forum Tutorials
    Replies: 9
    Last Post: 05-21-2007, 03:55 AM
  2. All Lists - item, object and NPC
    By purepkownage in forum Tools
    Replies: 2
    Last Post: 05-11-2007, 09:46 AM
  3. NPC Magic Distance Bug Fix
    By Zekkalkan in forum Tutorials
    Replies: 5
    Last Post: 05-06-2007, 07:21 PM
  4. Replies: 8
    Last Post: 05-04-2007, 09:52 PM
  5. Replies: 4
    Last Post: 05-03-2007, 03:57 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •