Personal tools

Lua/Tutorials/Example PDA Map

From JC2-MP Documentation

< Lua‎ | Tutorials
Jump to: navigation, search

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.


class 'PDA'
function PDA:__init( ... ) = Image.Create( AssetLocation.Game, '' )
	-- Resize / set the initial position of the map Vector2( Render.Width/2, Render.Width/2 ) ) 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 )
function PDA:PDAInput( e )
	local input = e.input
	if input == Action.GuiPDA then
		-- Toggle the new PDA map.
		-- Block the game from opening the standard Just Cause 2 PDA map.
		return false
	-- 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
function PDA:Toggle( ... )
	if self.toggle_timer:GetMilliseconds() > 250 then
		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 )
			-- map is currently rendering so close the PDA
			Events:Unsubscribe( self.map_render )
			self.map_render = nil
			Mouse:SetVisible( false )
function PDA:PDARender( ... )
	if == nil then return end
	if self.use_border then
		--Border Render
		Render:FillArea(,*2, Color.Black )
		-- Water Render
		Render:FillArea( Vector2.Zero, Render.Size, Color(6,36,47,255) )
	-- Render our map.
	-- Anything you wish to draw on top of your map goes here.
function ModuleLoad( ... )
	pda = PDA()
Events:Subscribe( 'ModuleLoad', ModuleLoad )