local input_time = 3.2 --how long player gets to input the correct key local speed = 1.3 --adjusts player movement speed (note; doesnt effect jumping) local jump_height = 35 --adjusts jump height (along with speed) local jump_speed = 80 --adjust jumping speed (so player moves up quicker) local jump_travel_time = 0.35 --allows player to travel forward a bit once maximum jump height has been reached (before falling) local damage = 50 --how much damage to apply if player misses an input (set to 0 to kill player no matter how much HP he might have) local way_set = 0 pressed = 0 local dead = 0 startx = nil starty = nil startz = nil player = nil checkpoint = nil checkpoint_d = nil checkpoint_i = nil local jumping = 0 local down = 0 local init_height = 0 local new_jump_height = 0 local new_jump_travel_time = 0 local state = "walk" input_time = input_time * 1000 function player_init(e) LoadImages("rail move",0) --folder that holds image Hide(e) CollisionOff(e) ai_soldier_pathindex[e] = -1 ai_path_point_index[e] = -1 player = e end function player_main(e) Hide(e) CollisionOff(e) if startx == nil or starty == nil or startz == nil then startx = g_Entity[e]['x'] starty = g_Entity[e]['y'] startz = g_Entity[e]['z'] end EntObjNo = g_Entity[e]['obj'] ModulateSpeed(e,speed) if g_PlayerHealth > 0 then if state == "walk" then StartTimer(e) -- Try and find a close path to patrol, just check once for it if ai_soldier_pathindex[e] == -1 then ai_soldier_pathindex[e] = -2 CharacterControlArmed(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 < 100 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) SetCharacterToWalk(e) ai_path_point_direction[e] = 1 ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e]) end end if 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(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)) if DistFromPath < 50 then if way_set == 0 then state = "input" end else way_set = 0 end else CharacterControlFidget(e) end if GetScancode() == 57 and pressed == 0 and jumping == 0 then --key to jump (space) pressed = 1 jumping = 1 end if jumping == 1 then if down == 0 then if g_PlayerPosY < new_jump_height then MoveUp(e,jump_speed) else new_jump_travel_time = g_Time + (jump_travel_time * 1000) down = 1 end elseif down == 1 then if g_Time > new_jump_travel_time then down = 2 end else if g_PlayerPosY > init_height then MoveUp(e,-jump_speed) else down = 0 jumping = 0 end end else new_jump_height = g_PlayerPosY + jump_height init_height = g_PlayerPosY end elseif state == "input" then if GetTimer(e) < input_time then ShowImage(0) SetImagePosition(50,50) Panel(39,90,61,99) TextCenterOnX(50,93,3,"Press 'Enter' to change course") TextCenterOnX(50,97,3,math.floor((input_time - GetTimer(e))/1000).."s") --MoveForward(e,-speed) if GetScancode() == 28 and pressed == 0 then --input key for changing direction (return) HideImage(0) pressed = 1 way_set = 1 state = "walk" 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 ai_path_point_index[e] = ai_path_point_max[e] -1 ai_path_point_direction[e] = 0 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 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(EntObjNo,ai_patrol_x[e],ai_patrol_z[e]) end else if damage ~= 0 then HurtPlayer(e,damage) else HurtPlayer(e,g_PlayerHealth) end HideImage(0) pressed = 1 way_set = 1 state = "walk" 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 ai_path_point_index[e] = ai_path_point_max[e] -1 ai_path_point_direction[e] = 0 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 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(EntObjNo,ai_patrol_x[e],ai_patrol_z[e]) end end --state TransportToIfUsed(e) else SetPosition(e,startx,starty,startz) ResetPosition(e,startx,starty,startz) AIEntityGoToPosition(EntObjNo,startx,startz) end if GetScancode() == 0 then pressed = 0 end if g_PlayerHealth < 1 then dead = 1 way_set = 1 HideImage(0) elseif dead == 1 then SetPosition(e,startx,starty,startz) ResetPosition(e,startx,starty,startz) AIEntityGoToPosition(EntObjNo,startx,startz) dead = 2 elseif dead == 2 then if checkpoint == nil then ai_soldier_pathindex[e] = -1 else ai_path_point_index[e] = checkpoint ai_path_point_direction[e] = checkpoint_d ai_soldier_pathindex[e] = checkpoint_i way_set = 0 end state = "walk" dead = 0 end --Prompt(state.." "..ai_path_point_index[e].." "..startx.." "..startz) end