local state = {} local door = {} function geisel_init(e) state[e] = "wait" ai_soldier_pathindex[e] = -1 end function geisel_main(e) CharacterControlUnarmed(e) if door[e] == nil then for a = 1,1999 do if g_Entity[a] ~= nil then if weapon_name2[a] ~= nil then if weapon_name2[a] == "hostage door" then if GetDistance(e,a) < 400 then door[e] = a break end end end end end else if state[e] == "wait" then CharacterControlDucked(e) if g_Entity[door[e]]['activated'] == 1 then CharacterControlStand(e) SetCharacterToRun(e) RotateToPlayer(e) state[e] = "free" end elseif state[e] =="free" then if GetPlayerDistance(e) < 300 then PromptLocal(e,"Thank you!") end if ai_soldier_pathindex[e] == -1 then ai_soldier_pathindex[e] = -2 CharacterControlUnarmed(e) -- find initial waypoint path to follow PathIndex = -1; pClosest = 99999; for pa = 1, AIGetTotalPaths(), 1 do for po = 1 , AIGetPathCountPoints(pa), 1 do pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po); pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po); pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ)); if pDist < pClosest and pDist < 300 then pClosest = pDist; PathIndex = pa; end end -- po end -- pa -- follow found path if PathIndex > -1 then ai_soldier_pathindex[e] = PathIndex; ai_path_point_index[e] = 2 ModulateSpeed(e,1.0) SetCharacterToRun(e) ai_path_point_direction[e] = 1 ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e]) end elseif ai_soldier_pathindex[e] > -1 then ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e]) ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e]) AIEntityGoToPosition(g_Entity[e]['obj'],ai_patrol_x[e],ai_patrol_z[e]) tDistX = g_Entity[e]['x'] - ai_patrol_x[e] tDistZ = g_Entity[e]['z'] - ai_patrol_z[e] DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ)) if DistFromPath < 70 then if ai_path_point_direction[e] == 1 then ai_path_point_index[e] = ai_path_point_index[e] + 1 if ( ai_path_point_index[e] > ai_path_point_max[e] ) then Hide(e) state[e] = "done" Destroy(e) end else ai_path_point_index[e] = ai_path_point_index[e] - 1 if ( ai_path_point_index[e] < 1 ) then ai_path_point_index[e] = 2 ai_path_point_direction[e] = 1 end end end end end end end function geisel_exit(e) end