Skip to content

Commit

Permalink
Merge pull request #5663 from SOZ-Faut-etre-Sub/fix/cayo-map
Browse files Browse the repository at this point in the history
Always display Cayo may with ExtraMapTiles lib
  • Loading branch information
NariieL authored Dec 4, 2023
2 parents f790373 + 2da4707 commit 40d782e
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 50 deletions.
Binary file added resources/[lib]/ExtraMapTiles/MINIMAP_LOADER.gfx
Binary file not shown.
303 changes: 303 additions & 0 deletions resources/[lib]/ExtraMapTiles/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
-- DO NOT MODIFY!
vBitmapTileSizeX = 4500.0
vBitmapTileSizeY = 4500.0
vBitmapStartX = -4140.0
vBitmapStartY = 8400.0

-- Overlay ID.
overlay = 0

-- Will store the keys of the currently drawn tiles.
drawnTiles = {}

-- List to store the dummy blip handles.
dummyBlips = {}

-- Function that will create a new tile.
function createTile(tileName)


-- Early exit for invalid tile name.
if extraTiles[tileName] == nil then
return
end

-- Get the tile's object.
local extraTile = extraTiles[tileName]

if extraTile.txd == nil or extraTile.txn == nil then
return
end



-- Get the texture info, alpha, centering and rotation.
local textureDictionary = extraTile.txd
local textureName = extraTile.txn
local alpha = extraTile.alpha or defaultAlpha
local centered = extraTile.centered or false
local rotation = extraTile.rotation or 0.0

-- Load the required texture.
loadTextureDictionary(textureDictionary)

-- Get the width and height of the texture.
local xTexture, yTexture, _ = table.unpack(GetTextureResolution(textureDictionary, textureName))

-- Compute the scale ratios.
local xScale = vBitmapTileSizeX / xTexture * 100
local yScale = vBitmapTileSizeY / yTexture * 100

-- Tile was configurated to use XY coordinates.
if extraTile.x ~= nil and extraTile.y ~= nil then

-- Compute offsets from given coordinates since other functionalities
-- such as extendPauseMenuMapBounds() work with offsets, not with XY coords directly.
extraTile.xOffset = (extraTile.x - vBitmapStartX) / vBitmapTileSizeX
extraTile.yOffset = (extraTile.y - vBitmapStartY) / vBitmapTileSizeY
end


-- Get the offsets, convert to float.
local xOffset = extraTile.xOffset * 1.0
local yOffset = extraTile.yOffset * (-1.0)


-- Compute X and Y coordinates based on the offsets.
local x = vBitmapStartX + xOffset * vBitmapTileSizeX
local y = vBitmapStartY - yOffset * vBitmapTileSizeY



-- Convert alpha to an INT.
alpha = math.floor(math.abs(alpha))
-- Convert rotation to FLOAT.
rotation = rotation * 1.0

-- Call the Scaleform function.
CallMinimapScaleformFunction(overlay, "ADD_SCALED_OVERLAY")
-- Push the parameters onto the stack.
ScaleformMovieMethodAddParamTextureNameString(textureDictionary)
ScaleformMovieMethodAddParamTextureNameString(textureName)
ScaleformMovieMethodAddParamFloat(x)
ScaleformMovieMethodAddParamFloat(y)
ScaleformMovieMethodAddParamFloat(rotation)
ScaleformMovieMethodAddParamFloat(xScale)
ScaleformMovieMethodAddParamFloat(yScale)
ScaleformMovieMethodAddParamInt(alpha)
ScaleformMovieMethodAddParamBool(centered)
EndScaleformMovieMethod()

-- Mark the texture as no longer needed.
SetStreamedTextureDictAsNoLongerNeeded(textureDictionary)

-- Add it to the drawn tiles table.
table.insert(drawnTiles, tileName)
end

-- Function that deletes a tile.
function deleteTile(tileName)

local id = -1

for i = 1, #drawnTiles do
if drawnTiles[i] == tileName then
id = i
table.remove(drawnTiles, id)
break
end
end

if id == -1 then
return
end

-- Call the remove scaleform function.
CallMinimapScaleformFunction(overlay, "REM_OVERLAY");
-- Push the parameter onto the stack.
ScaleformMovieMethodAddParamInt(id - 1)
EndScaleformMovieMethod()
end

-- Function that will draw all tiles in the extraTiles table.
function createAllTiles()

local extraTilesNames = getTableKeys(extraTiles)
if extraTilesNames == nil then
return
end

-- Iterate all extra tiles.
for i = 1, #extraTilesNames do

-- Get the current tile's key.
local tileName = extraTilesNames[i]

-- Create the new tile.
createTile(tileName)
end

if #dummyBlips == 0 then
extendPauseMenuMapBounds()
end
end

-- Function that will delete all tiles that are currently drawn.
function deleteAllTiles()

-- Delete the tile at index 1. The table will shift the remaining
-- elements' indices.
for i = 1, #drawnTiles do
deleteTile(drawnTiles[1])
end

if #dummyBlips ~= 0 then
resetPauseMenuMapBounds()
end
end

-- Function that returns true if the tile with the specified name is currently drawn
-- or false otherwise.
function isTileDrawn(tileName)
if tileName == nil then
return false
end

for i = 1, #drawnTiles do
if drawnTiles[i] == tileName then
return true
end
end

return false
end

-- Function that will let you move outside the normal bounds of the
-- pause menu map.
function extendPauseMenuMapBounds()

if #dummyBlips ~= 0 then
resetPauseMenuMapBounds()
end


local extraTilesNames = drawnTiles
if extraTilesNames == nil then
return
end

-- Set starting values.
local xMinOffset = extraTiles[extraTilesNames[1]].xOffset or 0
local xMaxOffset = extraTiles[extraTilesNames[1]].xOffset or 0
local yMinOffset = extraTiles[extraTilesNames[1]].yOffset or 0
local yMaxOffset = extraTiles[extraTilesNames[1]].yOffset or 0

-- Find min and max values for xOffset and yOffset.
for i = 1, #extraTilesNames do
local extraTile = extraTiles[extraTilesNames[i]]

if extraTile.xOffset < xMinOffset then
xMinOffset = extraTile.xOffset
end

if extraTile.xOffset > xMaxOffset then
xMaxOffset = extraTile.xOffset
end

if extraTile.yOffset < yMinOffset then
yMinOffset = extraTile.yOffset
end

if extraTile.yOffset > yMaxOffset then
yMaxOffset = extraTile.yOffset
end
end

-- Create 4 invisible blips at the corners of the furthest tiles
-- to create something like a bounding box in which all other
-- tiles are included. This could possibly be improved to use 2
-- blips instead of 4.

createDummyBlip(vBitmapStartX + xMinOffset * vBitmapTileSizeX - vBitmapTileSizeX / 2,
vBitmapStartY + yMaxOffset * vBitmapTileSizeY + vBitmapTileSizeY / 2)

createDummyBlip(vBitmapStartX + xMinOffset * vBitmapTileSizeX - vBitmapTileSizeX / 2,
vBitmapStartY + (yMinOffset - 1) * vBitmapTileSizeY - vBitmapTileSizeY / 2)

createDummyBlip(vBitmapStartX + (xMaxOffset + 1) * vBitmapTileSizeX + vBitmapTileSizeX / 2,
vBitmapStartY + (yMinOffset - 1) * vBitmapTileSizeY - vBitmapTileSizeY / 2)

createDummyBlip(vBitmapStartX + (xMaxOffset + 1) * vBitmapTileSizeX + vBitmapTileSizeX / 2,
vBitmapStartY + yMaxOffset * vBitmapTileSizeY + vBitmapTileSizeY / 2)
end

-- This function will reset the pause menu map's bounds to the default.
function resetPauseMenuMapBounds()
for i = 1, #dummyBlips do
RemoveBlip(dummyBlips[i])
end

dummyBlips = {}
end

-- Function that will create an invisible blip.
function createDummyBlip(x, y)
local dummyBlip = AddBlipForCoord(x, y, 1.0)
SetBlipDisplay(dummyBlip, 4)
SetBlipAlpha(dummyBlip, 0)

table.insert(dummyBlips, dummyBlip)
end

-- Loads a minimap overlay from a given path.
function loadMinimapOverlay(gfxFilePath)
local _overlay = AddMinimapOverlay(gfxFilePath)

while not HasMinimapOverlayLoaded(_overlay) do
Citizen.Wait(0)
end

SetMinimapOverlayDisplay(_overlay, 0.0, 0.0, 100.0, 100.0, 100.0)

return _overlay
end

-- Loads a texture dictionary into memory.
function loadTextureDictionary(textureDictionary)
if not HasStreamedTextureDictLoaded(textureDictionary) then
RequestStreamedTextureDict(textureDictionary, false)
while not HasStreamedTextureDictLoaded(textureDictionary) do
Citizen.Wait(0)
end
end
end

-- Function that converts the keys of a dictionary to an alphabetically-sorted list.
function getTableKeys(keyset)
local list = {}

for key, _ in pairs(keyset) do
table.insert(list, key)
end

table.sort(list)

return list
end

exports("createAllTiles", createAllTiles)
exports("deleteAllTiles", deleteAllTiles)
exports("createTile", createTile)
exports("deleteTile", deleteTile)
exports("extendPauseMenuMapBounds", extendPauseMenuMapBounds)
exports("resetPauseMenuMapBounds", resetPauseMenuMapBounds)
exports("isTileDrawn", isTileDrawn)


Citizen.CreateThread(function()
-- Load the minimap overlay.
overlay = loadMinimapOverlay("MINIMAP_LOADER.gfx")

-- Draw all tiles.
createAllTiles()
end)
53 changes: 53 additions & 0 deletions resources/[lib]/ExtraMapTiles/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--[[
This is the offsets table. This tells the script where to create new map tiles.
The origin point from which offset positions are calculated is defined by the
vBitmapStartX and vBitmapStartY, same as in the minimap.ymt file. Do not modify
the vBitmapStartX and vBitmapStartY, or the script will not function correctly.
The keys of each tile can be arbitrary, maybe something so you can identify them,
but they have to be unique.
xOffset represents the number of tiles away from the origin point to place the new
tile on the X axis. A positive xOffset will place the new tile to the right of the
origin on the X axis and to the left for negative values.
Same for yOffset, but on the Y axis. Positive values place it above the origin and
negative values place it below the origin point.
If needed, xOffset and yOffset you can omit the xOffset and yOffset fields and use
just x and y fields that represent in-game XY coordinates.
Remember that the anchor point of all new tiles is the top left corner of the tile,
unless setting centered to true.
Other optional fields include are:
- alpha: sets the alpha of the tile. Ranges from 0 to 100.
- rotation: Sets the rotation of the tile in a clockwise direction. Ranges from 0 to 360.
- centered: Sets the tile in the center of the chosen point. Can be true or false.
Important: By default, one tile's dimensions are 4500x4500. This is useful when creating
a grid of tiles using in-game XY coordinates so that you can perfectly align them together.
]]

-- Extra tiles can be placed at any offets, they don't have to be "connected" to the default
-- map's tiles.
extraTiles = {
[1] = {x = 4730.0, y = -5145.0, txd = "tile_cayo", txn = "cayo", centered = true},

-- 2 tiles in the top left corner of the default map.
--[1] = {xOffset = -1, yOffset = 1, txd = "minimap_extra_tile_1", txn = "extra_tile_1"},
--[2] = {xOffset = -2, yOffset = 1, txd = "minimap_extra_tile_1", txn = "extra_tile_1", alpha = 50},

-- Another tile in the middle, on the right side of the default map, but rotated 25 degrees clockwise
--[3] = {xOffset = 2, yOffset = 0, txd = "minimap_extra_tile_2", txn = "extra_tile_2", alpha = 70, rotation = 25},

-- Tiles created using in game coordinates instead of offsets.
--[4] = {x = 0.0, y = 0.0, txd = "minimap_extra_tile_1", txn = "extra_tile_1", centered = true},
--[5] = {x = 4500.0, y = 0.0, txd = "minimap_extra_tile_1", txn = "extra_tile_1"},
}


-- Default alpha value that will be used if not specified in the extraTiles table.
defaultAlpha = 100
20 changes: 20 additions & 0 deletions resources/[lib]/ExtraMapTiles/fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Manifest data.
fx_version "cerulean"
games {"gta5"}
lua54 "yes"

-- Resource information.
name "Extra Map Tiles"
description "Adds extra tiles for textures on the minimap and pause menu map."
version "1.2.0"
author "L1CKS"

-- Files.
files {
"MINIMAP_LOADER.gfx" -- Always first in the list.
}

client_scripts {
"config.lua",
"client.lua"
}
Binary file not shown.
Loading

0 comments on commit 40d782e

Please sign in to comment.