Jump to content

Little help with unloading custom radar textures


koragg

Recommended Posts

So thanks to @Stroth (who gave me link) I now have this cool looking radar but I have a problem with the edits I wanna do to it. I want to make it toggleable by two commands: "on" and "off", so that each player can enable or disable it if they wish to do so. I've done a lot of those on/off functions until now and thought it'll be easy but with radar textures it's a bit different than with dxdraw I guess. Here's the code below (I combined both scripts in one file), hope someone who is more familiar with shaders and textures can help me out to achieve the things I want.

local tiles = { }
local timer
local enabled = true

local ROW_COUNT = 12

--# Textures table

local blips_textures = {
  { "arrow", "blips/arrow.png" },
  { "radardisc", "blips/radardisc.png" },
  { "radar_airYard", "blips/radar_airYard.png" },
  { "radar_ammugun", "blips/radar_ammugun.png" },
  { "radar_barbers", "blips/radar_barbers.png" },
  { "radar_BIGSMOKE", "blips/radar_BIGSMOKE.png" },
  { "radar_boatyard", "blips/radar_boatyard.png" },
  { "radar_bulldozer", "blips/radar_bulldozer.png" },
  { "radar_burgerShot", "blips/radar_burgerShot.png" },
  { "radar_cash", "blips/radar_cash.png" },
  { "radar_CATALINAPINK", "blips/radar_CATALINAPINK.png"},
  { "radar_centre", "blips/radar_centre.png" },
  { "radar_CESARVIAPANDO", "blips/radar_CESARVIAPANDO.png" },
  { "radar_chicken", "blips/radar_chicken.png" },
  { "radar_CJ", "blips/radar_CJ.png" },
  { "radar_CRASH1", "blips/radar_CRASH1.png" },
  { "radar_dateDisco", "blips/radar_dateDisco.png" },
  { "radar_dateDrink", "blips/radar_dateDrink.png" },
  { "radar_dateFood", "blips/radar_dateFood.png" },
  { "radar_diner", "blips/radar_diner.png" },
  { "radar_emmetGun", "blips/radar_emmetGun.png" },
  { "radar_enemyAttack", "blips/radar_enemyAttack.png" },
  { "radar_fire", "blips/radar_fire.png" },
  { "radar_Flag", "blips/radar_Flag.png" },
  { "radar_gangB", "blips/radar_gangB.png" },
  { "radar_gangG", "blips/radar_gangG.png" },
  { "radar_gangN", "blips/radar_gangN.png" },
  { "radar_gangP", "blips/radar_gangP.png" },
  { "radar_gangY", "blips/radar_gangY.png" },
  { "radar_girlfriend", "blips/radar_girlfriend.png" },
  { "radar_gym", "blips/radar_gym.png" },
  { "radar_hostpital", "blips/radar_hostpital.png" },
  { "radar_impound", "blips/radar_impound.png" },
  { "radar_light", "blips/radar_light.png" },
  { "radar_LocoSyndicate", "blips/radar_LocoSyndicate.png" },
  { "radar_MADDOG", "blips/radar_MADDOG.png" },
  { "radar_mafiaCasino", "blips/radar_mafiaCasino.png" },
  { "radar_MCSTRAP", "blips/radar_MCSTRAP.png" },
  { "radar_modGarage", "blips/radar_modGarage.png" },
  { "radar_north", "blips/radar_north.png" },
  { "radar_OGLOC", "blips/radar_OGLOC.png" },
  { "radar_pizza", "blips/radar_pizza.png" },
  { "radar_police", "blips/radar_police.png" },
  { "radar_propertyG", "blips/radar_propertyG.png" },
  { "radar_propertyR", "blips/radar_propertyR.png" },
  { "radar_qmark", "blips/radar_qmark.png" },
  { "radar_race", "blips/radar_race.png" },
  { "radar_runway", "blips/radar_runway.png" },
  { "radar_RYDER", "blips/radar_RYDER.png" },
  { "radar_saveGame", "blips/radar_saveGame.png" },
  { "radar_school", "blips/radar_school.png" },
  { "radar_spray", "blips/radar_spray.png" },
  { "radar_SWEET", "blips/radar_SWEET.png" },
  { "radar_tattoo", "blips/radar_tattoo.png" },
  { "radar_THETRUTH", "blips/radar_THETRUTH.png" },
  { "radar_TORENO", "blips/radar_TORENO.png" },
  { "radar_TorenoRanch", "blips/radar_TorenoRanch.png" },
  { "radar_triads", "blips/radar_triads.png" },
  { "radar_triadsCasino", "blips/radar_triadsCasino.png" },
  { "radar_truck", "blips/radar_truck.png" },
  { "radar_tshirt", "blips/radar_tshirt.png" },
  { "radar_waypoint", "blips/radar_waypoint.png" },
  { "radar_WOOZIE", "blips/radar_WOOZIE.png" },
  { "radar_ZERO", "blips/radar_ZERO.png" },
  { "siteM16", "blips/siteM16.png" },
  { "siterocket", "blips/siterocket.png" }
}

function toggleCustomTiles ( )
	for i = 2, #blips_textures do
    local shader = dxCreateShader("texture.fx")
        engineApplyShaderToWorldTexture(shader, blips_textures[i][1])
        dxSetShaderValue(shader, "gTexture", dxCreateTexture(blips_textures[i][2]))
    end
	disabled = not enabled
	    if ( enabled ) then
		    handleTileLoading ( )
		        timer = setTimer ( handleTileLoading, 500, 0 )
	    else
		    if isTimer ( timer ) then killTimer ( timer ) end
		        for name, data in pairs ( tiles ) do
			        unloadTile ( name )
		        end
	       end
	end
addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), toggleCustomTiles)

function handleTileLoading ( )
	local visibleTileNames = table.merge ( engineGetVisibleTextureNames ( "radar??" ), engineGetVisibleTextureNames ( "radar???" ) )
	    for name, data in pairs ( tiles ) do
		    if not table.find ( visibleTileNames, name ) then
			    unloadTile ( name )
		    end
	    end
	for index, name in ipairs ( visibleTileNames ) do
		loadTile ( name )
	end
end

function table.merge ( ... )
	local ret = { }
	    for index, tbl in ipairs ( {...} ) do
		    for index, val in ipairs ( tbl ) do
			    table.insert ( ret, val )
		    end
	    end
	return ret
end

function table.find ( tbl, val )
	for index, value in ipairs ( tbl ) do
		if ( value == val ) then
			return index
		end
	end
	
	return false
end

function loadTile ( name )
	if type ( name ) ~= "string" then
		return false
	end
	
	if ( tiles[name] ) then
		return true
	end
	
	local id = tonumber ( name:match ( "%d+" ) )
	
	if not ( id ) then
		return false
	end
	
	local row = math.floor ( id / ROW_COUNT )
	local col = id - ( row * ROW_COUNT )
	
	local posX = -3000 + 500 * col
	local posY =  3000 - 500 * row
	
	local file = string.format ( "sattelite/sattelite_%d_%d.png", row, col )

	local texture = dxCreateTexture ( file )
	if not ( texture ) then
		outputChatBox ( string.format ( "Failed to load texture for %q (%q)", tostring ( name ), tostring ( file ) ) )
		return false
	end
	
	local shader = dxCreateShader ( "texreplace.fx" )
	
	if not ( shader ) then
		outputChatBox ( "Failed to load shader" )
		destroyElement ( texture )
		return false
	end
	
	dxSetShaderValue ( shader, "gTexture", texture )
	engineApplyShaderToWorldTexture ( shader, name )
	tiles[name] = { shader = shader, texture = texture }
	return true
end

function unloadTile ( name )
	local tile = tiles[name]
	    if not ( tile ) then
		    return false
	    end
	if isElement ( tile.shader )  then destroyElement ( tile.shader )  end
	if isElement ( tile.texture ) then destroyElement ( tile.texture ) end
	
	tiles[name] = nil
	return true
end

Above is original code from author but what I did in my attempt to edit it was that I changed "onClientResourceStart" to "onClientRender" and added two functions to check if 'enabled' is true or not, that way radar would be turned on "if enabled = true" and turned off "if enabled = false" but I had extreme lag after using the commands. That's because I haven't properly unloaded all shaders/textures which the resource loads. So I decided to just post the original, clean script above and see what ideas you guys may have to make this happen. Cheers :)

Edited by koragg
Link to comment
11 minutes ago, koragg said:

I had extreme lag after using the commands. That's because I haven't properly unloaded all shaders/textures which the resource loads.

I don't think the lags are caused by the not unloaded textures or similar. It's because there's something failing, and probably in the render handler function.

PS: i don't have read your code xD, i posted because some loaded texture will not make lags, failing functions and big tasks do.

Link to comment

First you need to save al the shaders, at line 77:

local shaders = {}

at line 80 change to:

shaders[i] = dxCreateShader("texture.fx")

and add the toggle function:

local toggle = true
function toggleradar()
  toggle = not toggle
  if toggle then
    for i = 2, #blips_textures do
        engineApplyShaderToWorldTexture(shaders[i], blips_textures[i][1])
        dxSetShaderValue(shaders[i], "gTexture", dxCreateTexture(blips_textures[i][2]))
    end
  else
    for i = 2, #blips_textures do
        engineRemoveShaderFromWorldTexture ( shaders[i], blips_textures[i][1] )
    end
  end
  
end

not tested but should be ok.

33 minutes ago, koragg said:


@Stroth

 I changed "onClientResourceStart" to "onClientRender"

I don't think that this is ever a good idea...

  • Like 1
Link to comment

@Wojak I got this with your way

5lgM1z2.png

36 minutes ago, LoPollo said:

so there's not only "lag", the fps will decrease... so there's a leak. How is the "structure" of the render handler? something like 

check if enabled

show or hide default radar

show or not the custom radar

?

In main function what I did was:

if visible then
  //code which loads custom radar

And in two seperate functions:

function radaron()
  visible = true
end
addCommandHandler("on", radaron)

function radaroff()
  if visible then
    visible = false
  end
end
addCommandHandler("off", radaroff)

Some parts of the custom radar unloaded (not all) and the fps drop started after typing the "off" command. Then if I type the "on" command fps increased a bit but was still bad.

Link to comment

@LoPollo yes I saw that later and fixed xD Don't know why it said function's nil as it was there and @Wojak, yes I replaced that and worked. Then it didn't unload the minimap images when I typed "off" command (as they're not shaders, just the radar outline and blips are shaders apparently) so I had to edit a bit more. Now everything works and there's no lag, fps drop or any kind of problems. Thanks to both of you, now I can easily add a switch checkbox to my (MrGreen's) settings panel. Working code (with commands) below: :mrgreen:

local tiles = {}
local timer
local visible = true

local ROW_COUNT = 12

--# Textures table

local blips_textures = {
  { "arrow", "blips/arrow.png" },
  { "radardisc", "blips/radardisc.png" },
  { "radar_airYard", "blips/radar_airYard.png" },
  { "radar_ammugun", "blips/radar_ammugun.png" },
  { "radar_barbers", "blips/radar_barbers.png" },
  { "radar_BIGSMOKE", "blips/radar_BIGSMOKE.png" },
  { "radar_boatyard", "blips/radar_boatyard.png" },
  { "radar_bulldozer", "blips/radar_bulldozer.png" },
  { "radar_burgerShot", "blips/radar_burgerShot.png" },
  { "radar_cash", "blips/radar_cash.png" },
  { "radar_CATALINAPINK", "blips/radar_CATALINAPINK.png"},
  { "radar_centre", "blips/radar_centre.png" },
  { "radar_CESARVIAPANDO", "blips/radar_CESARVIAPANDO.png" },
  { "radar_chicken", "blips/radar_chicken.png" },
  { "radar_CJ", "blips/radar_CJ.png" },
  { "radar_CRASH1", "blips/radar_CRASH1.png" },
  { "radar_dateDisco", "blips/radar_dateDisco.png" },
  { "radar_dateDrink", "blips/radar_dateDrink.png" },
  { "radar_dateFood", "blips/radar_dateFood.png" },
  { "radar_diner", "blips/radar_diner.png" },
  { "radar_emmetGun", "blips/radar_emmetGun.png" },
  { "radar_enemyAttack", "blips/radar_enemyAttack.png" },
  { "radar_fire", "blips/radar_fire.png" },
  { "radar_Flag", "blips/radar_Flag.png" },
  { "radar_gangB", "blips/radar_gangB.png" },
  { "radar_gangG", "blips/radar_gangG.png" },
  { "radar_gangN", "blips/radar_gangN.png" },
  { "radar_gangP", "blips/radar_gangP.png" },
  { "radar_gangY", "blips/radar_gangY.png" },
  { "radar_girlfriend", "blips/radar_girlfriend.png" },
  { "radar_gym", "blips/radar_gym.png" },
  { "radar_hostpital", "blips/radar_hostpital.png" },
  { "radar_impound", "blips/radar_impound.png" },
  { "radar_light", "blips/radar_light.png" },
  { "radar_LocoSyndicate", "blips/radar_LocoSyndicate.png" },
  { "radar_MADDOG", "blips/radar_MADDOG.png" },
  { "radar_mafiaCasino", "blips/radar_mafiaCasino.png" },
  { "radar_MCSTRAP", "blips/radar_MCSTRAP.png" },
  { "radar_modGarage", "blips/radar_modGarage.png" },
  { "radar_north", "blips/radar_north.png" },
  { "radar_OGLOC", "blips/radar_OGLOC.png" },
  { "radar_pizza", "blips/radar_pizza.png" },
  { "radar_police", "blips/radar_police.png" },
  { "radar_propertyG", "blips/radar_propertyG.png" },
  { "radar_propertyR", "blips/radar_propertyR.png" },
  { "radar_qmark", "blips/radar_qmark.png" },
  { "radar_race", "blips/radar_race.png" },
  { "radar_runway", "blips/radar_runway.png" },
  { "radar_RYDER", "blips/radar_RYDER.png" },
  { "radar_saveGame", "blips/radar_saveGame.png" },
  { "radar_school", "blips/radar_school.png" },
  { "radar_spray", "blips/radar_spray.png" },
  { "radar_SWEET", "blips/radar_SWEET.png" },
  { "radar_tattoo", "blips/radar_tattoo.png" },
  { "radar_THETRUTH", "blips/radar_THETRUTH.png" },
  { "radar_TORENO", "blips/radar_TORENO.png" },
  { "radar_TorenoRanch", "blips/radar_TorenoRanch.png" },
  { "radar_triads", "blips/radar_triads.png" },
  { "radar_triadsCasino", "blips/radar_triadsCasino.png" },
  { "radar_truck", "blips/radar_truck.png" },
  { "radar_tshirt", "blips/radar_tshirt.png" },
  { "radar_waypoint", "blips/radar_waypoint.png" },
  { "radar_WOOZIE", "blips/radar_WOOZIE.png" },
  { "radar_ZERO", "blips/radar_ZERO.png" },
  { "siteM16", "blips/siteM16.png" },
  { "siterocket", "blips/siterocket.png" }
}

local shaders = {}
function radaron()
visible = true
	if visible then
		for i = 2, #blips_textures do
			shaders[i] = dxCreateShader("texture.fx")
			engineApplyShaderToWorldTexture(shaders[i], blips_textures[i][1])
			dxSetShaderValue(shaders[i], "gTexture", dxCreateTexture(blips_textures[i][2]))
		end
		    handleTileLoading()
	if isTimer(timer) then killTimer(timer) end
		    timer = setTimer(handleTileLoading, 500, 0)
	end
   visible = false
end
addCommandHandler("on", radaron)
   
function radaroff()
	if visible == false then
		for i = 2, #blips_textures do
			engineRemoveShaderFromWorldTexture(shaders[i], blips_textures[i][1])
		end
	if isTimer(timer ) then killTimer(timer) end
		for name, data in pairs(tiles) do
		    unloadTile(name)
		end
  end
end
addCommandHandler("off", radaroff)

function handleTileLoading ( )
	local visibleTileNames = table.merge ( engineGetVisibleTextureNames ( "radar??" ), engineGetVisibleTextureNames ( "radar???" ) )
	    for name, data in pairs ( tiles ) do
		    if not table.find ( visibleTileNames, name ) then
			    unloadTile ( name )
		    end
	    end
	for index, name in ipairs ( visibleTileNames ) do
		loadTile ( name )
	end
end

function table.merge ( ... )
	local ret = { }
	    for index, tbl in ipairs ( {...} ) do
		    for index, val in ipairs ( tbl ) do
			    table.insert ( ret, val )
		    end
	    end
	return ret
end

function table.find ( tbl, val )
	for index, value in ipairs ( tbl ) do
		if ( value == val ) then
			return index
		end
	end
	
	return false
end

function loadTile ( name )
	if type ( name ) ~= "string" then
		return false
	end
	
	if ( tiles[name] ) then
		return true
	end
	
	local id = tonumber ( name:match ( "%d+" ) )
	
	if not ( id ) then
		return false
	end
	
	local row = math.floor ( id / ROW_COUNT )
	local col = id - ( row * ROW_COUNT )
	
	local posX = -3000 + 500 * col
	local posY =  3000 - 500 * row
	
	local file = string.format ( "sattelite/sattelite_%d_%d.png", row, col )

	local texture = dxCreateTexture ( file )
	if not ( texture ) then
		outputChatBox ( string.format ( "Failed to load texture for %q (%q)", tostring ( name ), tostring ( file ) ) )
		return false
	end
	
	local shader = dxCreateShader ( "texreplace.fx" )
	
	if not ( shader ) then
		outputChatBox ( "Failed to load shader" )
		destroyElement ( texture )
		return false
	end
	
	dxSetShaderValue ( shader, "gTexture", texture )
	engineApplyShaderToWorldTexture ( shader, name )
	tiles[name] = { shader = shader, texture = texture }
	return true
end

function unloadTile ( name )
	local tile = tiles[name]
	    if not ( tile ) then
		    return false
	    end
	if isElement ( tile.shader )  then destroyElement ( tile.shader )  end
	if isElement ( tile.texture ) then destroyElement ( tile.texture ) end
	
	tiles[name] = nil
	return true
end

 

Edited by koragg
Link to comment

OK well, there is one small bug that came up after linking it to the settings panel. If a player has already set the radar to the GTA V one (the last time he was on the server) and clicks on the checkbox to untick it now, the shader images do not unload. The minimap ones revert to default gta ones but not the shaders. :\ 

Link to comment

Like the reply of @Wojak, he deserves it. He put much more effort than me. :)

What function do you call exactly when ticking/unticking the checkbox?

radaroff and radaron?

 

Also after using that resource some times, could you check perfromancebrowser - lua memory for that resource?

On load tile you create the texture and apply it, in unload you "remove if from the world" but do not destroy it

Edited by LoPollo
Link to comment
8 minutes ago, LoPollo said:

Like the reply of @Wojak, he deserves it. He put much more effort than me. :)

What function do you call exactly when ticking/unticking the checkbox?

radaroff and radaron?

Yea, those two. "radaron" is fine but as I said, I'll say again in case you didn't get it :D

*Player joins server, opens F1 panel, checks the GTA V Radar to try it out

*Player quits server

*In few hours he comes back on the server, but wants to remove the GTA V Radar

*Player unticks the checkbox

*Minimap images unload fine, radar blip images stay the same from the GTA V Radar, although there is a line which unloads shaders in the "radaroff" function

Note: If the player ticks the GTA V Radar, plays a bit, then unticks it (without disconnecting from the server), everything unloads fine. Problem's when he quits and comes back, then it doesn't unload the shaders.

PS The user-panel I use saves such settings for ticked checkboxes in a xml file which it loads when the player connects again and applies the functions for the client.

Edited by koragg
Link to comment

And i guess you execute on connect the radaron if the saved state was on... :/ 

Is it possible that the problem is raised by the fact the client is still initializing?

1. Under what event do you check the saved state and execute radaron?

2. Can you try to execute the function with a delay - setTimer? just some seconds to make sure there's no relation with the initialization of the client when he connects

2 minutes ago, koragg said:

although there is a line which unloads shaders in the "radaroff" function

a "line"? 

Link to comment
33 minutes ago, LoPollo said:

And i guess you execute on connect the radaron if the saved state was on... :/ 

Is it possible that the problem is raised by the fact the client is still initializing?

1. Under what event do you check the saved state and execute radaron?

2. Can you try to execute the function with a delay - setTimer? just some seconds to make sure there's no relation with the initialization of the client when he connects

a "line"? 

engineRemoveShaderFromWorldTexture(shaders, blips_textures[1])

And ok, I'll try all that tomorrow, wanna race now :)

 

EDIT:

addEventHandler("onClientGUIClick", resourceRoot, ui_ClickHandler) is used to call the required function

and

addEventHandler("onClientResourceStart", resourceRoot, loadUISettings) is used when the panel loads the xml file and then execute the things

 

Edited by koragg
So since it's "onClientResourceStart" I guess problem isn't with initialization as this handler is called when the player has the resource. + i have everything downloaded and still the bug happens every time.
Link to comment

ui_ClickHandler what function exactly call? radaron and radaroff? i want to understand if the bug happens even with the same functions you use with the commandhandler.

I asked to use the timer because if you call these functions... well the only things that change is "when" they are called. 

Link to comment

Well there is a 1 or 2 second delay when I join the server. It first shows the default radar and after that second it loads the new one from the user panel.

Here's the full script which loads all such settings from the .xml file (See lines below so you don't look at all of them).

PASTEBIN (As I don't wanna spam the topic with 1k line codes :D)

Lines 109-112 tell which functions the resource should use

Line 157 sets the default function to be called when a new player joins (aka, still doesn't have a .xml file yet)

Lines 408-418 tell what should happen when the player ticks/unticks the checkbox ( saveTime() saves this to the .xml file)

Lines 745-750 tell the GUI window to update if the checkbox should be ticked or not (depending on the user's preference and what he has (dis)activated)

Link to comment
30 minutes ago, koragg said:

(As I don't wanna spam the topic with 1k line codes :D)

There are spoilers ;)

 

Honestly i can't see any problem.. on start you call the updateUIgui and it uses the export of gtavradar to (dis)activate the radar... 

and i guess that exported function is the same you use with the command handler :/

 

Nope i do not have any other idea than delaying by some seconds the calls at line 568-569 and see what happens, just as a test

Link to comment

I can't find any problem in the code honestly...

What if you replace the exported function call with an executeCommandHandler that execute the "on" and "off" cmds you have in the first resource?

EDIT: exports["gtavradar"].radaron()  at line 411: shouldn't it be exports["gtavradar"]:radaron()? Same at lines 415, 111-112

Edited by LoPollo
Link to comment
1 hour ago, LoPollo said:

I can't find any problem in the code honestly...

What if you replace the exported function call with an executeCommandHandler that execute the "on" and "off" cmds you have in the first resource?

EDIT: exports["gtavradar"].radaron()  at line 411: shouldn't it be exports["gtavradar"]:radaron()? Same at lines 415, 111-112

No, look at other exports a bit up, that's the right way.

Interesting suggestion with executeCommandHandler. I always thought that it's server only :) I'll give it a go soon.

 

Edited by koragg
Link to comment

Actually i was pretty sure about this, checked in the first resource that came in my mind (i had to download, i'm not at home)

exports.dynamic_lighting:setNightSpotRadius(radius)

EDIT: that's offtopic anyway

Let me know what happens with the executecmd

Edited by LoPollo
Link to comment
5 hours ago, LoPollo said:

Actually i was pretty sure about this, checked in the first resource that came in my mind (i had to download, i'm not at home)

exports.dynamic_lighting:setNightSpotRadius(radius)

EDIT: that's offtopic anyway

Let me know what happens with the executecmd

Unfortunately that resource is made to work only with functions, the executecmd can't work there.

Btw, you're 100% correct about the exports, but that specific resource which I use for the settings uses the format I mentioned before :P

Soo..only fix would be to somehow fix the unloading in the function when it's called. @Wojak help please :S

Link to comment
17 hours ago, LoPollo said:

Why? O.o

OK, I just did it with executeCommandHandler and result is same. Minimap images unload fine but the shaders do not if they have been set to on the last time you've been on the server and try to disable them now. Player needs to untick the checkbox and then reconnect to see the complete old radar. :S

Link to comment

Finally fixed it. I loaded the default textures as shaders in the "radaroff" function. This way they overwrite the gta v shaders and radar looks like default one (it kinda is). And since I had trouble with unloading, I decided that I'll only load shaders and it worked :) Thanks to @Wojak, @LoPollo and @xiti for the help. Now everything's running fine!

As always I'll post my working code below so that if others have the same problem or just wanna learn stuff, they'll be able to from it:

local tiles = {}
local timer
local visible = true

local ROW_COUNT = 12

--# Textures table

local blips_textures = {
  { "arrow", "blips/arrow.png" },
  { "radardisc", "blips/radardisc.png" },
  { "radar_airYard", "blips/radar_airYard.png" },
  { "radar_ammugun", "blips/radar_ammugun.png" },
  { "radar_barbers", "blips/radar_barbers.png" },
  { "radar_BIGSMOKE", "blips/radar_BIGSMOKE.png" },
  { "radar_boatyard", "blips/radar_boatyard.png" },
  { "radar_bulldozer", "blips/radar_bulldozer.png" },
  { "radar_burgerShot", "blips/radar_burgerShot.png" },
  { "radar_cash", "blips/radar_cash.png" },
  { "radar_CATALINAPINK", "blips/radar_CATALINAPINK.png"},
  { "radar_centre", "blips/radar_centre.png" },
  { "radar_CESARVIAPANDO", "blips/radar_CESARVIAPANDO.png" },
  { "radar_chicken", "blips/radar_chicken.png" },
  { "radar_CJ", "blips/radar_CJ.png" },
  { "radar_CRASH1", "blips/radar_CRASH1.png" },
  { "radar_dateDisco", "blips/radar_dateDisco.png" },
  { "radar_dateDrink", "blips/radar_dateDrink.png" },
  { "radar_dateFood", "blips/radar_dateFood.png" },
  { "radar_diner", "blips/radar_diner.png" },
  { "radar_emmetGun", "blips/radar_emmetGun.png" },
  { "radar_enemyAttack", "blips/radar_enemyAttack.png" },
  { "radar_fire", "blips/radar_fire.png" },
  { "radar_Flag", "blips/radar_Flag.png" },
  { "radar_gangB", "blips/radar_gangB.png" },
  { "radar_gangG", "blips/radar_gangG.png" },
  { "radar_gangN", "blips/radar_gangN.png" },
  { "radar_gangP", "blips/radar_gangP.png" },
  { "radar_gangY", "blips/radar_gangY.png" },
  { "radar_girlfriend", "blips/radar_girlfriend.png" },
  { "radar_gym", "blips/radar_gym.png" },
  { "radar_hostpital", "blips/radar_hostpital.png" },
  { "radar_impound", "blips/radar_impound.png" },
  { "radar_light", "blips/radar_light.png" },
  { "radar_LocoSyndicate", "blips/radar_LocoSyndicate.png" },
  { "radar_MADDOG", "blips/radar_MADDOG.png" },
  { "radar_mafiaCasino", "blips/radar_mafiaCasino.png" },
  { "radar_MCSTRAP", "blips/radar_MCSTRAP.png" },
  { "radar_modGarage", "blips/radar_modGarage.png" },
  { "radar_north", "blips/radar_north.png" },
  { "radar_OGLOC", "blips/radar_OGLOC.png" },
  { "radar_pizza", "blips/radar_pizza.png" },
  { "radar_police", "blips/radar_police.png" },
  { "radar_propertyG", "blips/radar_propertyG.png" },
  { "radar_propertyR", "blips/radar_propertyR.png" },
  { "radar_qmark", "blips/radar_qmark.png" },
  { "radar_race", "blips/radar_race.png" },
  { "radar_runway", "blips/radar_runway.png" },
  { "radar_RYDER", "blips/radar_RYDER.png" },
  { "radar_saveGame", "blips/radar_saveGame.png" },
  { "radar_school", "blips/radar_school.png" },
  { "radar_spray", "blips/radar_spray.png" },
  { "radar_SWEET", "blips/radar_SWEET.png" },
  { "radar_tattoo", "blips/radar_tattoo.png" },
  { "radar_THETRUTH", "blips/radar_THETRUTH.png" },
  { "radar_TORENO", "blips/radar_TORENO.png" },
  { "radar_TorenoRanch", "blips/radar_TorenoRanch.png" },
  { "radar_triads", "blips/radar_triads.png" },
  { "radar_triadsCasino", "blips/radar_triadsCasino.png" },
  { "radar_truck", "blips/radar_truck.png" },
  { "radar_tshirt", "blips/radar_tshirt.png" },
  { "radar_waypoint", "blips/radar_waypoint.png" },
  { "radar_WOOZIE", "blips/radar_WOOZIE.png" },
  { "radar_ZERO", "blips/radar_ZERO.png" },
  { "siteM16", "blips/siteM16.png" },
  { "siterocket", "blips/siterocket.png" }
}

local old_blips_textures = {
  { "arrow", "oldblips/arrow.png" },
  { "radardisc", "oldblips/radardisc.png" },
  { "radar_airYard", "oldblips/radar_airYard.png" },
  { "radar_ammugun", "oldblips/radar_ammugun.png" },
  { "radar_barbers", "oldblips/radar_barbers.png" },
  { "radar_BIGSMOKE", "oldblips/radar_BIGSMOKE.png" },
  { "radar_boatyard", "oldblips/radar_boatyard.png" },
  { "radar_bulldozer", "oldblips/radar_bulldozer.png" },
  { "radar_burgerShot", "oldblips/radar_burgerShot.png" },
  { "radar_cash", "oldblips/radar_cash.png" },
  { "radar_CATALINAPINK", "oldblips/radar_CATALINAPINK.png"},
  { "radar_centre", "oldblips/radar_centre.png" },
  { "radar_CESARVIAPANDO", "oldblips/radar_CESARVIAPANDO.png" },
  { "radar_chicken", "oldblips/radar_chicken.png" },
  { "radar_CJ", "oldblips/radar_CJ.png" },
  { "radar_CRASH1", "oldblips/radar_CRASH1.png" },
  { "radar_dateDisco", "oldblips/radar_dateDisco.png" },
  { "radar_dateDrink", "oldblips/radar_dateDrink.png" },
  { "radar_dateFood", "oldblips/radar_dateFood.png" },
  { "radar_diner", "oldblips/radar_diner.png" },
  { "radar_emmetGun", "oldblips/radar_emmetGun.png" },
  { "radar_enemyAttack", "oldblips/radar_enemyAttack.png" },
  { "radar_fire", "oldblips/radar_fire.png" },
  { "radar_Flag", "oldblips/radar_Flag.png" },
  { "radar_gangB", "oldblips/radar_gangB.png" },
  { "radar_gangG", "oldblips/radar_gangG.png" },
  { "radar_gangN", "oldblips/radar_gangN.png" },
  { "radar_gangP", "oldblips/radar_gangP.png" },
  { "radar_gangY", "oldblips/radar_gangY.png" },
  { "radar_girlfriend", "oldblips/radar_girlfriend.png" },
  { "radar_gym", "oldblips/radar_gym.png" },
  { "radar_hostpital", "oldblips/radar_hostpital.png" },
  { "radar_impound", "oldblips/radar_impound.png" },
  { "radar_light", "oldblips/radar_light.png" },
  { "radar_LocoSyndicate", "oldblips/radar_LocoSyndicate.png" },
  { "radar_MADDOG", "oldblips/radar_MADDOG.png" },
  { "radar_mafiaCasino", "oldblips/radar_mafiaCasino.png" },
  { "radar_MCSTRAP", "oldblips/radar_MCSTRAP.png" },
  { "radar_modGarage", "oldblips/radar_modGarage.png" },
  { "radar_north", "oldblips/radar_north.png" },
  { "radar_OGLOC", "oldblips/radar_OGLOC.png" },
  { "radar_pizza", "oldblips/radar_pizza.png" },
  { "radar_police", "oldblips/radar_police.png" },
  { "radar_propertyG", "oldblips/radar_propertyG.png" },
  { "radar_propertyR", "oldblips/radar_propertyR.png" },
  { "radar_qmark", "oldblips/radar_qmark.png" },
  { "radar_race", "oldblips/radar_race.png" },
  { "radar_runway", "oldblips/radar_runway.png" },
  { "radar_RYDER", "oldblips/radar_RYDER.png" },
  { "radar_saveGame", "oldblips/radar_saveGame.png" },
  { "radar_school", "oldblips/radar_school.png" },
  { "radar_spray", "oldblips/radar_spray.png" },
  { "radar_SWEET", "oldblips/radar_SWEET.png" },
  { "radar_tattoo", "oldblips/radar_tattoo.png" },
  { "radar_THETRUTH", "oldblips/radar_THETRUTH.png" },
  { "radar_TORENO", "oldblips/radar_TORENO.png" },
  { "radar_TorenoRanch", "oldblips/radar_TorenoRanch.png" },
  { "radar_triads", "oldblips/radar_triads.png" },
  { "radar_triadsCasino", "oldblips/radar_triadsCasino.png" },
  { "radar_truck", "oldblips/radar_truck.png" },
  { "radar_tshirt", "oldblips/radar_tshirt.png" },
  { "radar_waypoint", "oldblips/radar_waypoint.png" },
  { "radar_WOOZIE", "oldblips/radar_WOOZIE.png" },
  { "radar_ZERO", "oldblips/radar_ZERO.png" }
}

local shaders = {}
function radaron()
visible = true
	if visible then
		for i = 2, #blips_textures do
			shaders[i] = dxCreateShader("texture.fx")
			engineApplyShaderToWorldTexture(shaders[i], blips_textures[i][1])
			dxSetShaderValue(shaders[i], "gTexture", dxCreateTexture(blips_textures[i][2]))
		end
		    handleTileLoading()
	if isTimer(timer) then killTimer(timer) end
		    timer = setTimer(handleTileLoading, 500, 0)
	end
   visible = false
end
addCommandHandler("on", radaron)
   
function radaroff()
	if visible == false then
		for i = 2, #old_blips_textures do
			shaders[i] = dxCreateShader("texture.fx")
			engineApplyShaderToWorldTexture(shaders[i], old_blips_textures[i][1])
			dxSetShaderValue(shaders[i], "gTexture", dxCreateTexture(old_blips_textures[i][2]))
		end
	if isTimer(timer ) then killTimer(timer) end
		for name, data in pairs(tiles) do
		    unloadTile(name)
		end
  end
end
addCommandHandler("off", radaroff)

function handleTileLoading ( )
	local visibleTileNames = table.merge ( engineGetVisibleTextureNames ( "radar??" ), engineGetVisibleTextureNames ( "radar???" ) )
	    for name, data in pairs ( tiles ) do
		    if not table.find ( visibleTileNames, name ) then
			    unloadTile ( name )
		    end
	    end
	for index, name in ipairs ( visibleTileNames ) do
		loadTile ( name )
	end
end

function table.merge ( ... )
	local ret = { }
	    for index, tbl in ipairs ( {...} ) do
		    for index, val in ipairs ( tbl ) do
			    table.insert ( ret, val )
		    end
	    end
	return ret
end

function table.find ( tbl, val )
	for index, value in ipairs ( tbl ) do
		if ( value == val ) then
			return index
		end
	end
	
	return false
end

function loadTile ( name )
	if type ( name ) ~= "string" then
		return false
	end
	
	if ( tiles[name] ) then
		return true
	end
	
	local id = tonumber ( name:match ( "%d+" ) )
	
	if not ( id ) then
		return false
	end
	
	local row = math.floor ( id / ROW_COUNT )
	local col = id - ( row * ROW_COUNT )
	
	local posX = -3000 + 500 * col
	local posY =  3000 - 500 * row
	
	local file = string.format ( "sattelite/sattelite_%d_%d.png", row, col )

	local texture = dxCreateTexture ( file )
	if not ( texture ) then
		outputChatBox ( string.format ( "Failed to load texture for %q (%q)", tostring ( name ), tostring ( file ) ) )
		return false
	end
	
	local shader = dxCreateShader ( "texreplace.fx" )
	
	if not ( shader ) then
		outputChatBox ( "Failed to load shader" )
		destroyElement ( texture )
		return false
	end
	
	dxSetShaderValue ( shader, "gTexture", texture )
	engineApplyShaderToWorldTexture ( shader, name )
	tiles[name] = { shader = shader, texture = texture }
	return true
end

function unloadTile ( name )
	local tile = tiles[name]
	    if not ( tile ) then
		    return false
	    end
	if isElement ( tile.shader )  then destroyElement ( tile.shader )  end
	if isElement ( tile.texture ) then destroyElement ( tile.texture ) end
	
	tiles[name] = nil
	return true
end

 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...