iiv03 Posted September 7, 2019 Share Posted September 7, 2019 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 IIYAMA Posted September 7, 2019 Moderators Share Posted September 7, 2019 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 ) 1 Link to comment
iiv03 Posted September 11, 2019 Author Share Posted September 11, 2019 (edited) 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 September 11, 2019 by xFabel Link to comment
Administrators Lpsd Posted September 11, 2019 Administrators Share Posted September 11, 2019 (edited) Just so you know, the actual max value for engineSetModelLODDistance is 325 Edited September 11, 2019 by LopSided 1 Link to comment
iiv03 Posted September 11, 2019 Author Share Posted September 11, 2019 (edited) 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 September 11, 2019 by xFabel Link to comment
Administrators Lpsd Posted September 11, 2019 Administrators Share Posted September 11, 2019 (edited) 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 September 11, 2019 by LopSided 1 Link to comment
iiv03 Posted September 12, 2019 Author Share Posted September 12, 2019 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now