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

How to use the SlapperHitEvent to log how many times it gets hit

Discussion in 'Help' started by MC ATECH, Sep 5, 2017.

  1. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    Hello!
    How do i use the SlapperHitEvent to create an ongoing tally (in a config) of how many players have hit the npc?

    The config should have the name of the npc with an integer next to it to show the popularity of that slapper to give me a better idea of what npc's to use and where to put them.

    Great if someone could talk me through how to do this.

    Thanks, mc atech.
     
  2. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    Hi,
    in PmmP there exist no "SlapperHitEvent". This event, has certainly been created by a plugin. You should tell us which Slapper plugin you use and show your previous attempts
     
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Please don't post these useless comments. There only is one slapper plugin, https://github.com/jojoe77777/Slapper.

    Alright, first, I hope you do know how to listen for events? Just implement Listener, register events in the PluginBase. Okay then, let's get to the point.

    The SlapperHitEvent has a getDamager() function to return the player that hit the slapper, and a getEntity() function to return the entity/slapper that got slapped by that player. You can't see that function in the file, as it extends EntityEvent which has that function already.

    I'm not sure how exactly you want to do this, but I'd recommend something along the lines of listening for SlapperCreationEvent, getting the name of the entity by doing SlapperCreationEvent->getEntity()->getNameTag(), then storing that name in an array (a property) with 0 as value and the name as key. Then everytime when an entity gets hit, increment that number by one, by checking the nametag of the slapper hit using the method above but on SlapperHitEvent.

    When your plugin disables, you would want to store that array you made. You could do yaml_emit_file("path/to/file", $arrayMentionedAbove); to store that data. Then when your plugin enables again, you check if that file exists, then fill the array mentioned above with yaml_parse_file("path/to/file"); and the process repeats again.
     
    jojoe77777, jasonwynn10 and MC ATECH like this.
  4. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    This helped a ton!
    Ill tell you how i do with this as i work through it! Thanks a lot!
     
    Last edited: Sep 6, 2017
  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.