Hi,
I have heroes owned by Neutral Hostile, that are controlled by an AI script state machine that I wrote. Every iteration of the logic they check if they are alive or not first before entering any other state.
I have included more code than necessary for clarity the actual problem is that ReviveHeroLoc is not working for me I am using this in the Respawn function at the bottom of this post if you want to skip ahead.
The alive state is checked by the following function
if this returns false then it enters this code
On the first entry into this code we will be in another state so currentState will not == dead so it will execute the else first
On the second entry into this code currentState is dead because we transitioned into it in the previous iteration so it will execute the first statement and call respawn. Switching states returns a delay in seconds which in the dead state transition is unitlevel * 5 + 1
if state is dead which it will be on the 2nd visit to the statement then call respawn
At the end of each state check it restarts the logic after a set duration by calling TimerUtils
hope this is making sense so far
The respawn function is fairly simple it picks a home base position to respawn at if it isn't already set then calls ReviveHeroLoc for the dead hero at that position my problem is this seems to return false and doesn't revive the hero
The debug calls seem to indicate that the heroes die echo the correct amount of time to respawn, swap states to dead correctly the respawn function is called ok. Inside the respawn function, the home base is a valid position, the hero is not null tested with the GetHeroProperName call but still the ReviveHeroLoc call returns false and does not respawn the hero
After this things tend to repeat as the first logic check is IsAlive which returns false since the hero didn't actually revive then it goes back to step one where the unit isn't alive and isn't in the dead state since we transition back to searching in the respawn function
So does anyone know why ReviveHeroLoc is returning false? and not actually respawning nuetral hostile owned heroes
Thanks for any help
I have heroes owned by Neutral Hostile, that are controlled by an AI script state machine that I wrote. Every iteration of the logic they check if they are alive or not first before entering any other state.
I have included more code than necessary for clarity the actual problem is that ReviveHeroLoc is not working for me I am using this in the Respawn function at the bottom of this post if you want to skip ahead.
The alive state is checked by the following function
JASS:
private function isAlive takes unit aUnit returns boolean
if(aUnit != null and GetWidgetLife(aUnit) > 0.405) then
return true
endif
return false
endfunction
JASS:
if(currentState[id] == dead) then
debug call DisplayTextToForce( GetPlayersAll(), "Id="+I2S(id)+" dead limit expired, calling respawn")
call Respawn(id)
else
set duration = transitionToState(id,dead)
debug call DisplayTextToForce( GetPlayersAll(), "Id="+I2S(id)+" is dead, waiting for respawn in "+I2S(duration)+" seconds!")
endif
On the second entry into this code currentState is dead because we transitioned into it in the previous iteration so it will execute the first statement and call respawn. Switching states returns a delay in seconds which in the dead state transition is unitlevel * 5 + 1
if state is dead which it will be on the 2nd visit to the statement then call respawn
At the end of each state check it restarts the logic after a set duration by calling TimerUtils
JASS:
call TimerStart(NewTimerEx(id),duration,false,function AILoop)
hope this is making sense so far
The respawn function is fairly simple it picks a home base position to respawn at if it isn't already set then calls ReviveHeroLoc for the dead hero at that position my problem is this seems to return false and doesn't revive the hero
JASS:
private function Respawn takes integer id returns nothing
local location position
debug local boolean respawnResult = false
if(homeBase[id] == null) then
set position = GetUnitLoc(heroes[id])
set homeBase[id] = Spice_GetClosestSpice(position)
call RemoveLocation(position)
endif
set position = GetUnitLoc(homeBase[id])
set respawnResult = ReviveHeroLoc(heroes[id],position,false)
debug if(respawnResult == true) then
debug call DisplayTextToForce( GetPlayersAll(), "Id="+I2S(id)+" named "+GetHeroProperName(heroes[id])+" is respawned, respawn call returned true at x"+R2S(GetLocationX(position))+" y"+R2S(GetLocationY(position)))
debug else
debug call DisplayTextToForce( GetPlayersAll(), "Id="+I2S(id)+" named "+GetHeroProperName(heroes[id])+" is respawned, respawn call returned false at x"+R2S(GetLocationX(position))+" y"+R2S(GetLocationY(position)))
debug endif
call RemoveLocation(position)
set position = null
call transitionToState(id,searching)
endfunction
After this things tend to repeat as the first logic check is IsAlive which returns false since the hero didn't actually revive then it goes back to step one where the unit isn't alive and isn't in the dead state since we transition back to searching in the respawn function
So does anyone know why ReviveHeroLoc is returning false? and not actually respawning nuetral hostile owned heroes
Thanks for any help
Last edited: