Add Event Point Command Help

Results 1 to 9 of 9
  1. #1
    Member SAINTmade is offline
    MemberRank
    Jul 2013 Join Date
    USALocation
    65Posts

    Add Event Point Command Help

    Hey Ragezone community. I'm trying to code a command for players to transfer event points in between eachother. I want the command to be @giveep <ign> <amt>.

    Here's my code so far:
    Code:
     } else if (splitted[0].equalsIgnoreCase("giveep")) {              if (player.getEventPoints > 0 && amount <= player.getEventPoints()) {
                MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
                 victim.gainEventPoints(Integer.parseInt(splitted[2]));
                player.gainEventPoints(-Integer.parseInt(splitted[2]));
                player.dropMessage("You have given " + splitted[1] + " " + splitted[2] + " Event Points.");
               victim.dropMessage(6, player.getName() + " has given you " + splitted[2] + " Event Points.");  
                 } else {
                     player.dropMessage("Make sure you have enough Event Points to give away.");
                 }
    I'm aware that it doesn't work. I'm kind of new to coding. But I what I am trying to do is make it check if the player has more or equal to the amount the player is trying to give away. If they do, the player would lose the amount they typed and the other player (victim) would gain the amount. The dropMessage's are pretty self explanatory.

    In game, the command says "Make sure you have enough Event Points to give away." even though I do have way more than enough to give away. I believe it is skipping the checking process, probably because I coded it wrong. Any help? Thanks guys.

    / Just incase you guys need my methods to help me out

    Code:
    public int getEventPoints() {           
    return eventpoints;
        }
           
            public void gainEventPoints(int eventpoints) {
                this.eventpoints += eventpoints;
            }
    
    private int eventpoints;


  2. #2
    Wut. QuietCrystal is offline
    MemberRank
    Aug 2010 Join Date
    SingaporeLocation
    346Posts

    Re: Add Event Point Command Help

    Quote Originally Posted by SAINTmade View Post
    Hey Ragezone community. I'm trying to code a command for players to transfer event points in between eachother. I want the command to be @giveep <ign> <amt>.

    Here's my code so far:
    Code:
     } else if (splitted[0].equalsIgnoreCase("giveep")) {              if (player.getEventPoints > 0 && amount <= player.getEventPoints()) {
                MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
                 victim.gainEventPoints(Integer.parseInt(splitted[2]));
                player.gainEventPoints(-Integer.parseInt(splitted[2]));
                player.dropMessage("You have given " + splitted[1] + " " + splitted[2] + " Event Points.");
               victim.dropMessage(6, player.getName() + " has given you " + splitted[2] + " Event Points.");  
                 } else {
                     player.dropMessage("Make sure you have enough Event Points to give away.");
                 }
    I'm aware that it doesn't work. I'm kind of new to coding. But I what I am trying to do is make it check if the player has more or equal to the amount the player is trying to give away. If they do, the player would lose the amount they typed and the other player (victim) would gain the amount. The dropMessage's are pretty self explanatory.

    In game, the command says "Make sure you have enough Event Points to give away." even though I do have way more than enough to give away. I believe it is skipping the checking process, probably because I coded it wrong. Any help? Thanks guys.

    / Just incase you guys need my methods to help me out

    Code:
    public int getEventPoints() {           
    return eventpoints;
        }
           
            public void gainEventPoints(int eventpoints) {
                this.eventpoints += eventpoints;
            }
    
    private int eventpoints;
    Code:
    player.getEventPoints > 0
    should be
    Code:
    player.getEventPoints() > 0
    Small errors like these would screw up the compilation.

    And before you complain that there are mysterious exploits all of a sudden, add a check for amount > 0. Otherwise I can give someone negative -9999 event points once I have 1 event point.

    After all, player.getEventPoints() > 0 and -9999 <= player.getEventPoints()

  3. #3
    I'm overrated. Fraysa is offline
    MemberRank
    Apr 2008 Join Date
    4,891Posts

    Re: Add Event Point Command Help

    First of all, you didn't define what amount is. You can it do by parsing splitted[0].

    Code:
    int amount = Integer.parseInt(splitted2]);
    Second, your statement doesn't make much sense, like @QuietCrystal mentioned. You have to check if the amount is not negative and if the player has sufficient event points.

    Lastly, you don't check if the victim is null. getCharacterByName will return null if the player is not registered inside the players' storage. So, simply check this using the following statement:

    Code:
    if (victim != null) {
       // Your code goes here...
    } else {
       player.dropMessage(6, "Player was not found.");
    }

  4. #4
    Member SAINTmade is offline
    MemberRank
    Jul 2013 Join Date
    USALocation
    65Posts

    Re: Add Event Point Command Help

    Quote Originally Posted by Fraysa View Post
    First of all, you didn't define what amount is. You can it do by parsing splitted[0].

    Code:
    int amount = Integer.parseInt(splitted2]);
    Second, your statement doesn't make much sense, like @QuietCrystal mentioned. You have to check if the amount is not negative and if the player has sufficient event points.

    Lastly, you don't check if the victim is null. getCharacterByName will return null if the player is not registered inside the players' storage. So, simply check this using the following statement:

    Code:
    if (victim != null) {
       // Your code goes here...
    } else {
       player.dropMessage(6, "Player was not found.");
    }
    OH nevermind. Testing now
    @Fraysa , Where in the code would I put int amount = Integer.parseInt(splitted2]); ? Thank you for helping.

  5. #5
    I'm overrated. Fraysa is offline
    MemberRank
    Apr 2008 Join Date
    4,891Posts

    Re: Add Event Point Command Help

    The decleration of the amount be set at the beginning of the method.

  6. #6
    Member SAINTmade is offline
    MemberRank
    Jul 2013 Join Date
    USALocation
    65Posts

    Re: Add Event Point Command Help

    Quote Originally Posted by Fraysa View Post
    The decleration of the amount be set at the beginning of the method.

    I'm not sure what you mean. Do you mean like this in MapleCharacter?
    Code:
    public int getEventPoints() {            int amount = Integer.parseInt(splitted2]);
                return eventpoints;
    	}
    If you do, I get errors.

  7. #7
    I'm overrated. Fraysa is offline
    MemberRank
    Apr 2008 Join Date
    4,891Posts

    Re: Add Event Point Command Help

    Quote Originally Posted by SAINTmade View Post
    I'm not sure what you mean. Do you mean like this in MapleCharacter?
    Code:
    public int getEventPoints() {            int amount = Integer.parseInt(splitted2]);
                return eventpoints;
        }
    If you do, I get errors.
    No. A little common sense please?... In the command, obviously.

  8. #8
    Member SAINTmade is offline
    MemberRank
    Jul 2013 Join Date
    USALocation
    65Posts

    Re: Add Event Point Command Help

    Quote Originally Posted by Fraysa View Post
    No. A little common sense please?... In the command, obviously.
    Heres my code now:
    Code:
    } else if (splitted[0].equalsIgnoreCase("giveep")) {              if (victim != null) {
                  if (player.getEventPoints() > 0 && -9999 <= player.getEventPoints()) {
                        int amount = Integer.parseInt(splitted[2]);
                  MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
                 victim.gainEventPoints(Integer.parseInt(splitted[2]));
                player.gainEventPoints(-Integer.parseInt(splitted[2]));
                player.dropMessage("You have given " + splitted[1] + " " + splitted[2] + " Event Points.");
               victim.dropMessage(6, player.getName() + " has given you " + splitted[2] + " Event Points.");  
                 } else {
                     player.dropMessage("Make sure you have enough Event Points to give away.");
                 }
                  } else {
                    player.dropMessage(6, "Player was not found.");
                    }
    Now it tells my "Player was not found.");

  9. #9
    Member SAINTmade is offline
    MemberRank
    Jul 2013 Join Date
    USALocation
    65Posts

    Re: Add Event Point Command Help

    nevermind. fixed. but by any chance is there a method that checks if you are trying to give event points to yourself? you can give yourself event points and it says 'You have given 1 event point to so & so" but you don't gain any event points. Is there like an if something ?

    code:
    Code:
      } else if (splitted[0].equalsIgnoreCase("giveep")) {                      MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(splitted[1]);
                 if (victim != null) {
                  if (player.getEventPoints() > 0 && -9999 <= player.getEventPoints()) {
                        int amount = Integer.parseInt(splitted[2]);
                 victim.gainEventPoints(Integer.parseInt(splitted[2]));
                player.gainEventPoints(-Integer.parseInt(splitted[2]));
                player.dropMessage("You have given " + splitted[1] + " " + splitted[2] + " Event Points.");
               victim.dropMessage(6, player.getName() + " has given you " + splitted[2] + " Event Points.");  
                 } else {
                     player.dropMessage("Make sure you have enough Event Points to give away.");
                 }
                  } else {
                    player.dropMessage(6, "Player was not found.");
                    }
    @Fraysa , @QuietCrystal

    - - - Updated - - -

    Quote Originally Posted by QuietCrystal View Post
    Code:
    player.getEventPoints > 0
    should be
    Code:
    player.getEventPoints() > 0
    Small errors like these would screw up the compilation.

    And before you complain that there are mysterious exploits all of a sudden, add a check for amount > 0. Otherwise I can give someone negative -9999 event points once I have 1 event point.

    After all, player.getEventPoints() > 0 and -9999 <= player.getEventPoints()
    I got it working but if you put a negative number, you wil lgain EP and the victim will lose EP. How do I add a check for amount > 0?

    Something like if int amount = -Integer ? Thank you :)

    - - - Updated - - -
    @Fraysa , @QuietCrystal nevermind guys. fixed everything. thank you!



Advertisement