Jump to content

Requesting function help.


patriot

Recommended Posts

Posted

Hi guys,

I need a clientside function that creates a dxText using parameters, for example:

function dxText(string text, local time)

Parameters:

string text = the text of the dxDrawtext.

local time = the time, in milliseconds for setTimer until the text disappears.

Basically, the function creates a dxDrawText for a specified time.

Thanks!

Posted

I can actually make it myself, but I don't know why that thing isn't working. Once I know what's the error in the following code, I will be able to make what I mentioned above.

  
function outPutFunc(string text) 
outputChatBox ( text ) 
end 
  

  
outPutFunc("Test") 
  

Posted

use this ban example and try to fix it

function announceBan( theBan ) 
    if getElementType( source ) then --Check if a player banned the IP/Serial 
        outputChatBox( getPlayerName( source ) .. " banned " .. ( getBanSerial(theBan) or getBanIP(theBan) ) ) --Output to the chatbox saying the player has banned the IP/Serial 
    end 
end 
  
addEventHandler( "onBan", root, announceBan ) --Adds the event handler for 'onBan' and must be bound to root 

Posted

All I wanted to know.

How do I make a bool parameter inside a function?

As far as I see when writing a LUA function there is no need to specifcy whether the parameter is a string ot int, but what when it comes to bool?

Posted
function testFunction ( argument ) 
    outputChatBox ( "Argument value is '".. ( argument and "true" or "false" ) .."'" ) 
end 
  
testFunction ( true ) 
testFunction ( false ) 

Is that what you meant?

Posted (edited)
All I wanted to know.

How do I make a bool parameter inside a function?

As far as I see when writing a LUA function there is no need to specifcy whether the parameter is a string ot int, but what when it comes to bool?

It's exactly the same.

local variable = 2; 
print( type( variable ) ); -- 'number' 
  
variable = "Something is wrong over there..."; 
print( type( variable ) ); -- 'string' 
  
variable = true; 
print( type( variable ) ); -- 'boolean' 

In Lua, you can change variable types by simply changing to a value of the type you want. In C++, for example, the type of the variables are "constant" - they're set at compile time and you can't change them at runtime ( well, actually you can but you might lose precision ).

Edited by Guest
Posted

Nevermind, got this already.

However, I tried to make the function that I wanted:

  
function dxText( text, timer ) 
    setTimer ( function() 
    dxDrawText ( .... ) 
    end, timer, 1 ) 
end 
  

  
addCommandHandler("showtext",function() 
dxGameText("Text test", 2000) 
end) 
  

But the text shows only after the specificed time and then disappears right away...

Posted

Okay then, I will simply handle a dxDrawText with no text at all ("") and change it everytime by setting a varaiable which stores the text. Then I will create a timer to reset the text ("") and I guess problem sorted out.

Sorry for being so LUA newbie.

Posted

A more efficient way ( you won't notice it, but if you add more texts it may starting lagging ) is to create an "onClientRender" event and call it when you want to draw the text. You'll still need variables, though.

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