namtatehtmit Posted November 10, 2016 Share Posted November 10, 2016 (edited) New member here, mainly c developer, newer to java, looking to make a cow killing script to warm up. I have read the API. Using state based scripting, my question is how do I get to check if my character is within a define area assuming I have an area defined. psuedo code for attacking: if( in cow pen area ) { if( not in combat ) { if( cow is not in combat) { return State.ATTACK; } } } Edited November 10, 2016 by namtatehtmit Link to comment Share on other sites More sharing options...
Explv Posted November 10, 2016 Share Posted November 10, 2016 (edited) New member here, mainly c developer, newer to java, looking to make a cow killing script to warm up. I have read the API. Using state based scripting, my question is how do I get to check if my character is within a define area assuming I have an area defined. psuedo code for attacking: if( in cow pen area ) { if( not in combat ) { if( cow is not in combat) { return State.ATTACK; } } } if (area.contains(myPosition()) Edited November 10, 2016 by Explv Link to comment Share on other sites More sharing options...
namtatehtmit Posted November 10, 2016 Author Share Posted November 10, 2016 (edited) if (area.contains(myPosition()) That works, but why do I not need to initialize a player object or anything? Like i just need to call the myposition() method and i get my characters position, where does that information come from? Also where do i look in the API to find other methods that pertain to my character? Edited November 10, 2016 by namtatehtmit Link to comment Share on other sites More sharing options...
Explv Posted November 10, 2016 Share Posted November 10, 2016 (edited) That works, but why do I not need to initialize a player object or anything? Like i just need to call the myposition() method and i get my characters position, where does that information come from? Also where do i look in the API to find other methods that pertain to my character? The player object for your own player can be accessed with: Player player = myPlayer(); The method: myPosition() Just does: myPlayer().getPosition() Edited November 10, 2016 by Explv Link to comment Share on other sites More sharing options...
Pseudo Posted November 10, 2016 Share Posted November 10, 2016 That works, but why do I not need to initialize a player object or anything? Like i just need to call the myposition() method and i get my characters position, where does that information come from? Also where do i look in the API to find other methods that pertain to my character? He's giving you pseudo code, you still need to reference the class that deals with the player object. Link to comment Share on other sites More sharing options...
Explv Posted November 10, 2016 Share Posted November 10, 2016 He's giving you pseudo code, you still need to reference the class that deals with the player object. No, i'm not. 4 Link to comment Share on other sites More sharing options...
namtatehtmit Posted November 10, 2016 Author Share Posted November 10, 2016 Thank you very much i appreciate the help. Link to comment Share on other sites More sharing options...
PlagueDoctor Posted November 11, 2016 Share Posted November 11, 2016 No, i'm not. I lol'd. Are there benefits doing it your way instead of just doing if(area.contains(myPlayer()) { } Link to comment Share on other sites More sharing options...
Tom Posted November 11, 2016 Share Posted November 11, 2016 I lol'd. Are there benefits doing it your way instead of just doing if(area.contains(myPlayer()) { } No, pretty much the exact same thing. I assume myPosition() calls myPlayer().getPosition() 1 Link to comment Share on other sites More sharing options...
Explv Posted November 11, 2016 Share Posted November 11, 2016 I lol'd. Are there benefits doing it your way instead of just doing if(area.contains(myPlayer()) { } tl;dr It's all the same shit. The Area class has several contains methods: public boolean contains(Entity entity) { return contains(entity.getX(), entity.getY()) && plane == entity.getZ(); } public boolean contains(Position position) { return contains(position.getX(), position.getY()) && plane == position.getZ(); } public boolean contains(int x, int y, int z) { return contains(x, y) && plane == z; } public boolean contains(int x, int y) { return (new java.awt.geom.Area(polygon)).contains((double)x, (double)y); } So, when you call: area.contains(myPlayer()) That will call the contains(Entity entity) method, because the Player is an Entity, which will then call the contains(int x, int y) method with the x coordinate and y coordinate of that entity, and also check if the z vlaues are the same. When you call: area.contains(myPosition()) That will call the contains(Position position) method, which will then call the contains(int x, int y, int z) method using the x, y and z coordinates of that Position, which then will call the contains(int x, int y) method, and also check the z values are the same. Either way, they both end up calling the same method contains(int x, int y) which checks that the polygon of the Area contains those coordinates, and also check that the z value is the same. 1 Link to comment Share on other sites More sharing options...
Saiyan Posted November 11, 2016 Share Posted November 11, 2016 Closing this, Thanks Explv for posting your detailed response! Link to comment Share on other sites More sharing options...