Solved Getting a direction the player is facing for teleport etc.

Discussion in 'Plugin Help/Development/Requests' started by Scorpionvssub, Nov 20, 2015.

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

    Scorpionvssub

    When i create an arena it stores the coords of the player using the command, when a player reaches a checkpoint does that too, however it ALWAYS spawns me facing south and a parkour or anything always going south to match the right angle just doesnt work well imo.. Ive checked tons of pages about vector(no clue much on that) math equacians(idk spelling + im terrible at math itself)... but they all keep referring to tons of other help questions and other pages never really giving a clear solution what i accually could use to get the right pitch yaw direction whatever is needed that when i do /pk create and face east it spawns me east when i join the parkour..

    Code:
            plugin.arenas.set("arena." + name + ".x", Double.valueOf(loc.getX()));
            plugin.arenas.set("arena." + name + ".y", Double.valueOf(loc.getY()));
            plugin.arenas.set("arena." + name + ".z", Double.valueOf(loc.getZ()));
            plugin.arenas.set("arena." + name + ".w", loc.getWorld().getName());
    Ive looked over it a bunch of time i seen getyaw getpitch getdirection getblocksomething get... well alot of stuff but which would really grab east when i set it as east and north when i want north etc. etc.? all those pages ive looked at are confusing me completely..

    Note: Yes i tried them but think im missing something
     
  2. Offline

    oceantheskatr

    You want to get the pitch and yaw.

    Pitch is looking up and down, yaw is looking left and right (or it's reversed lol).
     
  3. Offline

    Scorpionvssub

    @oceantheskatr thanks so i added those to be set when you create the arena then i tried to grab those values back in the teleports but where as loc is xyz it wont allow to put the other 2 in addition to this.. so thought i'd try getting the eyedirection then set the yaw + pitch but..doesn't seem to be valid

    Code:
        public static void teleportToArena(Main plugin, Player p, String name)
        {
            if (plugin.arenas.get("arena." + name) != null)
            {
                double x = plugin.arenas.getDouble("arena." + name + ".x");
                double y = plugin.arenas.getDouble("arena." + name + ".y");
                double z = plugin.arenas.getDouble("arena." + name + ".z");
                double yaw = plugin.arenas.getDouble("arena." + name + ".yaw");
                double pi = plugin.arenas.getDouble("arena." + name + ".pitch");
                World w = Bukkit.getWorld(plugin.arenas.getString("arena." + name + ".w"));
                Location loc = new Location(w, x, y, z);
                plugin.oldloc.put(p, p.getLocation());
                plugin.armor.put(p, p.getInventory().getArmorContents());
                p.getInventory().setArmorContents(null);
                plugin.invs.put(p, p.getInventory().getContents());
                p.getInventory().clear();
                p.teleport(loc);
                p.getEyeLocation().setDirection(yaw, pi);
            }
        }
        
    Also tried int as they are numbers to see if that resolved anything but nope...
     
  4. Offline

    oceantheskatr

    Try making yaw and pitch floats.
     
  5. Offline

    Scorpionvssub

    @oceantheskatr

    Here is another issue i tried to fix/solve but dont wanna end up breaking more then needed or even ending up unable to get it to what it is now...

    http://hastebin.com/xezicuwumu.avrasm

    At line 11/12 it teleports you to the last checkpoint you crossed which is set at the ifs below it (iron plate) it stores your location or the loc of that plate then teleports u back if u hit water/lava However...it spawns me south, i tried serialize which is often suggested i k...but then you need to deserialize it which then wants me to static some stuff which often when i do it end up to be not so smart to do.. Hope you got a suggestion, i could try float again but dont think that will work on this? or idk where to put it
     
    Last edited: Nov 21, 2015
  6. Offline

    oceantheskatr

    I'm pretty tired so I'm not sure if I read this right, but try changing this:
    this.plugin.checkpoint.put(p, (Location) p.getLocation().getBlock().getLocation());

    to this:
    this.plugin.checkpoint.put(p, (Location) p.getLocation());

    And by the way when storing a player in a hashmap/hashset/arraylist/etc. you should use their name Player#getName. Using the actual player can lead to memory leaks or somethin like that.
     
  7. Offline

    Scorpionvssub

    @oceantheskatr If i do p.getname it says it may not contain of type String now its spamming "you reached a checkpoint" over and over and over.. but does set the location correctly
     
  8. Online

    timtower Moderator Moderator

    @Scorpionvssub Then you also need to use p.getName in your checks.
     
  9. Offline

    Scorpionvssub

    May have a solution or figured it out testing now
     
  10. Online

    timtower Moderator Moderator

    @Scorpionvssub Change the type of the hashmap to string,location, you aren't using player objects anymore.
     
    oceantheskatr likes this.
  11. Offline

    Scorpionvssub

    Code:
                if ((p.getLocation().getBlock() != null) &&
                        (p.getLocation().getBlock().getType().equals(Material.IRON_PLATE))) {
                    if (this.plugin.checkpoint.containsKey(p)) {
                        int x = (int) ((Location) this.plugin.checkpoint.get(p)).getX();
                        int z = (int) ((Location) this.plugin.checkpoint.get(p)).getZ();
    
                        int bx = p.getLocation().getBlockX();
                        int bz = p.getLocation().getBlockZ();
                        if ((x != bx) || (z != bz)) {
                            this.plugin.addCheckpoint(p);
                            p.sendMessage(prefix + ChatColor.BLUE + " You reached a checkpoint.");
                            p.sendMessage(String.valueOf(p) + " is the name");
                            this.plugin.checkpoint.put(p, (Location) p.getLocation());
                        }
                    } else {
                        this.plugin.addCheckpoint(p);
                        p.sendMessage(prefix + ChatColor.BLUE + " You reached a checkpoint.");
                        this.plugin.checkpoint.put(p, (Location) p.getLocation());
                    }
                }
    Does it mean i also have to change the int bx and bz stuff? due to that it grabs a block and what was suggested is removing the block.


    Edit: tried something but didnt work out as i cant use p.getname everywhere

    Code:
               if (this.plugin.checkpoint.containsKey(p.getName())) {
                        int x = (int) ( this.plugin.checkpoint.get(p.getName())).getX();
                        int z = (int) ( this.plugin.checkpoint.get(p.getName())).getZ();
    
                        int bx = (int) p.getLocation().getX();
                        int bz = (int) p.getLocation().getY();
                        if ((x != bx) || (z != bz)) {
                            this.plugin.addCheckpoint(p);
     
    Last edited: Nov 22, 2015
Thread Status:
Not open for further replies.

Share This Page