Jump to content

help engineSetModelLODDistance


iiv03

Recommended Posts

hey everybody, have a problem in function im trying to do engineSetModelLODDistance ON/OFF but nothing well I could not find any error in debugscript what's problem

function draw.setVisible(visible, notifyDisplay)
	draw.visible = visible and true or false
	if draw.visible then
	removeEventHandler("onClientResourceStart", root,draw.changeDistance)
	addEventHandler("onClientResourceStart", root,draw.changeDistance)
	end
	if notifyDisplay then
		triggerEvent("notification:create", localPlayer, "Draw distance", "is now "..(draw.visible and "OFF" or "ON"))
	end
end

function draw.changeDistance()
    for i,object in pairs(getElementsByType("object")) do
        if isElement(object) then
            local elementID = getElementModel(object )
            engineSetModelLODDistance(elementID,1000)
        end
    end
end

 

Link to comment
  • Moderators
15 hours ago, xFabel said:

what's problem

 

You are only setting it ON, even when you are trying to set it OFF.

engineSetModelLODDistance(elementID, eventName == "onClientResourceStart" and 1000 or 150)

 

1000 is ON.

Something below 170 is OFF. ( probably each object has an unique LOD distance value )

 

 

  • Sad 1
Link to comment
On 07/09/2019 at 20:37, IIYAMA said:

 

You are only setting it ON, even when you are trying to set it OFF.


engineSetModelLODDistance(elementID, eventName == "onClientResourceStart" and 1000 or 150)

 

1000 is ON.

Something below 170 is OFF. ( probably each object has an unique LOD distance value )

 

 

i tried some and I couldn't find any solution

function draw.setVisible(visible, notifyDisplay)
	draw.visible = visible and true or false
	if draw.visible then
	removeEventHandler("onClientResourceStart", root,draw.changeDistance)
	addEventHandler("onClientResourceStart", root,draw.changeDistance)
	end
	if notifyDisplay then
		triggerEvent("notification:create", localPlayer, "Draw distance", "is now "..(draw.visible and "OFF" or "ON"))
	end
end

function draw.changeDistance()
    for i,object in pairs(getElementsByType("object")) do
        if isElement(object) then
            local elementID = getElementModel(object )
		engineSetModelLODDistance(elementID, eventName == "onClientResourceStart" and 1000 or 0)

        end
    end
end
	addEventHandler("onClientResourceStart", root,draw.changeDistance)

 

Edited by xFabel
Link to comment
20 minutes ago, LopSided said:

Just so you know, the actual max value for engineSetModelLODDistance is 325

i put 325 too before and nothing too :/

		engineSetModelLODDistance(elementID, eventName == "onClientResourceStart" and 325 or 100)

 

addEvent("onSettingChange", true)
addEventHandler("onSettingChange", localPlayer,
function(variable, value)
	if variable == "draw_distance" then
		local state = not (value == "Off")
		draw.setVisible(state, true)
	end
end)


function draw.setVisible(visible, notifyDisplay)
	draw.visible = visible and true or false
	if draw.visible then
	removeEventHandler("onClientResourceStart", root,draw.changeDistance)
	addEventHandler("onClientResourceStart", root,draw.changeDistance)
	end
	if notifyDisplay then
		triggerEvent("notification:create", localPlayer, "Draw distance", "is now "..(draw.visible and "ON" or "OFF"))
	end
end

function draw.changeDistance()
    for i,object in pairs(getElementsByType("object")) do
        if isElement(object) then
            local elementID = getElementModel(object )
		engineSetModelLODDistance(elementID, eventName  == "onClientResourceStart" and 325 or 100)
        end
    end
end

Anyone guys?

Edited by xFabel
Link to comment
  • Administrators

Try this

addEvent("onSettingChange", true)
addEventHandler("onSettingChange", localPlayer,
function(variable, value)
	if variable == "draw_distance" then
		local state = not (value == "Off")
		draw.setVisible(state, true)
	end
end)


function draw.setVisible(visible, notifyDisplay)
	draw.visible = visible and true or false  
	draw.changeDistance(draw.visible)
	if notifyDisplay then
		triggerEvent("notification:create", localPlayer, "Draw distance", "is now "..(draw.visible and "ON" or "OFF"))
	end
end

function draw.changeDistance(max)
    for i,object in pairs(getElementsByType("object")) do
        if isElement(object) then
            local elementID = getElementModel(object)
			engineSetModelLODDistance(elementID, max and 325 or 100)
        end
    end
end

function initialize()
	draw.setVisible(true, false)
end
addEventHandler("onClientResourceStart", resourceRoot, initialize)

Your code had all sorts of logic errors, especially with the onClientResourceStart, which was only being added when you ran draw.setVisible, but also being attached for all resources, instead of just the current one. It would never run for the current resource that way.

 

 

Edited by LopSided
  • Like 1
Link to comment
10 hours ago, LopSided said:

Try this


addEvent("onSettingChange", true)
addEventHandler("onSettingChange", localPlayer,
function(variable, value)
	if variable == "draw_distance" then
		local state = not (value == "Off")
		draw.setVisible(state, true)
	end
end)


function draw.setVisible(visible, notifyDisplay)
	draw.visible = visible and true or false  
	draw.changeDistance(draw.visible)
	if notifyDisplay then
		triggerEvent("notification:create", localPlayer, "Draw distance", "is now "..(draw.visible and "ON" or "OFF"))
	end
end

function draw.changeDistance(max)
    for i,object in pairs(getElementsByType("object")) do
        if isElement(object) then
            local elementID = getElementModel(object)
			engineSetModelLODDistance(elementID, max and 325 or 100)
        end
    end
end

function initialize()
	draw.setVisible(true, false)
end
addEventHandler("onClientResourceStart", resourceRoot, initialize)

Your code had all sorts of logic errors, especially with the onClientResourceStart, which was only being added when you ran draw.setVisible, but also being attached for all resources, instead of just the current one. It would never run for the current resource that way.

 

 

thx

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