1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved dmging an entity

Discussion in 'Development' started by dbcooper, Aug 15, 2018.

  1. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    How would I be able to dmg an entity such as cow, sheep, pig, or chicken. But only those 4.
    I have my server to block any entity dmg in the main world.

    What could I ad to the function to make it allow only the 4 entities to be damaged?
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Cancel all other entities damage expect 4 of them
     
  3. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    In the function, you could do
    PHP:
     /** @Entity $entity */
     
    if($entity instanceof Cow || $entity instanceof Sheep || $entity instanceof Pig || $entity instanceof Chicken) {
       return; 
    // return so the code doesn't execute on them.
     
    I'm sure there are more effective ways, just none that I know would work, aside from putting the entity names in an array and checking if the entity in question's name is in it.
     
    OnTheVerge likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.