The Driver Syndicate/Scripting/Mission Scripting/Story Missions

From Equilibrium Engine Wiki
Jump to navigation Jump to search

Creating Missions

Here are some examples of how to create missions.

  • "#TAGS or ID" should always be chosen so that it does not create duplicates/conflicts with other mods/addons or the base game! See EqLocalizationTool
  • Weather, time of day and music can be defined separately for each mission.
  • Make sure that you only use environment parameters that are available for the level.
  • If you use vehicles for the mission that are included in community cars, you should mention this in your readme and the mod description. (missing vehicles cause crashes)

Example 1a: Simple drive from A to B mission with timer

The following content belongs in the .lua file for such a mission.

-- Basic Mission Example 1a with cops
--------------------------------------------------------------------------------

world:SetLevelName("levelname") --set levelname here
world:SetEnvironmentName("day_clear") --set weather here
MISSION.MusicScript = "frisco_night" --set music here

MISSION.Init = function()

	--SetMusicState(MUSIC_STATE_PURSUIT)

	MISSION.Data = {
		targetPosition = Vector3D.new(-61.93,40.71,-68.29),
	}    --set mission target here (coordinates)
	
	MISSION.Settings.EnableCops = true  --true / false = enable/disable cops
	
	local playerCar = gameses:CreateCar("mustang", CAR_TYPE_NORMAL) -- set player car here
	
	MISSION.playerCar = playerCar
	
	playerCar:SetMaxDamage(12.0)
	
	-- real
	playerCar:SetOrigin( Vector3D.new(15.20,70.71,67.85) ) --set startingpoint here
	playerCar:SetAngles( Vector3D.new(-180.00,90.00,-180.00) ) --set starting direction here

	playerCar:Spawn()
	playerCar:SetColorScheme( 4 )

	-- for the load time, set player car
	gameses:SetPlayerCar( playerCar )
	
	playerCar:Lock(true)

	gameHUD:Enable(true)
	gameHUD:FadeIn(false, 2.5)
    gameHUD:ShowAlert("#TITLE01", 7, HUD_ALERT_NORMAL) -- set Mission Title in Localization file


	missionmanager:ScheduleEvent( function()
		MISSION.Phase1Start()		
	end, 3 )
end

function MISSION.Phase1Start()

        local playerCar = MISSION.playerCar
        
        gameHUD:Enable(true)
        playerCar:Lock(false)
        
        MISSION.targetHandle = gameHUD:AddMapTargetPoint(MISSION.Data.targetPosition)
    
        -- here we start
        missionmanager:SetRefreshFunc( MISSION.Phase1Update )
    
        gameHUD:ShowScreenMessage("#DESCRIPTION01", 5) -- set Mission Description in Localization file
        
        missionmanager:EnableTimeout( true, 110 ) -- true/false, time (in seconds)
end

function MISSION.OnDone()
        local playerCar = MISSION.playerCar
        
        gameHUD:RemoveTrackingObject(MISSION.targetHandle)
    
		playerCar:Lock(true)
        
        return true
end

MISSION.UpdateAll = function(delta)

	local camera = world:GetView()
	
	local playerCar = MISSION.playerCar
	
	UpdateCops( playerCar, delta )

	-- check player vehicle is wrecked
	if CheckVehicleIsWrecked( playerCar, MISSION.Data, delta ) then
		gameHUD:ShowAlert("#WRECKED_VEHICLE_MESSAGE", 3.5, HUD_ALERT_DANGER)
		
		MISSION.OnDone()
		
		missionmanager:SetRefreshFunc( function() 
			return false 
		end ) 

		gameses:SignalMissionStatus( MIS_STATUS_FAILED, 4.0 )
		return false
	end
	
	if missionmanager:IsTimedOut() then
		gameHUD:ShowAlert("#TIME_UP_MESSAGE", 3.5, HUD_ALERT_DANGER)

		MISSION.OnDone()
		
		missionmanager:SetRefreshFunc( function() 
			return false 
		end ) 
		
		gameses:SignalMissionStatus( MIS_STATUS_FAILED, 4.0 )
		return false
	end
	
	return true
end

MISSION.Phase1Update = function( delta )

	local playerCar = MISSION.playerCar

	local distToTarget = length(playerCar:GetOrigin() - MISSION.Data.targetPosition)
	local playerSpeed = playerCar:GetSpeed()

	if distToTarget < 90.0 then
	
		if playerCar:GetPursuedCount() > 0 then
			gameHUD:ShowScreenMessage("#LOSE_TAIL_MESSAGE", 1.5)
		elseif playerSpeed < 60 then

			if distToTarget < 4.0 then
			
				gameHUD:RemoveTrackingObject(MISSION.targetHandle)
				
				playerCar:Lock(true)
				
				missionmanager:EnableTimeout( false, 80 )
				
				-- TODO: cutscene black bar curtains
				missionmanager:ScheduleEvent( MISSION.OnCompleted, 0 )
			
				missionmanager:SetRefreshFunc( function() 
					return false 
				end ) 
			
				return false
			end
		else
			gameHUD:ShowScreenMessage("#SLOW_DOWN_MESSAGE", 1.0)
		end
	end
	
	return MISSION.UpdateAll(delta)
end

function MISSION.OnCompleted()

	MISSION.OnDone()
	
	missionmanager:SetRefreshFunc( function() 
		return false 
	end ) 
	
	gameses:SignalMissionStatus( MIS_STATUS_SUCCESS, 4.0 )
	
	gameHUD:ShowAlert("#MENU_GAME_TITLE_MISSION_SUCCESS", 2.5, HUD_ALERT_SUCCESS)
	
	gameHUD:ShowScreenMessage("#JOBDONE01", 4) -- set success Text in Localization file
end

The following IDs are specifically designed for this mission and must be specified in a file so that they can be translated into another language.

(#TITLE01, #DESCRIPTION01, #JOBDONE01)

Since this is just an example, you should use other IDs for your own missions to avoid conflicts.

  • Cops are enabled in this example
  • Timer is enabled in this example

See here how to add it to the game!

Example 1b: Simple drive from A to B mission without timer

The following content belongs in the .lua file for such a mission.

-- Basic Mission Example 1b without cops
--------------------------------------------------------------------------------

world:SetLevelName("levelname") --set levelname here
world:SetEnvironmentName("dusk_clear") --set weather here
MISSION.MusicScript = "frisco_day" --set music here

MISSION.Init = function()

	--SetMusicState(MUSIC_STATE_PURSUIT)

	MISSION.Data = {
		targetPosition = Vector3D.new(-619.93,40.71,-683.29),
	}    --set mission target here (coordinates)
	
	MISSION.Settings.EnableCops = false  --true / false = enable/disable cops
	
	local playerCar = gameses:CreateCar("toledocoupe", CAR_TYPE_NORMAL) -- set player car here
	
	MISSION.playerCar = playerCar
	
	playerCar:SetMaxDamage(12.0)
	
	-- real
	playerCar:SetOrigin( Vector3D.new(1598.20,70.71,677.85) ) --set startingpoint here
	playerCar:SetAngles( Vector3D.new(-180.00,90.00,-180.00) ) --set starting direction here

	playerCar:Spawn()
	playerCar:SetColorScheme( 4 )

	-- for the load time, set player car
	gameses:SetPlayerCar( playerCar )
	
	playerCar:Lock(true)

	gameHUD:Enable(true)
	gameHUD:FadeIn(false, 2.5)
    gameHUD:ShowAlert("#TITLE02", 7, HUD_ALERT_NORMAL) -- set Mission Title in Localization file


	missionmanager:ScheduleEvent( function()
		MISSION.Phase1Start()		
	end, 3 )
end

function MISSION.Phase1Start()

        local playerCar = MISSION.playerCar
        
        gameHUD:Enable(true)
        playerCar:Lock(false)
        
        MISSION.targetHandle = gameHUD:AddMapTargetPoint(MISSION.Data.targetPosition)
    
        -- here we start
        missionmanager:SetRefreshFunc( MISSION.Phase1Update )
    
        gameHUD:ShowScreenMessage("#DESCRIPTION02", 5) -- set Mission Description in Localization file
        
        missionmanager:EnableTimeout( false, 90 ) -- enable/false, time (in seconds)
end

function MISSION.OnDone()
        local playerCar = MISSION.playerCar
        
        gameHUD:RemoveTrackingObject(MISSION.targetHandle)
    
		playerCar:Lock(true)
        
        return true
end

MISSION.UpdateAll = function(delta)

	local camera = world:GetView()
	
	local playerCar = MISSION.playerCar
	
	--UpdateCops( playerCar, delta )

	-- check player vehicle is wrecked
	if CheckVehicleIsWrecked( playerCar, MISSION.Data, delta ) then
		gameHUD:ShowAlert("#WRECKED_VEHICLE_MESSAGE", 3.5, HUD_ALERT_DANGER)
		
		MISSION.OnDone()
		
		missionmanager:SetRefreshFunc( function() 
			return false 
		end ) 

		gameses:SignalMissionStatus( MIS_STATUS_FAILED, 4.0 )
		return false
	end
	
	if missionmanager:IsTimedOut() then
		gameHUD:ShowAlert("#TIME_UP_MESSAGE", 3.5, HUD_ALERT_DANGER)

		MISSION.OnDone()
		
		missionmanager:SetRefreshFunc( function() 
			return false 
		end ) 
		
		gameses:SignalMissionStatus( MIS_STATUS_FAILED, 4.0 )
		return false
	end
	
	return true
end

MISSION.Phase1Update = function( delta )

	local playerCar = MISSION.playerCar

	local distToTarget = length(playerCar:GetOrigin() - MISSION.Data.targetPosition)
	local playerSpeed = playerCar:GetSpeed()

	if distToTarget < 90.0 then
	
		if playerCar:GetPursuedCount() > 0 then
			gameHUD:ShowScreenMessage("#LOSE_TAIL_MESSAGE", 1.5)
		elseif playerSpeed < 60 then

			if distToTarget < 4.0 then
			
				gameHUD:RemoveTrackingObject(MISSION.targetHandle)
				
				playerCar:Lock(true)
				
				missionmanager:EnableTimeout( false, 80 )
				
				-- TODO: cutscene black bar curtains
				missionmanager:ScheduleEvent( MISSION.OnCompleted, 0 )
			
				missionmanager:SetRefreshFunc( function() 
					return false 
				end ) 
			
				return false
			end
		else
			gameHUD:ShowScreenMessage("#SLOW_DOWN_MESSAGE", 1.0)
		end
	end
	
	return MISSION.UpdateAll(delta)
end

function MISSION.OnCompleted()

	MISSION.OnDone()
	
	missionmanager:SetRefreshFunc( function() 
		return false 
	end ) 
	
	gameses:SignalMissionStatus( MIS_STATUS_SUCCESS, 4.0 )
	
	gameHUD:ShowAlert("#MENU_GAME_TITLE_MISSION_SUCCESS", 2.5, HUD_ALERT_SUCCESS)
	
	gameHUD:ShowScreenMessage("#JOBDONE02", 4) -- set success Text in Localization file
end

The following IDs are specifically designed for this mission and must be specified in a file so that they can be translated into another language.

(#TITLE02, #DESCRIPTION02, #JOBDONE02)

Since this is just an example, you should use other IDs for your own missions to avoid conflicts.

  • Cops are disabled in this example
  • Timer is disabled in this example

See here how to add it to the game!

Example 2: Following a car to its destination

ToDo:

see here how to add it to the game

How to add the missions to the Game/Mod

ToDo:

See Also

The Driver Syndicate/Scripting/Mission Scripting

The Driver Syndicate/Scripting/Lua Reference

The Driver Syndicate/Addon System

Engine Tools/EqLocalizationTool