Jump to content

[SOLVED] How do I update map without restarting gamemode?


LonerJak

Recommended Posts

I have a gamemode and a map that goes with it. Let's say I add a new car spawner to the map, I can restart the car spawner resource and it reloads all off the spawners from the map. But before I restart the resource to update the car spawners, I must reload the map resource so the changes will be there.

This is where the problem comes in, I don't want to have to restart the entire gamemode just to load a few changes to the map. How can I reload the map without restarting my gamemode resource too? My maps name is "gtc-mainmap", if I do /restart gtc-mainmap it restarts my gamemode, which logs everybody out in the middle of gameplay. Is there any way to load changes to the map file whilst allowing players to continue playing?

I see this when i play other servers, I'll be playing, then I'll see the download bar at the bottom, then boom, there's new things added to the map, but I can't seem to make this happen in my server.

Edited by Guest
Link to comment
You could try to stop mapmanager if you have only one map for the whole gamemode.

Okay I'll try that. But I think I use the event "onGamemodeMapStart" to get the map root to create objects from custom map elements.

Is there a way I can get the main map root from inside another resource?

I have my main gamemode, GTC. Inside the GTC resource I use "onGamemodeMapStart" to get the map root, which is then stored in the variable MAP_ROOT, then I export a function called 'getMapRoot()' which I'm trying to call from another resource, 'gtc_sprayshops', so I can get all 'sprayshop' elements from the map and create markers for them.

But I can't seem to use the map root passed by that function.

When I try this:

gtc_sprayshops > sprayshops_s.lua

-- Loads and creates the pay n spray shops when the resource is started. 
    -- 
addEventHandler("onResourceStart", resourceRoot, 
    function () 
        local sprayshops = getElementsByType("sprayshop", exports.GTC:getMapRoot()) 
         
        for _, sprayshop in pairs(sprayshops) do 
            local x = getElementData(sprayshop, "posX") 
            local y = getElementData(sprayshop, "posY") 
            local z = getElementData(sprayshop, "posZ") 
             
            local sprayMark = createMarker(x,y,z, "cylinder", 4, 110,140,200, 200) 
            setElementData(sprayMark, "markType", "sprayshop") 
             
            createBlip(x,y,0, 63, 2, 255,0,0, 255, 0, 400.0) 
        end 
    end 
) 

It gives me this error:

[2015-03-23 15:05:24] WARNING: [GTC]\gtc_sprayshops\sprayshops_s.lua:12: Bad argument @ 'getElementsByType' [Expected element at argument 2, got table] 
[2015-03-23 15:05:24] ERROR: [GTC]\gtc_sprayshops\sprayshops_s.lua:14: bad argument #1 to 'pairs' (table expected, got boolean) 

This is how I get the map root in the gamemode resource:

GTC > gtc_s.lua

MAP_ROOT = { } 
  
-- [EXPORTED] Allows other resources to access the map root. 
    -- 
function getMapRoot() 
    return MAP_ROOT 
end 
  
-- Loads up all map related data and create the needed elements. 
    -- 
addEventHandler("onGamemodeMapStart", root, 
    function (startedMap) 
        MAP_ROOT = getResourceRootElement(startedMap) 
         
        -- Freezes all peds/clerks that are present in the map. 
        local peds = getElementsByType("ped", MAP_ROOT) 
        local clerks = getElementsByType("clerk", MAP_ROOT) 
        for _, ped in ipairs(peds) do setElementFrozen(ped, true) end 
        for _, clerk in ipairs(clerks) do setElementFrozen(clerk, true) end 
    end 
) 

I don't want to create all my Pay n Spray markers, car spawn markers, etc, in my gamemode resource. I want those objects to be created by the resources that deal with them, but I've tried many things attempting to get the map root from outside the gamemode resource and I always get this error.

How can I load all "sprayshop" elements from the map root in the resource "gtc_sprayshops"?

Link to comment

Yes I've tried that function before and had no success. I'll try this again, but first here is how my directory is looking:

> resources

>> [GTC]

>>> [maps]

>>>> gtc-mainmap

>>>>> gtc-mainmap.map

>>> GTC

>>>> gtc_s.lua

>>> gtc_sprayshops

>>>> sprayshops_s.lua

I've specified the map file in the meta.xml file of my gamemode resource like so:

<map src="gtc-mainmap.map" dimension="0" /> 

Do I need to specify the relative path to the map since it isn't in the same directory as the meta.xml file? Or is simply putting the filename of the map enough?

Anyways, I changed the script to:

-- Loads and creates the pay n spray shops when the resource is started. 
    -- 
addEventHandler("onResourceStart", resourceRoot, 
    function () 
        local mapRoot = getResourceMapRootElement(getResourceFromName("GTC"), "gtc-mainmap.map") 
        local sprayshops = getElementsByType("sprayshop", mapRoot) 
         
        for _, sprayshop in pairs(sprayshops) do 
            local x = getElementData(sprayshop, "posX") 
            local y = getElementData(sprayshop, "posY") 
            local z = getElementData(sprayshop, "posZ") 
             
            local sprayMark = createMarker(x,y,z, "cylinder", 4, 110,140,200, 200) 
            setElementData(sprayMark, "markType", "sprayshop") 
             
            createBlip(x,y,0, 63, 2, 255,0,0, 255, 0, 400.0) 
        end 
    end 
) 

But, I've tried all 3 of these in the meta file of the gamemode:

<map src="gtc-mainmap.map" dimension="0" /> 

<map src="../[maps]/gtc-mainmap.map" dimension="0" /> 

<map src="../[maps]/gtc-mainmap/gtc-mainmap.map" dimension="0" /> 

And in all 3 cases when I start the server I get the error:

ERROR: Couldn't find map <map_filename> for resource GTC 

I don't know if my updated script works or not because I can't even get the server to start.

Could you either help me figure out what I'm doing wrong, or give me an example of a gamemode, a map, and a resource that gets the maproot to find custom map elements in?

Link to comment

Okay, I just got the map file to get recognized, but now with this code:

-- Loads and creates the pay n spray shops when the resource is started. 
    -- 
addEventHandler("onResourceStart", resourceRoot, 
    function () 
        local mapRoot = getResourceMapRootElement(getResourceFromName("GTC"), "gtc-mainmap.map") 
        local sprayshops = getElementsByType("sprayshop", mapRoot) 
         
        for _, sprayshop in pairs(sprayshops) do 
            local x = getElementData(sprayshop, "posX") 
            local y = getElementData(sprayshop, "posY") 
            local z = getElementData(sprayshop, "posZ") 
             
            local sprayMark = createMarker(x,y,z, "cylinder", 4, 110,140,200, 200) 
            setElementData(sprayMark, "markType", "sprayshop") 
             
            createBlip(x,y,0, 63, 2, 255,0,0, 255, 0, 400.0) 
        end 
    end 
) 

I get the error:

[2015-03-23 15:59:30] WARNING: [GTC]\gtc_sprayshops\sprayshops_s.lua:13: Bad argument @ 'getElementsByType' [Expected element at argument 2, got boolean] 
[2015-03-23 15:59:30] ERROR: [GTC]\gtc_sprayshops\sprayshops_s.lua:15: bad argument #1 to 'pairs' (table expected, got boolean) 

So this line

local mapRoot = getResourceMapRootElement(getResourceFromName("GTC"), "gtc-mainmap.map") 

Must be wrong.

I now have the map file in the gamemode resource folder

resources/[GTC]/GTC/maps/gtc-mainmap/gtc-mainmap.map 

Do I need to specify a path for the second argument of 'getResourceMapRootElement'?

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...