Thread: getting player ID without player name

Results 1 to 3 of 3
  1. #1 getting player ID without player name 
    Registered Member
    Join Date
    Jun 2009
    Posts
    133
    Thanks given
    0
    Thanks received
    1
    Rep Power
    47
    Code:
    if(UID < 1) {
    BufferedWriter bw = null;
    PlayerHandler.getPlayerID;
    client p = (client) server.playerHandler.players[otherPIndex];
    bw = new BufferedWriter(new FileWriter("data/bannedips.txt", true));
    	 bw.write(p.playerLastConnect);
    	 bw.newLine();
    	 bw.flush();
    			
    			p.disconnected = true;
    			
    }
    whats needed here
    Reply With Quote  
     

  2. #2  
    Registered Member Hexagon's Avatar
    Join Date
    May 2008
    Posts
    672
    Thanks given
    28
    Thanks received
    18
    Rep Power
    33
    You can't get player id without the name =]
    getPlayerID(String playerName)

    the void needs it
    Reply With Quote  
     

  3. #3  
    Registered Member
    Deadly Uzi's Avatar
    Join Date
    Jul 2008
    Posts
    994
    Thanks given
    177
    Thanks received
    87
    Rep Power
    362
    Code:
    public int getPlayerID(String value) {
    
    // Loop through all the players.
    for(Player player : Server.playerHandler.players) {
    
    if(player.playerName.equalsIgnoreCase(value)
    // If the username mathes, return this players' ID.
    return player.playerId;
    
    }
    
    // Otherwise, no player could be matched, return -1. (like default value or something).
    return -1;
    }
    This loops through your array containing all your players, while it's looping, it checks if the current player's(the one thats being looped through) username is the same as the one you put in as your parameters(like getPlayerID("bob")), if so, it returns this player's ID.

    This could work with anything, like if you want it to check for like the players IP, you would put player.connectedFrom or something. (Instead of player.playerName).

    Hope this helps
    Attempting to develop a multi-revision library. See it on GitHub.
    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

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •