Jump to content

[Solved] Error with call function


Valentin3526

Recommended Posts

Posted (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 by Guest

Valentin3526 | dfigfjf:

Posted

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.

Lua Scripter

?ucet=miki_cz

Owner of mshost.cz MTA portal.

Posted
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 

Discord: LoOs#1111

_____________________________

76561198299431254.png

Posted (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 by Guest

Valentin3526 | dfigfjf:

Posted (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 by Guest

Discord: LoOs#1111

_____________________________

76561198299431254.png

Posted (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 by Guest

Discord: LoOs#1111

_____________________________

76561198299431254.png

Posted
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 

Valentin3526 | dfigfjf:

Posted
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

Valentin3526 | dfigfjf:

Posted
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

Discord: LoOs#1111

_____________________________

76561198299431254.png

Posted

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 

4m2k75U.pngbutton_4.PNG

Skype : mohammed.almoudeer1

Github : MoDeR2014

Community : MoDeR2014

Youtube : MoDeR2014

Posted

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) 

CiTLh.png

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