Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance map editor #511

Merged
6 changes: 5 additions & 1 deletion [editor]/edf/edf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,11 @@ function edfCreateElement(elementType, creatorClient, fromResource, parametersTa
elseif dataField == "rotation" then
edfSetElementRotation(newElement, dataValue[1], dataValue[2], dataValue[3], dataValue[4])
elseif dataField == "interior" then
setElementInterior(newElement, dataValue)
if dataValue == -1 then
IIYAMA12 marked this conversation as resolved.
Show resolved Hide resolved
setElementInterior(newElement, 0) -- Interior -1 only works on removeWorldModel (But element data must be set to -1)
else
setElementInterior(newElement, dataValue)
end
setElementData(newElement, dataField, dataValue)
elseif dataField == "dimension" then
setElementDimension(newElement, dataValue)
Expand Down
5 changes: 4 additions & 1 deletion [editor]/edf/interface.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local interface_mt = {
__index = function(t, k)
t[k] = function(...) return call(t.res, k, ...) end
t[k] = function(...)
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
return call(t.res, k, ...)
end
return t[k]
end
}
Expand Down
2 changes: 1 addition & 1 deletion [editor]/edf/properties_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ propertyGetters = {
model = getElementModel,
rotZ = getPedRotation,
health = getElementHealth,
armor = setPedArmor,
armor = getPedArmor,
collisions = function(element)
local collisions = getElementData(element, "collisions")
if collisions == "true" or collisions == false then
Expand Down
1 change: 0 additions & 1 deletion [editor]/editor/freeroam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ addEventHandler("onResourceStart", resourceRoot,
if not getResourceFromName("freeroam") then
outputChatBox("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!", root, 255, 0, 0)
outputDebugString("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!")
editor_gui.outputMessage("WARNING: 'FREEROAM' RESOURCE NOT FOUND. Editor will not function properly. Please install the 'freeroam' resource immediately!", root, 255, 0, 0)
end
end
)
3 changes: 2 additions & 1 deletion [editor]/editor_gui/client/elementproperties.lua
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,8 @@ function openPropertiesBox( element, resourceName, shortcut )
addEventHandler("onClientElementDataChange", selectedElement, checkForNewID)

addEDFPropertyControlsForElement( selectedElement )
addPropertyControl("selection", "locked", "Locked", function (control) exports.editor_main:lockSelectedElement(selectedElement, control:getValue() == "true" or false) end, {value = exports.editor_main:isElementLocked(selectedElement) and "true" or "false", validvalues = {"false","true"}, datafield = "locked"})
-- `locked` is reserved for vehicles
addPropertyControl("selection", "locked-s", "Locked selection", function (control) exports.editor_main:lockSelectedElement(selectedElement, control:getValue() == "true" or false) end, {value = exports.editor_main:isElementLocked(selectedElement) and "true" or "false", validvalues = {"false","true"}, datafield = "locked"})

creatingNewElment = false
syncPropertiesCallback = applyPropertiesChanges
Expand Down
5 changes: 4 additions & 1 deletion [editor]/editor_gui/client/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ local interface = {

local interface_mt = {
__index = function(t, k)
return function(...) return call(t.res, k, ...) end
return function(...)
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
return call(t.res, k, ...)
end
end
}

Expand Down
1 change: 1 addition & 0 deletions [editor]/editor_gui/server/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local interface = {

local interface_mt = {
__index = function(t, k)
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
return function(...) return call(t.res, k, ...) end
end
}
Expand Down
98 changes: 56 additions & 42 deletions [editor]/editor_main/client/colpatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,26 @@ function createColPatchObjects()
g_placementObjs = {}
g_placementIDObjs = {}

for k,v in ipairs(g_placementData) do
if k % COL_CREATE_FRAME == 0 then
coroutine.yield()
end

local obj = createObject(v.id, v.x, v.y, v.z, v.rx, v.ry, v.rz)
if obj then
setElementDimension(obj, getWorkingDimension())
setElementAlpha(obj, 0)
if v.int > 0 and v.int < 256 then
setElementInterior(obj, v.int)
if g_placementData then
for k,v in ipairs(g_placementData) do
if k % COL_CREATE_FRAME == 0 then
coroutine.yield()
end
g_placementObjs[obj] = v

if not g_placementIDObjs[v.id] then
g_placementIDObjs[v.id] = {}
local obj = createObject(v.id, v.x, v.y, v.z, v.rx, v.ry, v.rz)
if obj then
setElementDimension(obj, getWorkingDimension())
setElementAlpha(obj, 0)
if v.int > 0 and v.int < 256 then
setElementInterior(obj, v.int)
end
g_placementObjs[obj] = v

if not g_placementIDObjs[v.id] then
g_placementIDObjs[v.id] = {}
end
table.insert(g_placementIDObjs[v.id], obj)
end
table.insert(g_placementIDObjs[v.id], obj)
end
end

Expand All @@ -95,12 +97,14 @@ end

function destroyColPatchObjects()
local i = 0
for obj in pairs(g_placementObjs) do
if i % COL_DESTROY_FRAME == 0 then
coroutine.yield()
if g_placementObjs then
for obj in pairs(g_placementObjs) do
if i % COL_DESTROY_FRAME == 0 then
coroutine.yield()
end
destroyElement(obj)
i = i + 1
end
destroyElement(obj)
i = i + 1
end

g_placementObjs = nil
Expand Down Expand Up @@ -175,17 +179,19 @@ end

function loadAndReplaceCollision()
g_colElements = {}
for k,colData in ipairs(g_colData) do
if k % COL_LOAD_FRAME == 0 then
coroutine.yield()
end

local col = engineLoadCOL(colData.colFile)
if col then
if engineReplaceCOL(col, colData.colID) then
table.insert(g_colElements, col)
else
destroyElement(col)
if g_colData then
for k,colData in ipairs(g_colData) do
if k % COL_LOAD_FRAME == 0 then
coroutine.yield()
end

local col = engineLoadCOL(colData.colFile)
if col then
if engineReplaceCOL(col, colData.colID) then
table.insert(g_colElements, col)
else
destroyElement(col)
end
end
end
end
Expand All @@ -194,27 +200,33 @@ function loadAndReplaceCollision()
end

function restoreAndDestroyCollision()
for k,colData in ipairs(g_colData) do
if k % COL_RESTORE_FRAME == 0 then
coroutine.yield()
end
engineRestoreCOL(colData.colID)
end
for k,col in ipairs(g_colElements) do
if isElement(col) then
if g_colData then
for k,colData in ipairs(g_colData) do
if k % COL_RESTORE_FRAME == 0 then
coroutine.yield()
end
destroyElement(col)
engineRestoreCOL(colData.colID)
end
end

g_colElements = nil
if g_colElements then
for k,col in ipairs(g_colElements) do
if isElement(col) then
if k % COL_RESTORE_FRAME == 0 then
coroutine.yield()
end
destroyElement(col)
end
end
g_colElements = nil
end

destroyColPatchObjects()
end

-- Called after we finish loading to apply removed world objects in current map
function applyRemovedColPatches()
if not g_placementIDObjs then return end
if not g_placementObjs then return end
for i,element in ipairs(getElementsByType("removeWorldObject")) do
local model = getElementData(element, "model")
if g_placementIDObjs[model] then
Expand Down Expand Up @@ -242,6 +254,8 @@ end

local function onClientElementCreateDestroy()
if not g_placementData then return end
if not g_placementIDObjs then return end
if not g_placementObjs then return end
if (getElementType(source) ~= "removeWorldObject") then return end

local model = getElementData(source, "model")
Expand Down
1 change: 1 addition & 0 deletions [editor]/editor_main/client/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local interface = {

local interface_mt = {
__index = function(t, k)
if getUserdataType(t.res) ~= "resource-data" or getResourceState(t.res) ~= "running" then return end
return function(...) return call(t.res, k, ...) end
end
}
Expand Down
4 changes: 2 additions & 2 deletions [editor]/editor_main/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function processClick ( clickedElement, key, keyState, lookX, lookY, lookZ )
end
end

if g_selectedElement ~= clickedElement and g_lock[clickedElement] then
if g_selectedElement ~= clickedElement and g_lock[edf.edfGetAncestor(clickedElement)] then
editor_gui.outputMessage("This element is locked, Press '"..cc["lock_selected_element"]:upper().."' to unlock it.", 255,255,255)
return false
end
Expand Down Expand Up @@ -517,7 +517,7 @@ end
function processDoubleClick ( clickedElement, key )
if not clickedElement then return end

if g_selectedElement ~= clickedElement and g_lock[clickedElement] then
if g_selectedElement ~= clickedElement and g_lock[edf.edfGetAncestor(clickedElement)] then
editor_gui.outputMessage("This element is locked, Press '"..cc["lock_selected_element"]:upper().."' to unlock it.", 255,255,255)
return false
end
Expand Down
2 changes: 1 addition & 1 deletion [editor]/editor_main/client/matrix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ local tround = function( t,mult )
end
function matrix.round( mtx, idp )
local mult = 10^( idp or 0 )
local fround = matrix.type( mtx ) == "number" and numound or tround
local fround = matrix.type( mtx ) == "number" and numround or tround
for i = 1,#mtx do
for j = 1,#mtx[1] do
mtx[i][j] = fround(mtx[i][j],mult)
Expand Down
1 change: 1 addition & 0 deletions [editor]/editor_main/server/EDFhandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ addEventHandler ( "onEDFLoad", root, registerEDF)

addEventHandler ( "onEDFUnload", root,
function ( resource )
if not loadedEDF[resource] then return end -- Only unload if the EDF has been loaded
loadedEDF[resource] = nil
for i, player in ipairs(getElementsByType"player") do
if clientGUILoaded[player] then
Expand Down
6 changes: 3 additions & 3 deletions [editor]/editor_main/server/definitionssync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ addEventHandler ( "reloadEDFDefinitions", root, reloadEDFDefinitions )

addEventHandler ( "onResourceStop",resourceRoot,
function()
if not newEDF then return end --newEDF is cleared when the editor is stopped (prevent a debug error)
for i, resourceName in ipairs(newEDF.addedEDF) do
if not allEDF then return end --allEDF is cleared when the editor is stopped (prevent a debug error)
for i, resourceName in ipairs(allEDF.addedEDF) do
local resource = getResourceFromName(resourceName)
if getResourceState ( resource ) == "running" then
if resource and getResourceState ( resource ) == "running" then
stopResource ( resource )
end
end
Expand Down
2 changes: 1 addition & 1 deletion [editor]/editor_main/server/orderedPairs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ function orderedNext(t, state)
-- table being iterated.

--print("orderedNext: state = "..tostring(state) )
local key
if state == nil then
-- the first time, generate the index
t.__orderedIndex = __genOrderedIndex( t )
key = t.__orderedIndex[1]
return key, t[key]
end
-- fetch the next value
key = nil
for i = 1,table.getn(t.__orderedIndex) do
if t.__orderedIndex[i] == state then
key = t.__orderedIndex[i+1]
Expand Down
2 changes: 1 addition & 1 deletion [editor]/editor_main/server/playerblips.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end

function setPlayerBlipSize(player,size)
if isElement(player) and getElementType(player)=="player" and playerBlips[player] and size and type(size)=="number" and size > 0 then
return setBlipSize(playerBlips[player])
return setBlipSize(playerBlips[player], size)
end

return false
Expand Down
2 changes: 1 addition & 1 deletion [gameplay]/sirenEdit/matrix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ local tround = function( t,mult )
end
function matrix.round( mtx, idp )
local mult = 10^( idp or 0 )
local fround = matrix.type( mtx ) == "number" and numound or tround
local fround = matrix.type( mtx ) == "number" and numround or tround
for i = 1,#mtx do
for j = 1,#mtx[1] do
mtx[i][j] = fround(mtx[i][j],mult)
Expand Down