-- LUA Script - precede every function and global member with lowercase name of script --adjusts pause when at end of path (waypoints) local wait_time = 1500 --set the speed of the platforms via their 'name' and their "size" by their 'strength' local move_speed = {} local at_node = {} local on_plat_range = {} g_floating_platform_activated = {} g_floating_platform_associateplayer = {} local jumped = 0 local old_time = {} local old_plat_dist = {} local modx = {} local modz = {} local pNewX = {} local pNewY = {} local pNewZ = {} function floating_platform2_init_name(e,name) move_speed[e] = tonumber(name) if move_speed[e] == nil then move_speed[e] = 1 end ai_soldier_state[e] = "patrol"; ai_soldier_pathindex[e] = -1; at_node[e] = 0 old_time[e] = 0 ai_path_point_max[e] = 0 g_floating_platform_activated[e] = 0 g_floating_platform_associateplayer[e] = 0 old_plat_dist[e] = 0 end function floating_platform2_main(e) if on_plat_range[e] == nil then if g_Entity[e]['health'] > 59 then on_plat_range[e] = g_Entity[e]['health'] else on_plat_range[e] = 80 end end CollisionOn(e) if ai_soldier_state[e] == "patrol" then if ai_soldier_pathindex[e] == -1 then ai_soldier_pathindex[e] = -2 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 < 200 then pClosest = pDist; PathIndex = pa; end end end if PathIndex > -1 then ai_soldier_pathindex[e] = PathIndex; ai_path_point_index[e] = 2 ai_path_point_direction[e] = 1 ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e]) end end PlayerDist = GetPlayerDistance(e) if PlayerDist < on_plat_range[e] and g_PlayerHealth > 0 and at_node[e] == 0 then g_floating_platform_activated[e] = 1 g_floating_platform_associateplayer[e] = 1 if pNewX[e] == nil then pNewX[e] = g_PlayerPosX pNewZ[e] = g_PlayerPosZ end end if g_floating_platform_activated[e] == 1 and ai_soldier_pathindex[e] > -1 then -- move to current node 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]) EntObjNo = g_Entity[e]['obj']; RotateToPoint(e,ai_patrol_x[e],ai_patrol_z[e]) AIEntityGoToPosition(EntObjNo,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)) tIncX = tDistX / DistFromPath tIncZ = tDistZ / DistFromPath if at_node[e] == 0 then modx[e] = (tIncX*move_speed[e]) modz[e] = (tIncZ*move_speed[e]) tNewX = g_Entity[e]['x'] - modx[e] tNewY = g_Entity[e]['y'] tNewZ = g_Entity[e]['z'] - modz[e] -- Associate Player with this moving entity platform ResetPosition ( e, tNewX, tNewY, tNewZ ) CollisionOff(e) --MoveForward(e,move_speed*200) CollisionOn(e) end if (g_KeyPressW == 1 or g_KeyPressS == 1 or g_KeyPressA == 1 or g_KeyPressD == 1 or GetScancode() == 200 or GetScancode() == 203 or GetScancode() == 205 or GetScancode() == 208) then if GetPlayerDistance(e) < on_plat_range[e] then g_floating_platform_associateplayer[e] = 0 end end if g_floating_platform_associateplayer[e] == 1 then pNewX[e] = pNewX[e] - modx[e] pNewY[e] = g_PlayerPosY pNewZ[e] = pNewZ[e] - modz[e] SetFreezePosition ( pNewX[e], pNewY[e], pNewZ[e] ) TransportToFreezePositionOnly() else pNewX[e] = g_PlayerPosX pNewZ[e] = g_PlayerPosZ end -- When reach node, decide where to go next if at_node[e] == 1 then g_floating_platform_associateplayer[e] = 0 if GetTimer(e) > wait_time then ai_path_point_index[e] = ai_path_point_max[e] -1 ai_path_point_direction[e] = 0 at_node[e] = 0 end elseif at_node[e] == 2 then g_floating_platform_associateplayer[e] = 0 if GetTimer(e) > wait_time then ai_path_point_index[e] = 2 ai_path_point_direction[e] = 1 at_node[e] = 0 end end if DistFromPath < 50 then StartTimer(e) 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 at_node[e] = 1 end else ai_path_point_index[e] = ai_path_point_index[e] - 1 if ( ai_path_point_index[e] < 1 ) then at_node[e] = 2 end end else if g_KeyPressSPACE == 1 then g_floating_platform_associateplayer[e] = 0 old_time[e] = g_Time jumped = 1 elseif jumped == 1 then g_floating_platform_associateplayer[e] = 0 if g_Time > old_time[e] + 800 then jumped = 0 end end end end end --Prompt(at_node[e].." "..GetTimer(e).." "..ai_path_point_index[e].." "..ai_path_point_max[e].." "..wait_time) end function RotateToPoint(e,x,z) if g_Entity[e] ~= nil and x > 0 and z > 0 then local destx = x - g_Entity[e]['x'] local destz = z - g_Entity[e]['z'] local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle < 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end SetRotation(e,0,angle,0) return angle end end