Tracking Explosions

Discussion in 'Plugin Development' started by ohtwo, Feb 17, 2013.

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

    ohtwo

    Hey guys, so I want to know how to track explosions (to keep track of who caused the explosions and if it damages another player). After thinking about it, here's my idea with the explosion caused by an arrow:

    Player 1 shoots arrow.
    Arrow hits ground (ProjectileHitListener)
    - Store shooter in hashmap?
    - Store radius coordinates same hashmap?
    Player 2 is damaged by an explosion, and if the area is within a stored location, eliminate that location from the hashmap.

    Heres the problem though. How do i clear the explosion from the hashmap after a certain time? Does anyone have a better, more efficient way to solve this problem?
     
  2. Offline

    Nitnelave

    You have to know what information you want : the location of the explosion, the time it happened, the entity responsible for the explosion, etc...
    And you also have to know what type of explosions you want to record, to know what listeners you will listen to.

    If you give us a brief description of your plugin (the relevant parts) and what you want to do with your explosions, we might be able to help you think this through.
     
  3. Offline

    ohtwo

    Basically I'm just creating explosive arrows. When an arrow hits a player, it works just fine. However, if the arrow lands on the ground, and a player is within proximity to its explosion, the player gets hurt without Minecraft "knowing" who the shooter is and who to credit if the hurt player dies.

    Bump?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    Nitnelave

    Wow, calm down! Just because I don't respond for half a day doesn't mean I forgot you!

    Given that the explosion creation and the entitydamaged event will happen in the same tick, you can pretty much clear the hashmap every second, it shouldn't be a problem because you won't clear it in between the explosion and the player getting hurt. That way, you could even simply use a list, because you will never have that many explosions. Store the location of the explosion in the lists along with the player responsible, and when a player gets damaged by an explosion you just have to check if it is "close" to a recorded explosion. To define close, either you define a constant, or you could compute the explosion radius by the maximum distance between the location of the explosion and the blocks destroyed (though that leaves the problem of an explosion over obsidian, for example, that won't destroy any blocks...).

    You can record the explosion when the arrow touches the ground and you create the explosion. That way, you will have the player as the shooter of the arrow.
     
Thread Status:
Not open for further replies.

Share This Page