Creating a PVP point system

Discussion in 'Plugin Development' started by iDoodleABC, Jul 24, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    iDoodleABC

    I am just starting to learn java, i know how to use simple variables and i am decent at maths.

    I was wondering if anyone could show me some example code of putting something before someones name as in a prefix. Also, how would i go about making a point system?

    The point system would just be you get 5% of the player's points in which you killed and they lose that 5% from their points. Also, the default would be set to a number like 100

    I use eclipse but im not actually sure how to export a project into a .jar file to use on my server, thanks :D
     
  2. Offline

    ninja2003

    I would suggest you not to start at the hard stuff, start with the basics such as a command that replies back to you when you enter it or eventhandlers.
     
  3. Offline

    Flamedek

    iDoodleABC Hey here
    To create a point system you will need to link the data to the players. To do this (and save it after restart ect) you will need to save it to a file, .yml is easiest.
    In that file you will store the players UUID and the matching 'points' value.
    To give players the default of 100 points, and to make sure every player is in the file so you won't get errors when you read from it you will want to listen to the PlayerJoinEvent. In the event check the players UUID, check if your file contains that UUID, if it does its all good, if it doesnt set their value to 100.

    Now when someone does, get their killer, check if it is a player and if so: get the 'points' value of the person that got killed, and take 5% from it. Now in the file set the killers value to whatever he had + that calculated value, and the dead mans value to whatever he had minus that calculated value.

    To add a prefix you could for example listen to the AsyncPlayerChatEvent, get the format of it and then set the format to whatever prefix you want added + the old format.


    I should warn you this forum is not a fan of spoonfeeding code to new devs, because if you don't know what you are doing it's no good making a plugin. Getting this all to work is gonna be a whole lot of figuring out and puzzling, but Im sure you will get there.
    If you don't know how to export the .jar, just look around. There are dozens of videos on that around.
    And for working with the file look up the YamlConfiguration object.

    Good luck 'n have fun!
     
  4. Start with a basic plugin and get that working. Just create a barebones plugin that will just load and work from there.

    Start with one objective like the prefix in someones name. Dont complicate it by jumping straight into a point system, as its something you will need to build up to.

    Prefixes in a players name would be done with using -> AsyncPlayerChatEvent. Use the method setPrefix("prefix here"); to set the prefix of the chat message.

    Code:java
    1. @EventHandler (priority = EventPriority.NORMAL)
    2. public void onPlayerChat(AsyncPlayerChatEvent e){
    3. Player chatter = e.getPlayer();
    4. String playerName = chatter.getName();
    5.  
    6. e.setFormat(playername);
    7. }


    You will need to know how to register events. We cant spoon feed you all the code ;) since you wont learn anything.
     
  5. Offline

    iDoodleABC



    Ok thanks guys! Too complicated for me right now but ill build up to it like frank said. Ill focus on trying to get a prefix infront of someones name :). You're right when you say spoon feeding me won't work, so thank you :)
     
  6. You're welcome, I speak from experience from teaching Java for over 2 years, best of luck :D
     
Thread Status:
Not open for further replies.

Share This Page