HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Neutral Hostile Guard Location

12-29-2006, 12:26 PM#1
Themerion
If I have a location X and want a neutral creep to start guarding that point, then I can just use SetUnitPosition to get it there. However, this doesn't look too smooth. So I want to make the unit move (walk, run, hover, fly, etc.) to that point, and then guard it. Are there any easy ways to do this, or do I have to use looping timers with continous checks?
12-29-2006, 12:50 PM#2
oNdizZ
try playing around with
Unit - Order (your_unit) to Move To (a_location)
12-29-2006, 12:56 PM#3
Thunder_Eye
unfortunatly the creep will run back to its original point
12-29-2006, 01:02 PM#4
oNdizZ
not if you give it a stop order when it has reached its location

Trigger:
asd
Collapse Events
Unit - A unit Is issued an order with no target
Collapse Conditions
(Issued order) Equal to (Order(idle))
Actions
12-29-2006, 01:46 PM#5
Themerion
Quote:
try playing around with
Unit - Order (your_unit) to Move To (a_location)

Yeah, that's what I meant with the looping timers.

Quote:
not if you give it a stop order when it has reached its location

Actually, a stop order won't do. What do work, is to use ShowUnitHide and ShowUnitShow. Alternatively, I think that SetUnitPosition works too.
12-29-2006, 03:09 PM#6
oNdizZ
now you really made me confused.
From your first post i assumed you had difficulties getting the unit to 'walk' to the location, and used SetUnitPosition to just teleport it there.

Quote:
Originally Posted by Themerion

Quote:
Originally Posted by oNdizZ
try playing around with
Unit - Order (your_unit) to Move To (a_location)

Yeah, that's what I meant with the looping timers.

Do you mean that snippet uses timers?

And a stop order will do to prevent the unit from walking back again.
12-30-2006, 10:33 AM#7
Themerion
I want a neutral hostile unit to walk to a location and then stay there. The problem is the neutral hostiles tend to stop walking after a certain amount of time; or after a certain distance.

That is why I mentioned a timer, as I can repeatedly tell the units to move to the target location. I thought of something like:

Collapse JASS:
// using CSCache
// The function calls probably are not exactly correct. Just ignore that.

function NeutralHostileWalk_loop_cb takes nothing returns nothing
    // This is where I want the unit to be eventually
    local location loc=GetAttachedLocation(GetEnumUnit(),"end_target")
    local location loc2=GetUnitLoc(GetEnumUnit())
    // This is the closest the unit has been to the point yet.
    local real closest_distance=GetAttachedReal(GetEnumUnit(),"closest_distance")
    local real current_distance=DistanceBetweenPoints(loc,lo2)

    // If the unit is closer than last check, then...
    if(current_distance < distance) then
        call AttachReal(GetEnumUnit(),"closest_distance",current_distance)
        // reset neutral hostile return distance and return timer
        call SetUnitPositionLoc(GetEnumUnit(),loc2)
        call IssuePointOrderLoc(GetEnumUnit(),loc)
    endif

    set loc2=null
    set loc=null
endfunction

// called by a timer
function NeutralHostileWalk_loop takes nothing returns nothing
    call ForGroup(walk_group,function NeutralHostileWalk_loop_cb)
endfunction
12-30-2006, 10:48 AM#8
Jazradel
Isn't that caused by a value in gameplay constants?

Camp Range or something?
12-30-2006, 10:52 AM#9
Themerion
Yes. But those values are supposed to remain as they are. Otherwise the guard-behaviour would be messed up...
12-30-2006, 06:21 PM#10
BertTheJasser
I guess this is the most simple solution of all, and it should work aswell:
Collapse JASS:
function ChangeCreepGuardPositionHome takes unit u,real newx,real newy returns nothing
local real x=GetUnitX(u)
local real y=GetUnitY(u)
call ShowUnit(u,false)
call SetUnitCreepGuard(u,false)
call SetUnitX(u,newx)
call SetUnitY(u,newy)
call SetUnitCreepGuard(u,true)
call SetUnitX(u,x)
call SetUnitY(u,y)
call ShowUnit(u,true)
endfunction

After the "creep return time" is elapsed, the unit will go to the new x/y (just theory, but should work) wich is from now on considered as its "home"

Hope I could help ;D
12-30-2006, 07:42 PM#11
Themerion


Thanks a lot! function SetUnitCreepGuard(unit,boolean) is precisely what I wanted =)
12-30-2006, 10:29 PM#12
Themerion
Actually, the SetUnitX and SetUnitY seem to affect their guarding position as well, making this not work :P

Anyway, being able to turn off their creep behaviour makes it possible to just order them to go to where I want them. When they've reached their destination I turn on the guard behaviour and use SetUnitX(u,GetUnitX(u)) to make them stay there.
12-31-2006, 09:26 AM#13
BertTheJasser
That's bad... maybe give it a try with
Collapse JASS:
call SetUnitPosition(u,x,y)
instead.
Btw. I am not shure if I got the essential meaning of your last post :?
12-31-2006, 11:05 AM#14
Themerion
Sorry for expressing myself badly.

It seems that all kinds of position altering functions will also change neutral hostile guard location.
Collapse JASS:
SetUnitX(args...)
SetUnitY(args...)
SetUnitPosition(args...)
//etc...

What I mean is: now that I can turn off their guard behaviour with SetUnitCreepGuard, I do not need to worry about the creeps forgetting about my orders after X seconds has elapsed ( You know, Neutral Hostile attempts to return after a certain amount of seconds ). In other words, I can simply turn off their guard behaviour, and order them to move to where they ought to be. When they've reached that position, I can turn on the guard behaviour. (and use ShowUnitShow() + ShowUnitHide() to update their creep guard locations)
12-31-2006, 05:33 PM#15
BertTheJasser
Oh.. well, it works, that is (I guess) your primary aim ;D.

Note: Do not use the wrapper functions ShowUnitShow() and it's negative. Simply use this
Collapse JASS:
call ShowUnit(u,false)
to hide and
Collapse JASS:
call ShowUnit(u,true)
to show a unit

Note: You should use x/y coords instead of locations, as you then have no risk of forgetting to destroy a location, which multiplyed with 500 means lag.