Jump to content

dxDrawCircle


Wumbaloo

Recommended Posts

Hey, i have this code, of the example in the dxDrawCircle wiki page:

local screenWidth, screenHeight = guiGetScreenSize( ) 
local stopAngle = 0 
  
addEventHandler( "onClientRender", root, 
    function( ) 
        if ( stopAngle < 360 ) then 
            stopAngle = stopAngle + 5 
        else 
            stopAngle = 0 
        end 
  
        dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, stopAngle ) 
    end 
) 

And it return me "attempt to call global 'dxDrawCircle' (a nil value)" i don't understand why

Link to comment

dxDrawCircle is an useful function so you need to define it in the script.

function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 

Link to comment
  • Moderators
But don't work when i do this:
local x, y = guiGetScreenSize() 
red = tocolor(255, 0, 0) 
dxDrawCircle(x/2, y/2, 50, 5, 1, 0, 360, red, true) 

Any error on the client-side ?

In general if you have this error:

attempt to call global 'functionNameHere' (a nil value)

Then it means that the function doesn't exist or is not defined yet.

Make sure you have copied and pasted the dxDrawCircle function at the right place.

Link to comment

No errors

 local x, y = guiGetScreenSize() 
red = tocolor(255, 0, 0) 
  
[function] 
  
    if rand == 0 then 
        text = "lui prend la jambe et la mord" 
        addEventHandler("onClientRender", root, 
            function () 
                dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) 
            end) 
    end 
  
function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 

Link to comment
No errors
 local x, y = guiGetScreenSize() 
red = tocolor(255, 0, 0) 
  
[function] 
  
    if rand == 0 then 
        text = "lui prend la jambe et la mord" 
        addEventHandler("onClientRender", root, 
            function () 
                dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) 
            end) 
    end 
  
  
  
function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 

-___-

function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 
  
-- now put your things here ._. 

Link to comment
No errors
 local x, y = guiGetScreenSize() 
red = tocolor(255, 0, 0) 
  
[function] 
  
    if rand == 0 then 
        text = "lui prend la jambe et la mord" 
        addEventHandler("onClientRender", root, 
            function () 
                dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) 
            end) 
    end 
  
function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 

How about not lying?

lsjjs4S.png

Link to comment

You don't understand me, look at my code:

 local x, y = guiGetScreenSize() 
red = tocolor(255, 0, 0) 
  
function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) 
    if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then 
        return false 
    end 
  
    local function clamp( val, lower, upper ) 
        if ( lower > upper ) then lower, upper = upper, lower end 
        return math.max( lower, math.min( upper, val ) ) 
    end 
  
    radius = type( radius ) == "number" and radius or 50 
    width = type( width ) == "number" and width or 5 
    angleAmount = type( angleAmount ) == "number" and angleAmount or 1 
    startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) 
    stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) 
    color = color or tocolor( 255, 255, 255, 200 ) 
    postGUI = type( postGUI ) == "boolean" and postGUI or false 
  
    if ( stopAngle < startAngle ) then 
        local tempAngle = stopAngle 
        stopAngle = startAngle 
        startAngle = tempAngle 
    end 
  
    for i = startAngle, stopAngle, angleAmount do 
        local startX = math.cos( math.rad( i ) ) * ( radius - width ) 
        local startY = math.sin( math.rad( i ) ) * ( radius - width ) 
        local endX = math.cos( math.rad( i ) ) * ( radius + width ) 
        local endY = math.sin( math.rad( i ) ) * ( radius + width ) 
  
        dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) 
    end 
  
    return true 
end 
  
function abc(source) 
    local rand = math.random(0, 6) 
    if rand == 0 then 
        addEventHandler("onClientRender", root, 
        function () 
            dxDrawCircle( x/2, y/2) 
        end) 
    else 
        addEventHandler("onClientRender", root, 
        function () 
            dxDrawCircle( x/2, y/2, 50, 5, 1, 0, 360, red, true) 
        end) 
    end 
end 

Link to comment
  • Moderators

That code works just fine:

efb5aed386f6929fc830f65e78f8e42f.png

and

422e7df0e200201d5a0af0d316024cf5.png

Please make sure you did everything correctly before saying it doesn't work.

Most of the scripters here do not test the scripts, they are guessing the problem and the solutions using what the original poster says and their knowledges.

As I can see you are french, if you prefer, you can ask for help in french in the French subforum.

I saw you were kinda angry because you didn't get a reply in time because I'm kinda alone in that section and I was away from home.

I always watch that French section and I get an email notification for each thread created in that section.

I hope to see you again there:

viewforum.php?f=128

Best regards,

Citizen

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