Solved How to code anti teamkill?

Discussion in 'Plugin Development' started by xDjBomber, Feb 23, 2014.

Thread Status:
Not open for further replies.
  1. Whats Name of the event for Anti Team Kill (PVP)?

    So if Player 1 team blue and attacks Player 2 (team blue) the 2. Player shouldn't get Damage from Player 1, so that they can't take damage, if they in the same teams?
     
  2. Offline

    calebbfmv

    Team team = <Scoreboard>.registerNewTeam(name);
    team.setAllowFriendlyFire(false);
     
  3. Thank you, will try it tommorrow!

    What is "<Scoreboard>" mean? (6 months ago, that i have the plugin updated)
     
  4. Offline

    The Fancy Whale

    You could do what calebbfmv said or depending on how you are doing teams you could just do a simple
    Code:java
    1. public void onDamage(EntityDamageByEntityEvent e)
    2. {
    3.  
    4. Entity damager = e.getDamager();
    5. Entity damaged = e.getEntity();
    6. if(!(damager instanceof Player)) return;
    7.  
    8. if(!(damaged instanceof Player)) return;
    9. }
    10.  
    11.  


    And then just check what team the damager and damaged are on and do e.setCancelled(true) if they are.
     
  5. Offline

    MrInspector

    The name of your scoreboard. ;)
     
  6. Offline

    jordanzilla02

    Also, couldn't you get the player's team and check if the damager is the other team, and of it isn't from the enemy cancel the event? Also this only applies to certain ways ie: array lists.
     
  7. *Removed*

    //EDIT: Ok should work now, ty guys.
     
  8. Offline

    calebbfmv

  9. Offline

    jordanzilla02

    What if you don't want to work with scoreboards? I like making two or more arraylist for the teams then check in the damage listener if the damager is from the same team, the damage will be cancelled because you can make a player called damager and use the teamname.contains(damager) or something similar to that.
     
  10. Offline

    calebbfmv

    jordanzilla02
    But,think in a larger scale:
    Your getting the list, reading it all, then comparing the strings to another. if you have 1000+ people for it, thing of the CPU having to deal with that, every time someone hits another. Unnecessary waste of time.
     
  11. Offline

    Booshayy

    You could do what jordanzilla02 said.

    Make an arraylist for each team. When the player is assigned to a team, put them in the proper arraylist, and make an event that prevents EntityDamageByEntity for that specific arraylist.
     
  12. Offline

    calebbfmv

    Booshayy
    That is NOT a good idea.....
     
  13. Offline

    Booshayy

  14. Offline

    calebbfmv

    Booshayy
    Memory:
    Every single time a Player is hit by another player, you are getting 2 lists, getting contents, then comparing. Think of it on a larger scale:
    1000 people battle:
    500 on 1 team, 500 on another.
    Each team hits 1 person, you do 500+ checks, all in 1 tick. Tell me that won't cause lag at some time?
     
  15. Offline

    jordanzilla02

    What is the likeliness of this?
     
  16. Offline

    calebbfmv

    jordanzilla02
    For me, 100%
    For others, idk. Good practice though.
     
  17. Offline

    jordanzilla02

    I am talking about 500 players on one team, I am assuming this is for a minigame and that is sort of ridiculous to have 1k players on one server, you will have some lag... (a lot of lag)
     
  18. Offline

    calebbfmv

    jordanzilla02
    Unless you run the better version.
    Regardless of having 500 on 1 team, you still do checks for each player, checking lists and things. It is just overall better, trust me.
     
  19. Offline

    _Cookie_

    I just use, EntityDamagedByEntityEvent.
    Then I have two ArrayLists, blue and red.
    Check if the player and attacker is on the same ArrayList, if so then cancel the event.
     
  20. Offline

    IkBenHarm

    calebbfmv
    ### OFFTOPIC ###
    since you are so against the comparing two lists. I started to wonder, what do the scoreboards do?
     
  21. Offline

    calebbfmv

  22. Already solved, ty guys.
     
  23. Offline

    IkBenHarm

Thread Status:
Not open for further replies.

Share This Page