Thread: PI Global object

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 PI Global object 
    Donator

    Chief Sosa's Avatar
    Join Date
    Jun 2012
    Posts
    1,163
    Thanks given
    49
    Thanks received
    234
    Rep Power
    83
    Hello, I am in need of some help on making these flowers show up for all players, I can't figure out how to if anyone can help will rep and thank.


    The Code i'm using
    Code:
    package server.model.content;
    
    import server.clip.region.Region;
    import server.model.players.Client;
    import server.util.Misc;
    
    
    public class Flowers {
        
         /**
          * Constants & boolean checker
          */
         private final int FLOWER_IDS[] = {2980,2981,2982,2983,2984,2985,2986,2987,2988};
         
         /**
          * Checks weather user is currently interacting with flower
          */
         public boolean clientFlowering = false;
         
         /**
          * Stores temporary variables for each new instance of flower planted
          */
         private int lastObject;
         
         /**
          * algorithm decides which flower to give. 
          * @param flower
          * @return 
          */
         private static int flowerDecoder(final int flower){
    		 int modifier = flower - 2980;
    		 return (modifier + 2460);
         }
        
         /**
          * Constructor creates the place flower event
          * @param c 
          */
         public Flowers(Client c){
             executeAction(c);
         }
         
         /**
          * Main block, Spawns the object & starts animation. Moves player to the side Clipped
          * @param c 
          */
         private void executeAction(Client c){
             int newFlower = getRandom();
             updateConstants(newFlower, c);
             c.getPA().checkObjectSpawn(newFlower, c.getX(), c.getY(), 1, 10);
             deleteSeeds(c);
             sendOptions(c);
             this.clientFlowering = true;
             moveOneStep(c);
         }
         
         /**
          * Handles movement direction.
          * @param c 
          */
         private static void moveOneStep(Client c){
             if (Region.getClipping(c.getX() - 1, c.getY(), c.heightLevel, -1, 0)) {
    		   c.getPA().walkTo(-1, 0);
    		  } else if (Region.getClipping(c.getX() + 1, c.getY(), c.heightLevel, 1, 0)) {
    		   c.getPA().walkTo(1, 0);
    		  } else if (Region.getClipping(c.getX(), c.getY() - 1, c.heightLevel, 0, -1)) {
    		   c.getPA().walkTo(0, -1);
    		  } else if (Region.getClipping(c.getX(), c.getY() + 1, c.heightLevel, 0, 1)) {
    		   c.getPA().walkTo(0, 1);
    		  }
         }
         
         /**
          * Selects a random flower ID
          * @return 
          */
         private int getRandom(){
             return (FLOWER_IDS[Misc.random(FLOWER_IDS.length-1)]);
         }
         
         /**
          * Sends the client an option to handle flowers
          * @param c 
          */
         private void sendOptions(Client c){
             c.getDH().sendOption2("Leave Flowers", "Harvest Flowers");
         }
         
         /**
          * Removes the seeds from invent
          * @param c 
          */
         private static void deleteSeeds(Client c){
             c.getItems().deleteItem(299, 1);
         }
         
         private void updateConstants(int objectType, Client c){
             lastObject = objectType;
         }
         
         /**
          * Method harvests flower from ground 
          * @param c
          * @param object
          * @param oX
          * @param oY 
          */
         public void harvestFlower(Client c, int object){
             c.getItems().addItem(flowerDecoder(object), 1);
             c.startAnimation(827);
             c.getPA().checkObjectSpawn(-1, c.getX()+1, c.getY(), 1, 10);
         }
         
         /**
          * Sends the option action
          * @param option 
          */
         public void handleOptions(int option, Client c){
             if (option == 0)
                 return;
             else
                 harvestFlower(c, lastObject);
             clientFlowering = false;
         }
    }
    and then in ClickItem.java just make a boolean isFlower, and if returned true, use this
    Code:
    new Flowers(c);
    of course import it.

    Reply With Quote  
     

  2. #2  
    Banned PI Global object Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Code:
         private void executeAction(Client c){
             int newFlower = getRandom();
             updateConstants(newFlower, c);
    
             for(Player p : PlayerHandler.players) {
                  if(p != null) {
                       ((Client)p).getPA().checkObjectSpawn(newFlower, c.getX(), c.getY(), 1, 10);
                  }
             }
    
             deleteSeeds(c);
             sendOptions(c);
             this.clientFlowering = true;
             moveOneStep(c);
         }
    Reply With Quote  
     

  3. #3  
    Donator

    Chief Sosa's Avatar
    Join Date
    Jun 2012
    Posts
    1,163
    Thanks given
    49
    Thanks received
    234
    Rep Power
    83
    Quote Originally Posted by lare96 View Post
    Code:
         private void executeAction(Client c){
             int newFlower = getRandom();
             updateConstants(newFlower, c);
    
             for(Player p : PlayerHandler.players) {
                  if(p != null) {
                       ((Client)p).getPA().checkObjectSpawn(newFlower, c.getX(), c.getY(), 1, 10);
                  }
             }
    
             deleteSeeds(c);
             sendOptions(c);
             this.clientFlowering = true;
             moveOneStep(c);
         }
    Ffs thanks, I was editing harvest flower Lmfao. Thank you very much

    Reply With Quote  
     

  4. #4  
    Banned PI Global object Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Quote Originally Posted by Lean. View Post
    Ffs thanks, I was editing harvest flower Lmfao. Thank you very much
    You'll need to do the same thing for harvestFlower if you want the flower to be removed for everyone, as well as anywhere else an object is placed/removed.
    Reply With Quote  
     

  5. #5  
    Donator

    Chief Sosa's Avatar
    Join Date
    Jun 2012
    Posts
    1,163
    Thanks given
    49
    Thanks received
    234
    Rep Power
    83
    Quote Originally Posted by lare96 View Post
    You'll need to do the same thing for harvestFlower if you want the flower to be removed for everyone, as well as anywhere else an object is placed/removed.
    Ok thanks for the help anything else i should know about ?

    Reply With Quote  
     

  6. #6  
    Enthimia Founder
    Ap4che's Avatar
    Join Date
    Jan 2014
    Posts
    180
    Thanks given
    0
    Thanks received
    65
    Rep Power
    30
    Quote Originally Posted by Lean. View Post
    Ok thanks for the help anything else i should know about ?
    Judging on what he told you, that's all you need to know.
    Reply With Quote  
     

  7. #7  
    Donator

    Chief Sosa's Avatar
    Join Date
    Jun 2012
    Posts
    1,163
    Thanks given
    49
    Thanks received
    234
    Rep Power
    83
    Quote Originally Posted by lare96 View Post
    You'll need to do the same thing for harvestFlower if you want the flower to be removed for everyone, as well as anywhere else an object is placed/removed.
    1 More thing, Why when i click harvest or leave flowers it will open up a shop?

    Reply With Quote  
     

  8. #8  
    Banned PI Global object Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Quote Originally Posted by Lean. View Post
    1 More thing, Why when i click harvest or leave flowers it will open up a shop?
    check your object clicking packets to see what happens when the flower object is clicked
    Reply With Quote  
     

  9. #9  
    Donator

    Chief Sosa's Avatar
    Join Date
    Jun 2012
    Posts
    1,163
    Thanks given
    49
    Thanks received
    234
    Rep Power
    83
    Quote Originally Posted by lare96 View Post
    check your object clicking packets to see what happens when the flower object is clicked
    I don't understand sorry what ?

    Reply With Quote  
     

  10. #10  
    Banned PI Global object Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Quote Originally Posted by Lean. View Post
    I don't understand sorry what ?
    check the same place that you would go to if you wanted to make it so when you click on an object something happens, it's usually actionhandler for project insanity
    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. [PI] How to delete global objects [/PI]
    By Austin_ in forum Snippets
    Replies: 19
    Last Post: 09-18-2013, 09:01 PM
  2. [PI] global-objects.cfg
    By thesancezzz in forum Help
    Replies: 0
    Last Post: 12-04-2011, 01:12 PM
  3. [pi] global objects
    By hyt45 in forum Help
    Replies: 5
    Last Post: 05-04-2011, 06:36 PM
  4. [REP][PI] Moving Global Objects [PI][REP]
    By Cal_Short in forum Help
    Replies: 0
    Last Post: 08-19-2010, 05:20 PM
  5. [PI] Global Objects
    By Mrthunder23 in forum Help
    Replies: 5
    Last Post: 06-27-2010, 01:21 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
  •