Check if player stays on a point

Discussion in 'Plugin Development' started by HackintoshMan, May 12, 2013.

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

    HackintoshMan

    I need to check if a player is on a point. If he is, start a timer that founds down from 5. If he gets off of the point stop the timer and reset it until he gets back on. I have spent about 2 weeks and I can't figure it out!
     
  2. Offline

    caseif

    Store the player's last move time in a global HashMap, then reset it on the PlayerMoveEvent (make sure it's not just a change of pitch or yaw). You can check this value in a repeating task, by comparing the current time to the HashMap time once per second.
     
  3. Offline

    WhatAaCow

    @AngryNerd I think if u use the PlayerMoveEvent event, you need to much CPU power. U said "in a repeating task; once per second" so u don't need the PlayerMoveEvent ;)
     
  4. Offline

    MrZoraman

    You'll also need to check for the player standing in a zone rather than a point. The odds of the player getting on the exact point you are checking for would be astronomical.
     
  5. Offline

    caseif

    But, you would need to know when the player moves, and you can't do that without a listener. Actually, I take that back; it would just be more difficult. You could use the task to store the player's location (not as an instance of the default Location variable, as they're unreliable), then check the next time it's called if it's still the same.
     
  6. Offline

    WhatAaCow

    AngryNerd U check every repeating task the players location with the location in the hashmap, and if he doesn't move, then make an Integer for the player and count every task +1 and if 5 is reached....do everythin u want to ;)
     
  7. Offline

    caseif

    I know, I said that.
     
  8. Offline

    WhatAaCow

    :)
     
  9. Offline

    HackintoshMan

    AngryNerd WhatAaCow MrZoraman

    I check to see if the player is in the range of the specific point with this code:

    Code:
    if (Math.abs(plugin.playerLocation.playerX(player)
                    - plugin.capturePointLocation.point1X()) <= 2
                    && Math.abs(plugin.playerLocation.playerX(player)
                            - plugin.capturePointLocation.point1X()) >= 0
                    && Math.abs(plugin.playerLocation.playerY(player)
                            - plugin.capturePointLocation.point1Y()) <= 1
                    && Math.abs(plugin.playerLocation.playerY(player)
                            - plugin.capturePointLocation.point1Y()) >= 0
                    && Math.abs(plugin.playerLocation.playerZ(player)
                            - plugin.capturePointLocation.point1Z()) <= 2
                    && Math.abs(plugin.playerLocation.playerZ(player)
                            - plugin.capturePointLocation.point1Z()) >= 0
                    && plugin.playerLocation.playerWorld(player).equals(
                            plugin.capturePointLocation.point1World())) {
                    plugin.captureTheFlagHandler.isBeingCaptured1 = true;
            }
    But what I can't do is start and stop the timer accordingly
     
  10. Offline

    caseif

    Store the task id in a global variable (by prefixing the task with "int id = "), then cancel it and clear the variable as you need to. Then again, you shouldn't need to stop it if it's checking all online players.
     
Thread Status:
Not open for further replies.

Share This Page