Skip to content

Commit

Permalink
Merge pull request #30 from Fernando-A-Rocha/2.0.4
Browse files Browse the repository at this point in the history
2.0.4
  • Loading branch information
Fernando-A-Rocha authored Jan 16, 2023
2 parents f83c58f + 93f9801 commit ce656a2
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 28 deletions.
2 changes: 1 addition & 1 deletion [editor_custom]/newmodels_editor/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
https://github.com/Fernando-A-Rocha/mta-add-models -->
<info author="Fernando" name="newmodels Editor Tool"
description="Add-Models Map Editor Tool"
version="2.0.3"
version="2.0.4"
type="script"/>

<include resource="newmodels"/>
Expand Down
2 changes: 1 addition & 1 deletion [examples]/newmodels-example/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<info author="Fernando"
name="newmodels Example"
description="implements mta-add-models library functions"
version="2.0.3"
version="2.0.4"
type="script" />

<include resource="newmodels" />
Expand Down
2 changes: 1 addition & 1 deletion [examples]/sampobj_reloaded/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<info author="Fernando" name="SAMP Objects Reloaded"
description="implements mta-add-models library functions to add all SA-MP objects"
version="2.0.3"
version="2.0.4"
type="script" />

<include resource="newmodels" />
Expand Down
1 change: 1 addition & 0 deletions [examples]/unittest_newmodels/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local temp_datas = {
player = exports.newmodels:getDataNameFromType("player"),
ped = exports.newmodels:getDataNameFromType("ped"),
object = exports.newmodels:getDataNameFromType("object"),
pickup = exports.newmodels:getDataNameFromType("pickup"),
}

addEventHandler( "onClientRender", root,
Expand Down
2 changes: 1 addition & 1 deletion [examples]/unittest_newmodels/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<info author="Fernando" name="Newmodels Unit Testing"
description="created for debugging purposes to test all functionalities of newmodels framework"
version="2.0.3"
version="2.0.4"
type="script" />

<include resource="newmodels"/>
Expand Down
15 changes: 15 additions & 0 deletions [examples]/unittest_newmodels/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function (startedResource)
-- test5()
-- test6()
-- test7()
-- test8()

end)

Expand Down Expand Up @@ -191,6 +192,20 @@ function test7()
end
end

-- Custom pickups
function test8()
local thePlayer = getRandomPlayer()
if not thePlayer then return end
local samp = getResourceFromName("sampobj_reloaded")
if not (samp and getResourceState(samp)=="running") then
return ptin("test8: sampobj_reloaded is not running")
end
local customID = 18749 -- SAMPLogoSmall
local pickup = createPickup(0,0,3, 3, 1239)
addEventHandler("onPickupHit", pickup, function() cancelEvent() end)
setElementData(pickup, "objectID", customID)
print("Created custom pickup with ID "..customID)
end


-- Vehicle testing
Expand Down
7 changes: 6 additions & 1 deletion newmodels/_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@

-- saves custom element model ID in its element data under the following names
dataNames = {
ped = "skinID", player = "skinID", -- must be the same
ped = "skinID",
vehicle = "vehicleID",
object = "objectID",
}

dataNames.player = dataNames.ped -- must be the same

-- support pickups with custom object models
dataNames.pickup = dataNames.object -- must be the same

-- saves the element's custom model's base model ID
-- useful for getting a vehicle's base model to fetch its original handling, etc
baseDataName = "baseID"
Expand Down
41 changes: 25 additions & 16 deletions newmodels/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function allocateNewMod(element, elementType, id)
-- as type so we need to change that to 'ped'
local elementType2 = elementType
if elementType2 == "player" then elementType2 = "ped" end
if elementType2 == "pickup" then elementType2 = "object" end

local paths = foundMod.paths
if type(paths) ~= "table" then
Expand Down Expand Up @@ -390,26 +391,32 @@ function setElementCustomModel(element, elementType, id, noRefresh)
end
end

-- refresh model so change can actually have an effect
local currModel = getElementModel(element)
if (currModel == allocated_id) and not (noRefresh) then
if getElementType(element) == "pickup" then
setPickupType(element, 3, allocated_id)
print("set pickup type to 3, "..allocated_id)
else

-- some logic to refresh model
local diffModel = 9--ped
if elementType == "vehicle" then
diffModel = 400
elseif elementType == "object" then
diffModel = 1337
end
if currModel == diffModel then
diffModel = diffModel + 1
end
-- refresh model so change can actually have an effect
local currModel = getElementModel(element)
if (currModel == allocated_id) and not (noRefresh) then

if setElementModel(element, diffModel) then
-- some logic to refresh model
local diffModel = 9--ped
if elementType == "vehicle" then
diffModel = 400
elseif elementType == "object" then
diffModel = 1337
end
if currModel == diffModel then
diffModel = diffModel + 1
end

if setElementModel(element, diffModel) then
setElementModel(element, allocated_id)
end
else
setElementModel(element, allocated_id)
end
else
setElementModel(element, allocated_id)
end

if getElementType(element)=="vehicle" then
Expand Down Expand Up @@ -508,6 +515,8 @@ function updateElementOnDataChange(source, theKey, oldValue, newValue)
local et = getElementType(source)
if et == "player" and data_et == "ped" then data_et = "player" end
if et == "ped" and data_et == "player" then data_et = "ped" end
if et == "pickup" and data_et == "object" then data_et = "pickup" end
if et == "object" and data_et == "pickup" then data_et = "object" end

if data_et ~= et then return end

Expand Down
2 changes: 1 addition & 1 deletion newmodels/meta.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<meta>
<info author="Fernando" name="mta-add-models"
description="minimalistic library for adding new models to your server"
version="2.0.3"
version="2.0.4"
type="script"/>

<!-- DOCUMENTATION:
Expand Down
9 changes: 8 additions & 1 deletion newmodels/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ end
function fixModList()
-- because ped mods can be applied on players too
modList.player = modList.ped
modList.pickup = modList.object
return true
end

Expand Down Expand Up @@ -293,7 +294,10 @@ function doModListChecks()

for elementType, name in pairs(dataNames) do

if elementType ~= "player" then -- exception
if not (
elementType == "player"
or elementType == "pickup"
) then -- exceptions
local mods1 = modList[elementType]
if not mods1 then
return modCheckError("Missing from modList: "..elementType.." = {},")
Expand All @@ -308,6 +312,9 @@ function doModListChecks()
if elementType == "player" then
return modCheckError("Please remove mod from modList: player = {...}, it will be added automatically to match 'ped' mods")
end
if elementType == "pickup" then
return modCheckError("Please remove mod from modList: pickup = {...}, it will be added automatically to match 'object' mods")
end

-- for _,mod in ipairs(mods) do
Async:foreach(mods, function(mod)
Expand Down
5 changes: 0 additions & 5 deletions newmodels/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ function verifySetModelArguments(element, elementType, id)
return false, reason
end

local dataName = dataNames[et]
if not dataName then
return false, et.." mods yet supported"
end

if not tonumber(id) then
return false, "Non-number ID passed"
end
Expand Down

0 comments on commit ce656a2

Please sign in to comment.