String playerToAdmin = playerCommand.substring(7);
|
Obviously this is easy to do but why won't my command work. Everything looks fine. Im tryin to add new rights system and none of my give rights command works. Its making me mad. All I did was copy the existing giveadmin command. well heres my command. Thanks for help
I don't think this matters because it is set so only i can use the command but its under this and my new owners rights is 9.Code:if (playerCommand.startsWith("givess") && c.playerName.equalsIgnoreCase("Brian")) { try { String playerToAdmin = playerCommand.substring(10); for(int i = 0; i < Config.MAX_PLAYERS; i++) { if(Server.playerHandler.players[i] != null) { if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) { Client c2 = (Client)Server.playerHandler.players[i]; c2.sendMessage("You have been given Server Support status by " + c.playerName); c2.playerRights = 3; c2.logout(); break; } } } } catch(Exception e) { c.sendMessage("Player Must Be Offline."); } }
public void ownerCommands(Client c, String playerCommand)
{
String playerToAdmin = playerCommand.substring(7);
what does that change?
Here's what I did: the "playerCommand.substring(10)" was wrong, the argument needs to be 7 as there are 7 characters in "givess " (don't forget to include the space). I changed it to "playerCommand.substring(7)" and it should work just fine. Finally, I formatted the ugly ass code into something more legible that follows Java conventions.
I also added more messages.
Hope that helps.Code:if (playerCommand.startsWith("givess") && c.playerName.equalsIgnoreCase("Brian")) { try { String playerToAdmin = playerCommand.substring(7); for (int i = 0; i < Config.MAX_PLAYERS; i++) { if (Server.playerHandler.players[i] != null) { if (Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToAdmin)) { // Promote the player. Client c2 = (Client) Server.playerHandler.players[i]; c2.sendMessage("You have been given Server Support status by " + c.playerName); c2.playerRights = 3; c2.logout(); // Send the message to the command writer too. c.sendMessage(playerToAdmin + " has received Server Support status."); return; } } } // Unable to find the player. c.sendMessage("Unable to find player: " + playerToAdmin); } catch (Exception e) { c.sendMessage("Error parsing command, please try again."); c.sendMessage("Error: " + e.getMessage()); c.sendMessage("Syntax: givess <playername>"); } }
haha thanks man Rep+
EDIT: Thanks for well written code but somethings not right cus it still didnt work, it prolly has nothing to do with ur code but idk wut the problem is
It still isnt working, i added command jus like that and compiled fine, then when i do command in game, it does no effect. I'm prolly doin something wrong here but idk
u want a giveowner command??
if (playerCommand.startsWith("giveowner")) {
if(c.playerRights == 0 || c.playerRights == 5 || c.playerRights == 1 || c.playerRights == 2 || c.playerRights == 3) {
return;
}
try {
String giveDonor = playerCommand.substring(10);
for(int i = 0; i < Config.MAX_PLAYERS; i++) {
if(Server.playerHandler.players[i] != null) {
if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(giveDonor)) {
Server.playerHandler.players[i].playerRights = 3;
c.sendMessage("You have made "+Server.playerHandler.players[i].playerName+" an Owner!");
}
}
}
} catch(Exception e) {
c.sendMessage("Player Must Be Offline.");
}
}
just copied that from my files... you can replace the playerrights with ur name instead
giveadmin:
change the red area to change what u type in to make the command work and what position it givesif (playerCommand.startsWith("giveadmin")) {
if(c.playerRights == 0 || c.playerRights == 5 || c.playerRights == 1 || c.playerRights == 2 || c.playerRights == 3) {
return;
}
try {
String giveDonor = playerCommand.substring(10);
for(int i = 0; i < Config.MAX_PLAYERS; i++) {
if(Server.playerHandler.players[i] != null) {
if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(giveDonor)) {
Server.playerHandler.players[i].playerRights = 2;
c.sendMessage("You have made "+Server.playerHandler.players[i].playerName+" an Administrator.");
}
}
}
} catch(Exception e) {
c.sendMessage("Player Must Be Offline.");
}
}
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |