mapmanager: fixes and some cleanup

This commit is contained in:
moscovium
2018-03-25 14:56:08 +02:00
parent fefd225904
commit 53fc373f5d
4 changed files with 130 additions and 139 deletions

View File

@@ -1,25 +1,7 @@
-- loosely based on MTA's https://code.google.com/p/mtasa-resources/source/browse/trunk/%5Bmanagers%5D/mapmanager/mapmanager_main.lua
maps = {}
gametypes = {}
AddEventHandler('getResourceInitFuncs', function(isPreParse, add)
add('resource_type', function(type)
return function(params)
local resourceName = GetInvokingResource()
if type == 'map' then
maps[resourceName] = params
elseif type == 'gametype' then
gametypes[resourceName] = params
end
end
end)
add('map', function(file)
AddAuxFile(file)
end)
end)
local maps = {}
local gametypes = {}
local function refreshResources()
local numResources = GetNumResources()
@@ -47,8 +29,16 @@ end)
refreshResources()
AddEventHandler('onResourceStarting', function(resource)
if GetNumResourceMetadata(resource, 'map') then
-- todo: add file
local num = GetNumResourceMetadata(resource, 'map')
if num then
for i = 0, num-1 do
local file = GetResourceMetadata(resource, 'map', i)
if file then
addMap(file, resource)
end
end
end
if maps[resource] then
@@ -132,7 +122,6 @@ AddEventHandler('onResourceStart', function(resource)
SetGameType(gtName)
print('Started gametype ' .. gtName)
TriggerClientEvent('onClientGameTypeStart', -1, getCurrentGameType())
SetTimeout(50, function()
if not currentMap then
@@ -155,6 +144,9 @@ AddEventHandler('onResourceStart', function(resource)
end
end
end
-- handle starting
loadMap(resource)
end)
local function handleRoundEnd()
@@ -177,6 +169,10 @@ AddEventHandler('mapmanager:roundEnded', function()
SetTimeout(50, handleRoundEnd) -- not a closure as to work around some issue in neolua?
end)
function roundEnded()
SetTimeout(50, handleRoundEnd)
end
AddEventHandler('onResourceStop', function(resource)
if resource == currentGameType then
TriggerEvent('onGameTypeStop', resource)
@@ -191,6 +187,9 @@ AddEventHandler('onResourceStop', function(resource)
currentMap = nil
end
-- unload the map
unloadMap(resource)
end)
AddEventHandler('rconCommand', function(commandName, args)