Code: Select all
nikitaUnit = nil
print("nikitaUnit:", nikitaUnit)
CreateTimer("NikitaPosUpdate")
SetTimerValue("NikitaPosUpdate", 1)
OnCharacterDispenseControllable(
function(player, controllable)
if GetEntityClass(controllable) == FindEntityClass("rep_weap_inf_remotedroid_ord") then
nikitaUnit = controllable
print("nikitaUnit:", nikitaUnit)
StartTimer("NikitaPosUpdate")
end
end
)
OnTimerElapse(
function(timer)
if nikitaUnit then
print("nikitaUnit:", nikitaUnit)
nikitaX,nikitaY,nikitaZ = GetWorldPosition(nikitaUnit)
print("Nikita X: ", nikitaX)
print("Nikita Y: ", nikitaY)
print("Nikita Z: ", nikitaZ)
local teamSize = GetTeamSize(2)
for i = 0, teamSize - 1 do
enemyIndex = GetTeamMember(2,i)
print("Getting Position of Enemy ", enemyIndex)
enemyX,enemyY,enemyZ = GetWorldPosition(GetCharacterUnit(enemyIndex))
print("Enemy X: ", enemyX)
print("Enemy Y: ", enemyY)
print("Enemy Z: ", enemyZ)
if (math.abs(enemyX - nikitaX) <= 32) and (math.abs(enemyY - nikitaZ) <= 32) then
print("Collide with Enemy ", enemyIndex)
KillObject(nikitaUnit)
end
end
end
SetTimerValue("NikitaPosUpdate", 1)
StartTimer("NikitaPosUpdate")
end,
"NikitaPosUpdate"
)
Once the player uses the remote droid, a timer is started. if the remote droid is alive, the function fetches its X,Y,Z coordinates and the X,Y,Z coordinates of every enemy AI. Then it checks for every enemy if the distance between the remote droid and that enemy is below a certain number. If this is true, the remote droid explodes. If this is false, the timer starts anew.
Problem
Everything works fine (as far as I can monitor it with the print commands) up until the point where the remote droid is near an enemy. The math statement is not being executed and I don't get a print entry in the BF2Log. And once the droid gets destroyed through time or an enemy shot, the game crashes.
Does somebody know how to prevent the CTD and make sure the math statement is being checked/executed correctly?