Jump to content

[TUT] Load maps using fetchRemote


gubi

Recommended Posts

Hi,

I was testing fetchRemote function and decide to create script that's gonna load map from cloud / URL. I added some settings soo you can create the whole system out of this few lines of code.

Also this resource is gonna need access to 'fetchRemote' function, simply add it in ACL and you can use it. There are 2 maps added so you can test it out.

 

 

local customMapsRawData = {

	["Trash on Grove Street"] = {
		["active"] = true, -- is map enabled or not
		["link"] = "http://www.gubi.studio/tut/mta/trash-on-grove-street.txt", -- link to text file which contain whole data of your .map file
		["visibleTo"] = getRootElement(), -- element which should see the map, can be player/getRootElement()
		["annoucment"] = true, -- if set to true will annouce on chat that map has been loaded
	},

	["Shop on Grove Street"] = {
		["active"] = false,
		["link"] = "http://www.gubi.studio/tut/mta/shop-on-grove-street.txt",
		["visibleTo"] = getRootElement(),
		["annoucment"] = false,
	}

}

local function createMapFromRawData(data, error, mapName, annoucment, visibleTo)
	if error == 0 then
		loadMapData(xmlLoadString(data), visibleTo)
		outputDebugString("Map "..mapName.." has been loaded!")
		if annoucment == true then
			outputChatBox("Map "..mapName.." has been loaded!", root, 0,255,0)
		end
	else
		outputDebugString("Map "..mapName.." failed while loading! Check if link is valid!", 3)
	end
end

local function loadCustomMaps()
        if not hasObjectPermissionTo(getThisResource(), "fetchRemote", true) then
			outputDebugString("This resource needs access to \"fetchRemote\" in ACL!", 1)
		return
	end
	for mapName, mapData in pairs(customMapsRawData) do
		if mapData["active"] == true then
				fetchRemote(mapData["link"], createMapFromRawData, "", false, mapName, mapData["annoucment"], mapData["visibleTo"])
		end
	end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), loadCustomMaps)

 

Edited by gubi
  • Like 3
Link to comment
  • Moderators

@gubi

What's with that visibleTo stuff?

visibleTo is not the same as a parentNode, which can't be a table because it is not a node, neither a player which is not allowed to have children from resources. And even if it was allowed, it wouldn't change the visibility for players.

 

This is where it matters:

https://wiki.multitheftauto.com/wiki/Element_tree

 

Edited by IIYAMA
Link to comment
21 hours ago, IIYAMA said:

@gubi

What's with that visibleTo stuff?

visibleTo is not the same as a parentNode, which can't be a table because it is not a node, neither a player which is not allowed to have children from resources. And even if it was allowed, it wouldn't change the visibility for players.

 

This is where it matters:

https://wiki.multitheftauto.com/wiki/Element_tree

 

Yeah seems like it's working only on root/player, unlucky

Link to comment
  • 1 month later...

Hello gubi,

I have tried your resource, but it always complains that it has no access to "fetchRemote". Changing line 32 to

        if not hasObjectPermissionTo(getThisResource(), "fetchRemote", true) then

has fixed the issue. Now I see naughty work of art on Grove Street ;)

I think this is a good use of the new xmlLoadString function call. But you could still add more features to this script, to make it better.

Link to comment
On 24/02/2020 at 01:26, The_GTA said:

Hello gubi,

I have tried your resource, but it always complains that it has no access to "fetchRemote". Changing line 32 to

 


        if not hasObjectPermissionTo(getThisResource(), "fetchRemote", true) then

 

has fixed the issue. Now I see naughty work of art on Grove Street ;)

I think this is a good use of the new xmlLoadString function call. But you could still add more features to this script, to make it better.

Oh yeah, fixed, thanks man

Link to comment
  • 8 months later...
On 19/01/2020 at 20:31, gubi said:

Hi,

I was testing fetchRemote function and decide to create script that's gonna load map from cloud / URL. I added some settings soo you can create the whole system out of this few lines of code.

Also this resource is gonna need access to 'fetchRemote' function, simply add it in ACL and you can use it. There are 2 maps added so you can test it out.

 

 


local customMapsRawData = {

	["Trash on Grove Street"] = {
		["active"] = true, -- is map enabled or not
		["link"] = "http://www.gubi.studio/tut/mta/trash-on-grove-street.txt", -- link to text file which contain whole data of your .map file
		["visibleTo"] = getRootElement(), -- element which should see the map, can be player/getRootElement()
		["annoucment"] = true, -- if set to true will annouce on chat that map has been loaded
	},

	["Shop on Grove Street"] = {
		["active"] = false,
		["link"] = "http://www.gubi.studio/tut/mta/shop-on-grove-street.txt",
		["visibleTo"] = getRootElement(),
		["annoucment"] = false,
	}

}

local function createMapFromRawData(data, error, mapName, annoucment, visibleTo)
	if error == 0 then
		loadMapData(xmlLoadString(data), visibleTo)
		outputDebugString("Map "..mapName.." has been loaded!")
		if annoucment == true then
			outputChatBox("Map "..mapName.." has been loaded!", root, 0,255,0)
		end
	else
		outputDebugString("Map "..mapName.." failed while loading! Check if link is valid!", 3)
	end
end

local function loadCustomMaps()
        if not hasObjectPermissionTo(getThisResource(), "fetchRemote", true) then
			outputDebugString("This resource needs access to \"fetchRemote\" in ACL!", 1)
		return
	end
	for mapName, mapData in pairs(customMapsRawData) do
		if mapData["active"] == true then
				fetchRemote(mapData["link"], createMapFromRawData, "", false, mapName, mapData["annoucment"], mapData["visibleTo"])
		end
	end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), loadCustomMaps)

 

Awesome tutorial keep it Up

Link to comment
  • Recently Browsing   0 members

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