Valentin3526 Posted October 12, 2015 Share Posted October 12, 2015 (edited) Hi, I have make a script inspired by "dxDrawLoading", my script don't have any error when I use the script in his resource, but when I use "exports["resource"]:function(args)" my loading bar are already at 100% and don't load Code clientside (Scripts.zip): local start = getTickCount() function dxDrawLoading(x, y, width, height, x2, y2, size, color, color2, color3, loadText, second, police) local now = getTickCount() local seconds = second local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + tonumber(seconds)) - start), "Linear") local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + tonumber(seconds)) - start),"Linear") dxDrawText ( loadText.."... "..math.floor(text).."%", x2, y2+1 , width, height, color3, size, police ) dxDrawRectangle(x, y ,width ,height -10, color) dxDrawRectangle(x, y, with ,height -10, color2) end my export (clientside) (Teams.zip): local start = getTickCount() sx ,sy = guiGetScreenSize() function drawLoad2() local saTeam = getPlayerTeam(getLocalPlayer()) local r, g, b = getTeamColor(saTeam) local now = getTickCount() exports["Scripts"]:dxDrawLoading(196*sx/800, 482*sy/600, 422*sx/800, 25*sy/600, 196*sx/800, 450*sy/600, 1.00*sx/800, tocolor(0,0,0,120), tocolor(r,g,b,255), tocolor(r,g,b,255), "Démarrage", 7000, "pricedown") if now > start + 7000 then start = getTickCount() end end export of my "meta.xml" (Scripts.zip): <export function="dxDrawLoading" type="client" /> Edited October 16, 2015 by Guest Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 40 view and 0 reply.. nobody can help me ? Link to comment
MIKI785 Posted October 14, 2015 Share Posted October 14, 2015 The expprted function is not dependent on anything else in the resource as far as i can see so just copy it to the resource in which you're calling it. It might even be a bit better for performance than calling exported function each frame but i cant confirm that, its just what i think. Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 Thanks MIKI785, but if I want use my export in multiples resources and I want to call it, how can I do ? because I don't want to make a copy in everyone of resources, I prefer use the call function... Link to comment
LoOs Posted October 14, 2015 Share Posted October 14, 2015 Thanks MIKI785, but if I want use my export in multiples resources and I want to call it, how can I do ? because I don't want to make a copy in everyone of resources, I prefer use the call function... testing :# local start = getTickCount() sx ,sy = guiGetScreenSize() function drawLoad2() start = getTickCount() local saTeam = getPlayerTeam(getLocalPlayer()) local r, g, b = getTeamColor(saTeam) local now = getTickCount() exports["Scripts"]:dxDrawLoading(196*sx/800, 482*sy/600, 422*sx/800, 25*sy/600, 196*sx/800, 450*sy/600, 1.00*sx/800, tocolor(0,0,0,120), tocolor(r,g,b,255), tocolor(r,g,b,255), "Démarrage", 7000, "pricedown") if now > start + 7000 then start = getTickCount() end end Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 (edited) Thanks MIKI785, but if I want use my export in multiples resources and I want to call it, how can I do ? because I don't want to make a copy in everyone of resources, I prefer use the call function... testing :# local start = getTickCount() sx ,sy = guiGetScreenSize() function drawLoad2() start = getTickCount() local saTeam = getPlayerTeam(getLocalPlayer()) local r, g, b = getTeamColor(saTeam) local now = getTickCount() exports["Scripts"]:dxDrawLoading(196*sx/800, 482*sy/600, 422*sx/800, 25*sy/600, 196*sx/800, 450*sy/600, 1.00*sx/800, tocolor(0,0,0,120), tocolor(r,g,b,255), tocolor(r,g,b,255), "Démarrage", 7000, "pricedown") if now > start + 7000 then start = getTickCount() end end Don't work, I have always the problem Edited October 14, 2015 by Guest Link to comment
LoOs Posted October 14, 2015 Share Posted October 14, 2015 (edited) Test : local start = getTickCount() function dxDrawLoading(x, y, width, height, x2, y2, size, color, color2, color3, loadText, second, police) start = getTickCount() local now = getTickCount() local seconds = second local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + tonumber(seconds)) - start), "Linear") local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + tonumber(seconds)) - start),"Linear") dxDrawText ( loadText.."... "..math.floor(text).."%", x2, y2+1 , width, height, color3, size, police ) dxDrawRectangle(x, y ,width ,height -10, color) dxDrawRectangle(x, y, with ,height -10, color2) end I think that the problem of the file that you extracted from it, Because the start seemed to lead by means of a start script Edited October 14, 2015 by Guest Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 now the loading are blocked at 0% Link to comment
LoOs Posted October 14, 2015 Share Posted October 14, 2015 now the loading are blocked at 0% I've modified the code Try Again Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 Still the same error Link to comment
LoOs Posted October 14, 2015 Share Posted October 14, 2015 (edited) Still the same error Are you using 'onClientRender'? and wait a bit ..... ___________________ test : start = getTickCount() function dxDrawLoading(x, y, width, height, x2, y2, size, color, color2, color3, loadText, second, police) start = getTickCount() local now = getTickCount() local seconds = second local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + tonumber(seconds)) - start), "Linear") local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + tonumber(seconds)) - start),"Linear") dxDrawText ( loadText.."... "..math.floor(text).."%", x2, y2+1 , width, height, color3, size, police ) dxDrawRectangle(x, y ,width ,height -10, color) dxDrawRectangle(x, y, with ,height -10, color2) end and delete : start = getTickCount() from file 2 Edited October 14, 2015 by Guest Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 Still the same error Are you using 'onClientRender'? and wait a bit ..... yes, I use the "onClientRender" clientside: function bar() local voiture = getPedOccupiedVehicle(source) local x, y, z = getElementPosition(source) if (getElementData(voiture, "motorS") ~= "dem") then addEventHandler("onClientRender", getRootElement(), drawLoad2) setTimer(function () removeEventHandler("onClientRender", getRootElement(), drawLoad2) setElementData(voiture, "motorS", "not") end, 7000, 1) end end addEvent("showMB", true) addEventHandler("showMB", getRootElement(), bar) my all clientside code: function vol() for i,voiture in ipairs (getElementsByType("vehicle")) do if (getElementData(voiture, "jackingV") == 1) then x, y, z = getElementPosition(voiture) moteur = playSound3D("alarme.mp3", x, y, z) setSoundMaxDistance(moteur, 50) attachElements(moteur, voiture) end end setTimer(function () setSoundMaxDistance(moteur, 0) end, 16000, 1) end addEvent("alarmeV", true) addEventHandler("alarmeV", getRootElement(), vol) function bar() local voiture = getPedOccupiedVehicle(source) local x, y, z = getElementPosition(source) if (getElementData(voiture, "motorS") ~= "dem") then addEventHandler("onClientRender", getRootElement(), drawLoad2) setTimer(function () removeEventHandler("onClientRender", getRootElement(), drawLoad2) setElementData(voiture, "motorS", "not") end, 7000, 1) end end addEvent("showMB", true) addEventHandler("showMB", getRootElement(), bar) --[[local start = getTickCount() sx ,sy = guiGetScreenSize() function drawLoad2() local saTeam = getPlayerTeam(getLocalPlayer()) local r, g, b = getTeamColor(saTeam) local now = getTickCount() exports["Scripts"]:dxDrawLoading(196*sx/800, 482*sy/600, 422*sx/800, 25*sy/600, 196*sx/800, 450*sy/600, 1.00*sx/800, tocolor(0,0,0,120), tocolor(r,g,b,255), tocolor(r,g,b,255), "Démarrage", 7000, "pricedown") if now > start + 7000 then start = getTickCount() end end]] local start = getTickCount() sx ,sy = guiGetScreenSize() function drawLoad2() start = getTickCount() local saTeam = getPlayerTeam(getLocalPlayer()) local r, g, b = getTeamColor(saTeam) local now = getTickCount() exports["Scripts"]:dxDrawLoading(196*sx/800, 482*sy/600, 422*sx/800, 25*sy/600, 196*sx/800, 450*sy/600, 1.00*sx/800, tocolor(0,0,0,120), tocolor(r,g,b,255), tocolor(r,g,b,255), "Démarrage", 7000, "pricedown") if now > start + 7000 then start = getTickCount() end end Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 test : start = getTickCount() function dxDrawLoading(x, y, width, height, x2, y2, size, color, color2, color3, loadText, second, police) start = getTickCount() local now = getTickCount() local seconds = second local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + tonumber(seconds)) - start), "Linear") local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + tonumber(seconds)) - start),"Linear") dxDrawText ( loadText.."... "..math.floor(text).."%", x2, y2+1 , width, height, color3, size, police ) dxDrawRectangle(x, y ,width ,height -10, color) dxDrawRectangle(x, y, with ,height -10, color2) end and delete : start = getTickCount() from file 2 the script don't work again Link to comment
LoOs Posted October 14, 2015 Share Posted October 14, 2015 test : start = getTickCount() function dxDrawLoading(x, y, width, height, x2, y2, size, color, color2, color3, loadText, second, police) start = getTickCount() local now = getTickCount() local seconds = second local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + tonumber(seconds)) - start), "Linear") local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + tonumber(seconds)) - start),"Linear") dxDrawText ( loadText.."... "..math.floor(text).."%", x2, y2+1 , width, height, color3, size, police ) dxDrawRectangle(x, y ,width ,height -10, color) dxDrawRectangle(x, y, with ,height -10, color2) end and delete : start = getTickCount() from file 2 the script don't work again You can make them into a single file, much better than the two files, problems will not occur Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 ok, I will do it, thanks you (even if I prefer use a call function ) Link to comment
MoDeR2014 Posted October 14, 2015 Share Posted October 14, 2015 try this function dxDrawLoading(x, y, width, height, x2, y2, size, color, color2, color3, loadText, second, police) if not start then start = getTickCount() end local seconds = second local with = interpolateBetween(0,0,0,width,0,0, (getTickCount() - start) / ((start + tonumber(seconds)) - start), "Linear") local text = interpolateBetween(0,0,0,100,0,0,(getTickCount() - start) / ((start + tonumber(seconds)) - start),"Linear") dxDrawText ( loadText.."... "..math.floor(text).."%", x2, y2+1 , width, height, color3, size, police ) dxDrawRectangle(x, y ,width ,height -10, color) dxDrawRectangle(x, y, with ,height -10, color2) end Link to comment
TAPL Posted October 14, 2015 Share Posted October 14, 2015 Try this. function dxDrawLoading(x, y, width, height, x2, y2, size, color, color2, color3, loadText, second, police, start, now) local seconds = second local with = interpolateBetween(0,0,0,width,0,0, (now - start) / ((start + tonumber(seconds)) - start), "Linear") local text = interpolateBetween(0,0,0,100,0,0,(now - start) / ((start + tonumber(seconds)) - start),"Linear") dxDrawText ( loadText.."... "..math.floor(text).."%", x2, y2+1 , width, height, color3, size, police ) dxDrawRectangle(x, y ,width ,height -10, color) dxDrawRectangle(x, y, with ,height -10, color2) end sx, sy = guiGetScreenSize() function drawLoad2() local saTeam = getPlayerTeam(getLocalPlayer()) local r, g, b = getTeamColor(saTeam) local now = getTickCount() exports["Scripts"]:dxDrawLoading(196*sx/800, 482*sy/600, 422*sx/800, 25*sy/600, 196*sx/800, 450*sy/600, 1.00*sx/800, tocolor(0,0,0,120), tocolor(r,g,b,255), tocolor(r,g,b,255), "Démarrage", 7000, "pricedown", start, now) if start <= now - 7000 then removeEventHandler("onClientRender", root, drawLoad2) end end addCommandHandler("startloading", function() addEventHandler("onClientRender", root, drawLoad2) start = getTickCount() end) Link to comment
Valentin3526 Posted October 14, 2015 Author Share Posted October 14, 2015 I will not try your scripts now, but I will try later 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