Home / Lua / Tutorials / Intermediate / Example PDA Map

This tutorial assumes you understand the basics of JC-MP modules / scripts. This information is available in the beginner section.
In this tutorial, you'll be able to see the basic uses of loading game assets and making use of them with the Render event to create a Map for your gamemode / script.
Client
class 'PDA'

function PDA:__init( ... )
	self.map = Image.Create( AssetLocation.Game, 'pda_map_dif.dds' )

	-- Resize / set the initial position of the map

	self.map:SetSize( Vector2( Render.Width/2, Render.Width/2 ) )
	self.map:SetPosition( Vector2( Render.Width*.25, Render.Height*.05 ) )

	-- Settings


	-- Some people prefer to render a border around their PDA
	-- I prefer to fill the screen with a water colour, use 
	-- this to toggle.
	self.use_border = true 
	self.border_width = Vector2( 10, 10 )


	-- used to stop our map open input from spamming.
	self.toggle_timer = Timer()

	-- Events

	-- initialize our map render, we'll use this for subscribing to the render event later
	self.map_render = nil

	Events:Subscribe( 'LocalPlayerInput', self, self.PDAInput )
end

function PDA:PDAInput( e )
	local input = e.input
	
	if input == Action.GuiPDA then
		-- Toggle the new PDA map.
		self:Toggle()
		-- Block the game from opening the standard Just Cause 2 PDA map.
		return false
	end

	-- Any inputs you need to process for the map have to go here
	-- before the input lock.


	-- Input lock --
	if self.map_render ~= nil then
		-- Block any game inputs while the map is rendering
		return false
	end

end

function PDA:Toggle( ... )
	if self.toggle_timer:GetMilliseconds() > 250 then
		self.toggle_timer:Restart()

		if self.map_render == nil then

			-- map currently isn't rendering so open the PDA

			self.map_render = Events:Subscribe( 'Render', self, self.PDARender )
			Mouse:SetVisible( true )

		else

			-- map is currently rendering so close the PDA

			Events:Unsubscribe( self.map_render )
			self.map_render = nil
			Mouse:SetVisible( false )

		end
	end
end

function PDA:PDARender( ... )
	if self.map == nil then return end

	if self.use_border then
		--Border Render
		Render:FillArea( self.map:GetPosition()-self.border_width, self.map:GetSize()+self.border_width*2, Color.Black )
	else
		-- Water Render
		Render:FillArea( Vector2.Zero, Render.Size, Color(6,36,47,255) )
	end

	-- Render our map.
	self.map:Draw()


	-- Anything you wish to draw on top of your map goes here.
end


function ModuleLoad( ... )
	pda = PDA()
end

Events:Subscribe( 'ModuleLoad', ModuleLoad )