Thread: Location and Timer help ( for LOBBY)

Results 1 to 7 of 7
  1. #1 Location and Timer help ( for LOBBY) 
    Registered Member Hyped's Avatar
    Join Date
    Dec 2016
    Posts
    171
    Thanks given
    21
    Thanks received
    7
    Rep Power
    4
    Hey everyone,

    I got a question, im making a lobby for my minigame this is what i got so far:
    Code:
    public class Lobby {
    
    	static int GameTimer = 10;
    	static int Minplayers = 2;
    	static int MaxPlayers = 10;
    	static int PlayersInLobby = 0;
    	
    	public static void addPlayer(Player player) {
    		if(player.getLocation() == Location.LOBBY) {
    			player.getPacketSender().sendMessage("Lobby entered");
    			if(PlayersInLobby == MaxPlayers) {
    				while(PlayersInLobby <= Minplayers && GameTimer > -1) {
    					GameTimer--;
    					if (GameTimer == 0) {
    						player.moveTo(new Position(3090, 3520));
    						player.getPacketSender().sendMessage("Test.");
    					//	InitializeGame();
    					}
    				}		
    			}
    		}
    	}
    As you can imagine it doesnt work at all. When entering the lobby i checked if i got registered with
    Code:
    player.getPacketSender().sendMessage("Lobby entered");
    . It doesnt give me a message. I also tested it with the timmer, same goed for when the timmer hit zero. It doesnt give me a message nor teleports me.

    Any help would be appreciated,

    Thanks for reading.

    Reginald
    learning, learning, learning, learning
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Feb 2017
    Posts
    113
    Thanks given
    23
    Thanks received
    29
    Rep Power
    16
    If it won't even give you the first "sendMessage" than my guess would be their is something wrong with your first "If" statement. Try commenting out the "if" statement. That will be the quickest way to see if there is something wrong with the whole method or if it is just that "If" statement.


    If it works without the "If" statement then...
    What does "player.getLocation" and "Location.Lobby" look like?


    Because your first "if" statement is:

    if(player.getLocation() == Location.LOBBY) { // do those check for a region or a specific coordinate?
    Attached image
    Attached image
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Alright, let's get some things straight. Whatever it is you're creating, I wouldn't make every variable static. Especially if you plan on making multiple instances of the .. whatever it is.; Even if not, I still wouldn't.

    The reason why you ain't getting that message is because player.getLocation() == Location.LOBBY can never equal true lol. You're comparing if two objects equal the same. They don't. The variables within may but the objects themselves don't. You can test this yourself, just put System.out.println(player.getLocation + " - " + Location.LOBBY); above the if-sentence there and you'll see, different objects. You'll either need to compare the variables or their hash.

    I'd personally use hash for comparing cause it'll keep the code cleaner and I'm pretty positive it's quite efficient.
    Code:
    	public int getTileHash() {
    		return y + (x << 14) + (plane << 28);
    	}
    This is the method for hash.
    Attached image
    Reply With Quote  
     

  5. Thankful user:


  6. #4  
    BIG OOF
    Awakening's Avatar
    Join Date
    May 2016
    Posts
    35
    Thanks given
    16
    Thanks received
    7
    Rep Power
    11
    Quote Originally Posted by Kris View Post
    Alright, let's get some things straight. Whatever it is you're creating, I wouldn't make every variable static. Especially if you plan on making multiple instances of the .. whatever it is.; Even if not, I still wouldn't.

    The reason why you ain't getting that message is because player.getLocation() == Location.LOBBY can never equal true lol. You're comparing if two objects equal the same. They don't. The variables within may but the objects themselves don't. You can test this yourself, just put System.out.println(player.getLocation + " - " + Location.LOBBY); above the if-sentence there and you'll see, different objects. You'll either need to compare the variables or their hash.

    I'd personally use hash for comparing cause it'll keep the code cleaner and I'm pretty positive it's quite efficient.
    Code:
    	public int getTileHash() {
    		return y + (x << 14) + (plane << 28);
    	}
    This is the method for hash.
    Mistake me if I'm wrong, buy you need something which stores the players within the mini-game?

    Hold game players:
    Code:
    public static Queue<Player> playersInGame = new ArrayDeque<Player>();
    Then you need a way of adding the player to the queue itself, which i'll leave you to figure out lol.
    Reply With Quote  
     

  7. Thankful user:


  8. #5  
    Registered Member Hyped's Avatar
    Join Date
    Dec 2016
    Posts
    171
    Thanks given
    21
    Thanks received
    7
    Rep Power
    4
    Quote Originally Posted by Catherby OS View Post
    If it won't even give you the first "sendMessage" than my guess would be their is something wrong with your first "If" statement. Try commenting out the "if" statement. That will be the quickest way to see if there is something wrong with the whole method or if it is just that "If" statement.


    If it works without the "If" statement then...
    What does "player.getLocation" and "Location.Lobby" look like?


    Because your first "if" statement is:

    if(player.getLocation() == Location.LOBBY) { // do those check for a region or a specific coordinate?
    Thanks for your reply, when i commented out the first if statement, there is nothing wrong with the code.
    The Location.LOBBY checks a region.

    Locations.java (for the lobby looks like this)
    [SPOIL]
    Code:
    		LOBBY(new int[]{3091, 3100, 3096, 3097, 3092, 3100}, new int[]{3507, 3513, 3510, 3512, 3512, 3507}, false, false, false, false, false, false) {
    		
    			@Override
    			public void process(Player p) {
    				//p.getPacketSender().sendMessage("You are in bounds.");
    				p.getDueling().process();
    				p.getPacketSender().sendInteractionOption("null", 1, false); //Remove challenge option
    					
    			}
    [/SPOIL]

    In different classes the following code does work
    Code:
    If(player.getLocation() == Location.LOBBY) {
     Example
    }
    When I tried to test the Lobbyclass code with
    Code:
    	public static void addPlayer(Player player) {
    		System.out.println(player.getLocation() + " - " + Location.LOBBY);
    		player.getPacketSender().sendMessage("Test.");
    	}
    It didnt gave me anything.

    So it has something to do with the Location.LOBBY check, not sure what the problem is.

    Quote Originally Posted by Kris View Post
    Alright, let's get some things straight. Whatever it is you're creating, I wouldn't make every variable static. Especially if you plan on making multiple instances of the .. whatever it is.; Even if not, I still wouldn't.

    The reason why you ain't getting that message is because player.getLocation() == Location.LOBBY can never equal true lol. You're comparing if two objects equal the same. They don't. The variables within may but the objects themselves don't. You can test this yourself, just put System.out.println(player.getLocation + " - " + Location.LOBBY); above the if-sentence there and you'll see, different objects. You'll either need to compare the variables or their hash.

    I'd personally use hash for comparing cause it'll keep the code cleaner and I'm pretty positive it's quite efficient.
    Code:
    	public int getTileHash() {
    		return y + (x << 14) + (plane << 28);
    	}
    This is the method for hash.
    Thanks for your post, When I want to check it for myself with System.out.println(player.getLocation + " - " + Location.LOBBY);. It didnt show anything it putted it like this:
    Spoiler for Code:
    Code:
    	public static void addPlayer(Player player) {
    		System.out.println(player.getLocation() + " - " + Location.LOBBY);
     		if(player.getLocation() == Location.LOBBY) {
    			player.getPacketSender().sendMessage("Lobby entered");
    			System.out.println(player.getLocation() + " - " + Location.LOBBY);
    			if(PlayersInLobby == MaxPlayers) {
    				while(PlayersInLobby <= Minplayers && GameTimer > -1) {
    					GameTimer--;
    					if (GameTimer == 0) {
    						player.moveTo(new Position(3090, 3520));
    						player.getPacketSender().sendMessage("Test.");
    					//	InitializeGame();
    					}
    				}		
    			}
    		}
    	}


    Did I use it wrong?

    Quote Originally Posted by Awakening View Post
    Mistake me if I'm wrong, buy you need something which stores the players within the mini-game?

    Hold game players:
    Code:
    public static Queue<Player> playersInGame = new ArrayDeque<Player>();
    Then you need a way of adding the player to the queue itself, which i'll leave you to figure out lol.
    Thanks for the post , yes I think so. I want the add the lobby step by step so I could understand and toubleshoot one step at a time.
    learning, learning, learning, learning
    Reply With Quote  
     

  9. #6  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    27
    Posts
    543
    Thanks given
    224
    Thanks received
    100
    Rep Power
    113
    Quote Originally Posted by reginaldrsps View Post
    Spoiler for Quote:
    Thanks for your reply, when i commented out the first if statement, there is nothing wrong with the code.
    The Location.LOBBY checks a region.

    Locations.java (for the lobby looks like this)
    [SPOIL]
    Code:
    		LOBBY(new int[]{3091, 3100, 3096, 3097, 3092, 3100}, new int[]{3507, 3513, 3510, 3512, 3512, 3507}, false, false, false, false, false, false) {
    		
    			@Override
    			public void process(Player p) {
    				//p.getPacketSender().sendMessage("You are in bounds.");
    				p.getDueling().process();
    				p.getPacketSender().sendInteractionOption("null", 1, false); //Remove challenge option
    					
    			}
    [/SPOIL]

    In different classes the following code does work
    Code:
    If(player.getLocation() == Location.LOBBY) {
     Example
    }
    When I tried to test the Lobbyclass code with
    Code:
    	public static void addPlayer(Player player) {
    		System.out.println(player.getLocation() + " - " + Location.LOBBY);
    		player.getPacketSender().sendMessage("Test.");
    	}
    It didnt gave me anything.

    So it has something to do with the Location.LOBBY check, not sure what the problem is.



    Thanks for your post, When I want to check it for myself with System.out.println(player.getLocation + " - " + Location.LOBBY);. It didnt show anything it putted it like this:
    Spoiler for Code:
    Code:
    	public static void addPlayer(Player player) {
    		System.out.println(player.getLocation() + " - " + Location.LOBBY);
     		if(player.getLocation() == Location.LOBBY) {
    			player.getPacketSender().sendMessage("Lobby entered");
    			System.out.println(player.getLocation() + " - " + Location.LOBBY);
    			if(PlayersInLobby == MaxPlayers) {
    				while(PlayersInLobby <= Minplayers && GameTimer > -1) {
    					GameTimer--;
    					if (GameTimer == 0) {
    						player.moveTo(new Position(3090, 3520));
    						player.getPacketSender().sendMessage("Test.");
    					//	InitializeGame();
    					}
    				}		
    			}
    		}
    	}


    Did I use it wrong?



    Thanks for the post , yes I think so. I want the add the lobby step by step so I could understand and toubleshoot one step at a time.
    Rid yourself of that Locations class, it's so clunky and improper.
    Tons of unnecessary skeletons used like abstracts, the entirety of how it is handled is just bad.

    Use this instead;
    Rs2-Server/Snippets - [Elvarg/OSRS Pk] Area

    Then do something with this, make it work.
    Just wrote it up quick for you, didn't really test or anything, sorry.

    Spoiler for Minigames:
    Code:
    package com.elvarg.world.content.minigames;
    
    public enum MinigameState {
    	NONE, LOBBY, IN_GAME, END_GAME;
    }
    Code:
    package com.elvarg.world.content.minigames;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.elvarg.world.entity.impl.player.Player;
    
    public enum Minigame {
    	PEST_CONTROL(new ArrayList<Player>());
    	
    	private final List<Player> gamePlayers;
    	
    	private Minigame(final List<Player> gamePlayers) {
    		this.gamePlayers = gamePlayers;
    	}
    	public List<Player> getGamePlayers() {
    		return gamePlayers;
    	}
    }
    Code:
    package com.elvarg.world.content.minigames;
    
    import com.elvarg.world.entity.impl.player.Player;
    import com.elvarg.world.model.SecondsTimer;
    
    public class MinigameHandler {
    	
    	/**
    	 * The player accessing the handler
    	 */
    	private final Player player;
    	
    	/**
    	 * Constructs the MinigameHandler with the parameter @player
    	 * 
    	 * @param player
    	 * 		The player accessing the handler
    	 */
    	public MinigameHandler(final Player player) {
    		this.player = player;
    	}
    	
    	/**
    	 * A timer in seconds used for a count down
    	 */
    	public static SecondsTimer gameTimer = new SecondsTimer();
    	
    	/**
    	 * The minimum players allowed in a minigame
    	 */
    	public static final int MINIMUM_PLAYERS = 2;
    	
    	/**
    	 * The maximum players allowed in a minigame
    	 */
    	public static final int MAXIMUM_PLAYERS = 10;
    	
    	/**
    	 * Adds a player to the @type.gamePlayers list
    	 * 
    	 * @param type
    	 * 		The minigame type for the player
    	 */
    	public void addPlayer(Minigame minigame) {
    		
    		if(minigame.getGamePlayers().size() == MAXIMUM_PLAYERS)
    			return;
    		
    		if (!minigame.getGamePlayers().contains(player))
    			minigame.getGamePlayers().add(player);
    		
    		if (player.getGameState().equals(MinigameState.NONE))
    			player.setGameState(MinigameState.LOBBY);
    		
    		if (minigame.getGamePlayers().size() == MINIMUM_PLAYERS) {
    			while(minigame.getGamePlayers().size() <= MINIMUM_PLAYERS && gameTimer.secondsRemaining() > 0) {
    				gameTimer.start(10); //10 Seconds, set to desired timer.
    			}
    		}
    		player.setGameType(minigame);
    		player.getPacketSender().sendMessage("Lobby entered");
    	}
    	public void removePlayer(Minigame minigame) {
    		for (Player players : minigame.getGamePlayers()) {
    			if (minigame.getGamePlayers().contains(players))
    				minigame.getGamePlayers().remove(players);
    		}
    	}
    }
    Code:
    package com.elvarg.world.content.minigames.PestControl;
    
    import com.elvarg.world.content.area.Areas;
    import com.elvarg.world.content.minigames.MinigameHandler;
    import com.elvarg.world.content.minigames.MinigameState;
    import com.elvarg.world.content.minigames.Minigame;
    import com.elvarg.world.entity.impl.player.Player;
    import com.elvarg.world.model.teleportation.TeleportHandler;
    import com.elvarg.world.model.teleportation.TeleportType;
    
    public class PestControl {
    	
    	public void joinLobby(Player player) {
    		if(Areas.SOME_MINIGAME_LOBBY.inBounds(player.getPosition().getX(), player.getPosition().getY())) {
    			
    			player.handleMinigames().addPlayer(Minigame.PEST_CONTROL);
    			
    			if (MinigameHandler.gameTimer.finished() && player.getMinigame().equals(Minigame.PEST_CONTROL)) {
    				TeleportHandler.teleport(player, Areas.SOME_MINIGAME_LOBBY.getTele(), TeleportType.NORMAL);
    				player.getPacketSender().sendMessage("Test.");
    				
    				for (Player players : player.getMinigame().getGamePlayers())
    					players.setGameState(MinigameState.IN_GAME);
    			}
    		}
    	}
    }
    There's probably a better way of doing it, idk

    Spoiler for Revy is perfect:
    Reply With Quote  
     

  10. Thankful user:


  11. #7  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Quote Originally Posted by reginaldrsps View Post
    Thanks for your post, When I want to check it for myself with System.out.println(player.getLocation + " - " + Location.LOBBY);. It didnt show anything it putted it like this:
    Spoiler for Code:
    Code:
    	public static void addPlayer(Player player) {
    		System.out.println(player.getLocation() + " - " + Location.LOBBY);
     		if(player.getLocation() == Location.LOBBY) {
    			player.getPacketSender().sendMessage("Lobby entered");
    			System.out.println(player.getLocation() + " - " + Location.LOBBY);
    			if(PlayersInLobby == MaxPlayers) {
    				while(PlayersInLobby <= Minplayers && GameTimer > -1) {
    					GameTimer--;
    					if (GameTimer == 0) {
    						player.moveTo(new Position(3090, 3520));
    						player.getPacketSender().sendMessage("Test.");
    					//	InitializeGame();
    					}
    				}		
    			}
    		}
    	}


    Did I use it wrong?
    Are you even calling the given method? It MUST send the message if you're calling it. If it sends nothing you ain't even calling it..
    Attached image
    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. Buy and ::buy bug help for 562
    By JustinFatalx in forum Help
    Replies: 10
    Last Post: 07-14-2010, 07:30 PM
  2. Replies: 41
    Last Post: 07-12-2010, 04:51 AM
  3. help for client sided and server sided
    By Zᴀᴄʜ in forum Help
    Replies: 5
    Last Post: 06-23-2010, 01:12 AM
  4. Replies: 9
    Last Post: 11-08-2009, 10:00 PM
  5. Replies: 5
    Last Post: 09-17-2009, 08:33 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
  •