my !randomplayer command

Results 1 to 12 of 12
  1. #1
    Valued Member yarden is offline
    MemberRank
    Jul 2012 Join Date
    137Posts

    my !randomplayer command

    This is the code :
    PHP Code:
    } else if (splitted[0].equals("randomplayer")) {
                List<
    String> list = new ArrayList<String>();
                for (
    MapleCharacter chr player.getMap().getCharacters()) {
                    if (
    chr != null && !chr.isSGM()) {
                    list.
    add(chr.getName());
                }
                
    String[] availableChar = list.toArray(new String[list.size()]);
                
    int chosenChar Randomizer.rand(0availableChar.length);
                
    player.getMap().broadcastMessage(MaplePacketCreator.sendYellowTip("The chosen player was " availableChar[chosenChar] + ".")); 
                } 
    Ok the the problem is that everytime i use it,It doesn't work very well
    It either sends the message "The chosen player was.." Twice or doesnt work at all..
    What can i do??or what's wrong with that code?


  2. #2
    $_SESSION['DEV']; hecari is offline
    MemberRank
    Dec 2008 Join Date
    336Posts

    Re: my !randomplayer command

    Oh god ._. Why List<String> ?
    Do you know that player.getMap().getCharacters() return List<MapleCharacter> data type? Use a List<MapleCharacter> variableName to hold the data return from player.getMap().getCharacters().
    PHP Code:
    public static class randomPlayer extends CommandExecute {
            
            public 
    int execute(MapleClient cString[] splitted) {
                List<
    MapleCharactercharactersz c.getPlayer().getMap().getCharacters();
                
    int amount charactersz.size();
                
    int random = (int) Randomizer.rand(0amount);
                
    MapleCharacter characterInList charactersz.get(random);
                
    String nameOfCharacter characterInList.getName();
                for (
    MapleCharacter chr charactersz) {
                       
    chr.dropMessage(1nameOfCharacter); // int messageType, string
                
    }
                return 
    1;
            }
        } 
    Port it to your source . The above code is based on Lithium .

  3. #3
    Valued Member yarden is offline
    MemberRank
    Jul 2012 Join Date
    137Posts

    Re: my !randomplayer command

    Quote Originally Posted by hecari View Post
    Oh god ._. Why List<String> ?
    Do you know that player.getMap().getCharacters() return List<MapleCharacter> data type? Use a List<MapleCharacter> variableName to hold the data return from player.getMap().getCharacters().
    PHP Code:
    public static class randomPlayer extends CommandExecute {
            
            public 
    int execute(MapleClient cString[] splitted) {
                List<
    MapleCharactercharactersz c.getPlayer().getMap().getCharacters();
                
    int amount charactersz.size();
                
    int random = (int) Randomizer.rand(0amount);
                
    MapleCharacter characterInList charactersz.get(random);
                
    String nameOfCharacter characterInList.getName();
                for (
    MapleCharacter chr charactersz) {
                       
    chr.dropMessage(1nameOfCharacter); // int messageType, string
                
    }
                return 
    1;
            }
        } 
    Port it to your source . The above code is based on Lithium .
    :S What do u mean port it to your source..?
    Sorry I'm trying to learn lol

  4. #4
    Proficient Member Firzen66 is offline
    MemberRank
    May 2010 Join Date
    190Posts

    Re: my !randomplayer command

    PHP Code:
    availableChar[chosenChar
    refers to MapleCharacter class, this class has getName() method, you shall use it that way:
    PHP Code:
    availableChar[chosenChar].getName() 
    btw, use chr.isGM() instead of chr.isSGM()

  5. #5
    Valued Member yarden is offline
    MemberRank
    Jul 2012 Join Date
    137Posts

    Re: my !randomplayer command

    Quote Originally Posted by Firzen66 View Post
    PHP Code:
    availableChar[chosenChar
    refers to MapleCharacter class, this class has getName() method, you shall use it that way:
    PHP Code:
    availableChar[chosenChar].getName() 
    btw, use chr.isGM() instead of chr.isSGM()
    isGM also reffers to donors so i'd rather use isSGM (:
    I know you can change it but it doesnt metter XD

    anyways
    where do you see availableChar[chosenChar] in the code? :O

  6. #6
    Proficient Member Firzen66 is offline
    MemberRank
    May 2010 Join Date
    190Posts

    Re: my !randomplayer command

    why won't you make a isDonator() instead of naming a donator as a GM?
    nvm, just change this line:
    PHP Code:
    player.getMap().broadcastMessage(MaplePacketCreator.sendYellowTip("The chosen player was " availableChar[chosenChar] + ".")); 
    to:
    PHP Code:
    player.getMap().broadcastMessage(MaplePacketCreator.sendYellowTip("The chosen player was " availableChar[chosenChar].getName() + ".")); 

  7. #7
    Valued Member yarden is offline
    MemberRank
    Jul 2012 Join Date
    137Posts

    Re: my !randomplayer command

    Quote Originally Posted by Firzen66 View Post
    why won't you make a isDonator() instead of naming a donator as a GM?
    nvm, just change this line:
    PHP Code:
    player.getMap().broadcastMessage(MaplePacketCreator.sendYellowTip("The chosen player was " availableChar[chosenChar] + ".")); 
    to:
    PHP Code:
    player.getMap().broadcastMessage(MaplePacketCreator.sendYellowTip("The chosen player was " availableChar[chosenChar].getName() + ".")); 
    Umm it says cannot find symbol

  8. #8
    Proficient Member Firzen66 is offline
    MemberRank
    May 2010 Join Date
    190Posts

    Re: my !randomplayer command

    I didn't see you added the name of the character, thought you added the character himself.
    does it show you an error in your bat files?

  9. #9
    Valued Member yarden is offline
    MemberRank
    Jul 2012 Join Date
    137Posts

    Re: my !randomplayer command

    Quote Originally Posted by Firzen66 View Post
    I didn't see you added the name of the character, thought you added the character himself.
    does it show you an error in your bat files?
    um no.
    The command does work but it's just that sometimes it sends the message twice with 2 different players like
    The chosen player was yarden
    the chosen player was firzen66

    instead of sending it once.
    and sometimes the ocmmand doesnt work at all

  10. #10
    Proficient Member Firzen66 is offline
    MemberRank
    May 2010 Join Date
    190Posts

    Re: my !randomplayer command

    lol, try this one:
    PHP Code:
    } else if (splitted[0].equals("randomplayer")) { 
                List<
    String> list = new ArrayList<String>();
                for (
    MapleCharacter chr player.getMap().getCharacters()) { 
                    if (
    chr != null && !chr.isSGM()) { 
                        list.
    add(chr.getName()); 
                    } 
                }
                
    String[] availableChar = list.toArray(new String[list.size()]); 
                
    int chosenChar Randomizer.rand(0availableChar.length); 
                
    player.getMap().broadcastMessage(MaplePacketCreator.sendYellowTip("The chosen player was " availableChar[chosenChar] + "."));  
            } 
    seems like you missed one bracket haha

  11. #11
    Valued Member yarden is offline
    MemberRank
    Jul 2012 Join Date
    137Posts

    Re: my !randomplayer command

    Quote Originally Posted by Firzen66 View Post
    lol, try this one:
    PHP Code:
    } else if (splitted[0].equals("randomplayer")) { 
                List<
    String> list = new ArrayList<String>();
                for (
    MapleCharacter chr player.getMap().getCharacters()) { 
                    if (
    chr != null && !chr.isSGM()) { 
                        list.
    add(chr.getName()); 
                    } 
                }
                
    String[] availableChar = list.toArray(new String[list.size()]); 
                
    int chosenChar Randomizer.rand(0availableChar.length); 
                
    player.getMap().broadcastMessage(MaplePacketCreator.sendYellowTip("The chosen player was " availableChar[chosenChar] + "."));  
            } 
    seems like you missed one bracket haha
    Actaully with that extra bracket i get tons of errors XD

  12. #12
    $_SESSION['DEV']; hecari is offline
    MemberRank
    Dec 2008 Join Date
    336Posts

    Re: my !randomplayer command

    Quote Originally Posted by yarden View Post
    Actaully with that extra bracket i get tons of errors XD
    1) Technically, player.getMap().getCharacters() return a MapleCharacter type of ArrayList. So why not use
    PHP Code:
    List<MapleCharacterlistOfCharacter player.getMap().getCharacters(); 
    2)Why do you even bothering converting it to array if you can get element based on the arrangement of the array.
    PHP Code:
    MapleCharacter characterInList charactersz.get(random); 
    3) Randomising
    PHP Code:
    int random = (int) Randomizer.rand(0listOfCharacter.size()); 
    4) For the broadcasting, just use a for loop to output to everyone to be safe. (the problem might be your broadcastMessage), debug it to get the problem.
    PHP Code:
    for(MapleCharacter chr player.getMap().getCharacters()) {
         
    chr.dropMessage("lalalala");

    5) As on getting the name
    PHP Code:
    characterInList.getName(); 



Advertisement