Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Xeos on January 22, 2015, 04:15:17 AM

Title: Detecting Creep Position
Post by: Xeos on January 22, 2015, 04:15:17 AM
I am playing with one of Virgil's scripts and it has this section below which detects a unit position. I would be grateful if someone could show me the code to detect the position of creep in the same way please?

<-closestUnit neq0 if
<-closestUnit CONST_COORDX GetUnitAttribute ->targetX
<-closestUnit CONST_COORDY GetUnitAttribute ->targetY
else
-1 ->targetX -1 ->targetY
endif


Thanks in advance
Ian
Title: Re: Detecting Creep Position
Post by: Hubs on January 22, 2015, 08:03:23 AM
I think you're looking for GetNearestGroundEnemy. It's not filled out on the wiki, but I found information about it on some forum and used it in a project i was working on.


# GetNearestGroundEnemy(X,Y,R,LOS,C,D,AC)
# X and Y are the starting coordinates, R is the range (inclusive), LOS is a bool for whether terrain blocks line of sight, C,AC,D are bools for whether to look at Creeper, AntiCreeper, Digitalis.
# It returns X Y coordinates

GetNearestGroundEnemy (CurrentCoords <-Range 1 1 0 0) ->TargetY ->TargetX


      
Title: Re: Detecting Creep Position
Post by: Xeos on January 22, 2015, 10:14:20 AM
Thanks Hubs for helping :)
How can I get that to work in the same format as the previous code in an 'if' statement ? - I have tried to play with it ( still a massive noob on coding as yet) for sometime and using the wiki and other examples, I have tried to configure it but I don't know enough yet to get it to work  :(

Title: Re: Detecting Creep Position
Post by: Hubs on January 22, 2015, 11:35:57 AM
Variable names are case sensitive, so try either of these:

GetNearestGroundEnemy (CurrentCoords <-Range 1 1 0 0) ->targetY ->targetX

# this way works too:

CurrentCoords <-Range 1 1 0 0 GetNearestGroundEnemy ->targetY ->targetX


CurrentCoords just takes the current X Y of the core this script is attached too. You could put whatever coords you want in place of that. Also, <-Range is assuming you have a Range variable. If you want to hard code it in, just replace iwth the range you want (in cells), or replace with a different variable name if you have one.
Title: Re: Detecting Creep Position
Post by: Xeos on January 22, 2015, 04:08:50 PM
Thanks again Hubs - I will keep playing with it and see if I can get it working :)