Jump to content

[Help]dxDrawText


bebo1king

Recommended Posts

Hello , i am trying to make so simple mod but i got some problems

local screenW,screenH = guiGetScreenSize () 
  
  
addEventHandler( "onClientPlayerStuntStart", getRootElement( ), 
    function ( stuntType ) 
        --outputChatBox( "You started stunt: " .. stuntType ); 
    end 
); 
  
addEventHandler( "onClientPlayerStuntFinish", getRootElement( ), 
    function ( stuntType, stuntTime, distance ) 
        dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
    end 
); 

the problem is the dxDrawText is showing so fast then it disappear

Link to comment
Because you should use
"onClientRender" 

Event for Dx functions!

i see it same

addEventHandler ( "onClientRender", getRootElement( ), 
addEventHandler( "onClientPlayerStuntFinish", getRootElement( ), 
    function ( stuntType, stuntTime, distance ) 
        dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
    end 
)); 

Link to comment
  
addEventHandler( "onClientPlayerStuntFinish", getRootElement( ), 
function() 
addEventHandler("onClientRender",root,lol) 
end 
) 
    function lol( stuntType, stuntTime, distance ) 
        dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
    end 
  

Link to comment
addEventHandler( "onClientPlayerStuntFinish", root,function lol( stuntType, stuntTime, distance ) 
        dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
end 
     
function() 
addEventHandler("onClientRender",root,lol) 
end 
) 

now the proplem is line1 '(' is expected near lol

this script proplems more than lines :D

Edited by Guest
Link to comment

You forgot the parenthesis at the end of your function. I'd highly recommend you check out the Debugging section of the Wiki.

I'd argue against writing your code like that, and instead write it like this;

function ExampleCode(stuntType, stuntTime, distance) 
-- Code here 
end 
addEventHandler("onClientPlayerStuntFinish", root, ExampleCode) 

Personally I think it's much easier to read your own code when structured this way instead. :)

Link to comment

ok now there is no error but we will back to the main point i was asking help for is that

the problem is the dxDrawText is showing so fast then it disappear

the full code right now

local screenW,screenH = guiGetScreenSize () 
  
function lol(stuntType, stuntTime, distance) 
  dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
end 
addEventHandler("onClientPlayerStuntFinish", root, lol) 
     
function nothing () 
addEventHandler("onClientRender",root,lol) 
end 

Link to comment

Because this code is never executed;

function nothing () 
addEventHandler("onClientRender",root,lol) 
end 

Try this;

local screenW,screenH = guiGetScreenSize () 
  
function lol(stuntType, stuntTime, distance) 
  dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
end 
    
function nothing() 
    addEventHandler("onClientRender", root, lol) 
end 
addEventHandler("onClientPlayerStuntFinish", root, nothing) 

Link to comment
Because this code is never executed;
function nothing () 
addEventHandler("onClientRender",root,lol) 
end 

Try this;

local screenW,screenH = guiGetScreenSize () 
  
function lol(stuntType, stuntTime, distance) 
  dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
end 
    
function nothing() 
    addEventHandler("onClientRender", root, lol) 
end 
addEventHandler("onClientPlayerStuntFinish", root, nothing) 

here is the error of your code

lua:4: attempt to concatnate local 'stunt'type (a nil value)

Link to comment

That's an error in your code, not mine.

Do you even read the error?

lua:4: attempt to concatnate local 'stunt'type (a nil value)

This means the error occurred at Line 4 in your code. The variable stuntType is returning a nil value - which means it's empty or doesn't exist.

Link to comment

Try this:

local screenW, screenH = guiGetScreenSize(); 
  
addEventHandler("onClientPlayerStuntFinish", getRootElement(), function(sty, sti, dis) 
    stuntType = sty; 
    stuntTime = sti; 
    distance = dis; 
    addEventHandler("onClientRender", getRootElement(), drawStunt); 
    setTimer( 
        removeEventHandler("onClientRender", getRootElement(), drawStunt) 
        stuntType = nil; 
        stuntTime = nil; 
        distance = nil; 
    end, 1000, 1); 
end); 
  
function drawStunt() 
    dxDrawText("You finished stunt: " .. stuntType ..", Time: " .. tostring( stuntTime ).. ", Distance: " .. tostring( distance ), screenW * 0.2219, screenH * 0.7935, screenW * 0.8839, screenH * 0.8963, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false); 
end 

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