Thread: [PI] If Player Logged In Statement

Results 1 to 9 of 9
  1. #1 [PI] If Player Logged In Statement 
    Registered Member HyreScape's Avatar
    Join Date
    May 2008
    Posts
    530
    Thanks given
    2
    Thanks received
    1
    Rep Power
    42
    I have been messing around and trying to get a if is logged in code to work and I am not the best at coding so I haven't been able to achieve success, so I would like to ask the community for help at this point.

    Code:
    }
    	if(!playerName.equalsIgnoreCase("Admin").isLoggedIn()) {
    	//Do Something
    	} else {
    	//Do Something
    	}
    All help is appreciated.
    Reply With Quote  
     

  2. #2  
    Donator
    Darkness's Avatar
    Join Date
    Nov 2012
    Age
    26
    Posts
    876
    Thanks given
    121
    Thanks received
    75
    Rep Power
    47
    May I ask what it is for?
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member HyreScape's Avatar
    Join Date
    May 2008
    Posts
    530
    Thanks given
    2
    Thanks received
    1
    Rep Power
    42
    When a player logs in it will shout it in the server. I know how to do that, I am just trying to get the login part to work.
    Reply With Quote  
     

  4. #4  
    Donator
    Darkness's Avatar
    Join Date
    Nov 2012
    Age
    26
    Posts
    876
    Thanks given
    121
    Thanks received
    75
    Rep Power
    47
    Edit; sorry you probably knew all of this
    I know how to do that
    so nvm sorry

    Well to be honest, all the codes that needs to see if a player just logged in\ is logged in uses this :

    Code:
    			for (int j = 0; j < PlayerHandler.players.length; j++) {
    				if (PlayerHandler.players[j] != null) {
    					Client c2 = (Client)PlayerHandler.players[j];
    Like this in public void initialize, client class :

    Code:
    		if (playerRights == 2) {
    			for (int j = 0; j < PlayerHandler.players.length; j++) {
    				if (PlayerHandler.players[j] != null) {
    					Client c2 = (Client)PlayerHandler.players[j];
    					c2.sendMessage("<col=16759296><shad=16759296>[Administrator]<img=2> "+ Misc.optimizeText(playerName) +" has just logged in.");
    				}
    			}
    		}
    To create the "isLoggedIn" , You would have to define it, so you'd probably have to create like a void of somekind with that code , with statements etc if you don't want to have it everytime, like to keep it only in the line " loggedIn" but i've never personally seen it. It's repeated everywhere in my source, commands.java and in initialize for every single rank\ command that checks if people are online
    Attached image
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    May 2013
    Posts
    23
    Thanks given
    5
    Thanks received
    5
    Rep Power
    11
    add this to player.java

    Code:
    	public static Player getPlayerForName(String playerName) {
    		for(Player p : PlayerHandler.players) {
    			if(p.playerName == playerName)
    				return p;
    		}
    		return null;
    	}
    then to check if it is logged in i believe u can do

    if(Player.getPlayerForName("playerName") != null)

    or if you have a loggedIn boolean use it like this Player.getPlayerForName("playerName").isLoggedIn


    also in case you need this:

    Code:
    	public static boolean isOffline(String playerName) {
    		for(Player p : PlayerHandler.players) {
    			if(p.playerName == playerName)
    				return false;
    		}
    		return true;
    	}
    Reply With Quote  
     

  6. #6  
    Registered Member HyreScape's Avatar
    Join Date
    May 2008
    Posts
    530
    Thanks given
    2
    Thanks received
    1
    Rep Power
    42
    Olinice,
    Thank you for the assistance, but I want it to just say it for the admin, I dont really care if other logs in, just if the main one comes online, that's the one I want to show.

    tringanmistake,
    I believe that's for a different type of source.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    May 2013
    Posts
    23
    Thanks given
    5
    Thanks received
    5
    Rep Power
    11
    Quote Originally Posted by HyreScape View Post
    Olinice,
    Thank you for the assistance, but I want it to just say it for the admin, I dont really care if other logs in, just if the main one comes online, that's the one I want to show.

    tringanmistake,
    I believe that's for a different type of source.
    No it's not, this works for PI, but since you were checking for username i thought u wanted to know if the player was online using its username if its not that its also easy.

    just use something like this:

    Code:
    	public static boolean isAdminOnline() {
    		for(Player p : PlayerHandler.players) {
    			if(p.playerRights == 3)
    				return true;
    		}
    		return false;
    	}
    Reply With Quote  
     

  8. #8  
    Donator
    Darkness's Avatar
    Join Date
    Nov 2012
    Age
    26
    Posts
    876
    Thanks given
    121
    Thanks received
    75
    Rep Power
    47
    Adding this to public void initialize in client.java will make it send a message when an admins log in . ( Player rights 2?)

    Code:
    		if (playerRights == 2) {
    			for (int j = 0; j < PlayerHandler.players.length; j++) {
    				if (PlayerHandler.players[j] != null) {
    					Client c2 = (Client)PlayerHandler.players[j];
    					c2.sendMessage("<col=16759296><shad=16759296>[Administrator]<img=2> "+ Misc.optimizeText(playerName) +" has just logged in.");
    				}
    			}
    		}
    Attached image
    Reply With Quote  
     

  9. #9  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    Olinice is correct. Allow me to explain what which part does.
    Code:
    if (playerRights == 2) {
    	for (int j = 0; j < PlayerHandler.players.length; j++) {
    		if (PlayerHandler.players[j] != null) {
    			Client c2 = (Client)PlayerHandler.players[j];
    			c2.sendMessage("<col=16759296><shad=16759296>[Administrator]<img=2> "+ Misc.optimizeText(playerName) +" has just logged in.");
    		}
    	}
    }
    The red part is the condition which must be met in order for the "logged in" code to be executed. Yours would be if the playerName equals a certain value, here it is broadened to a rank.

    The green part loops through all the players who're online. If the playerObject grabbed is legit (not null) the violet part is executed.

    The violet part is the code that gets executed for EVERY player online. Notice the first line casts the player to the Client object, this is the target player.
    Here the target player receives a message.
    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. [PI] Weird out print when players log in
    By Ambient in forum Help
    Replies: 7
    Last Post: 02-07-2012, 06:14 AM
  2. Replies: 5
    Last Post: 08-20-2009, 03:53 AM
  3. Say when a player logged in.
    By Hyperventilate in forum Help
    Replies: 0
    Last Post: 03-29-2009, 04:55 AM
  4. Replies: 15
    Last Post: 02-01-2009, 05:29 AM
  5. Replies: 1
    Last Post: 01-21-2009, 03:34 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
  •