Jump to content

Pls Correct


Scripting

Recommended Posts

Hi People,

I m set this code:

for id, player in ipairs ( getElementsByType ( "player" ) ) do 

To drawe Text to all players when I Command,

but don t work!

Pls fix that and thx

client-side:

function onCommand() 
  
function draw () 
  
sWidth, sHeight = guiGetScreenSize() 
        find = "The Word: Welcome!" 
dxDrawText(tostring (find),sWidth-700,sHeight-200,sWidth-350,sHeight-100,tocolor(255,255,0),1.0,"bankgothic","right","top",false,false,false) -- Money DX text 
end 
addEventHandler("onClientRender", getRootElement(), draw) 
end 
addCommandHandler ( "drawWel",onCommand) 

Link to comment

Are you trying to draw a dxtext when you enter the command "drawWel" or what the hell?

local sWidth,sHeight = guiGetScreenSize() 
local find = "The Word: Welcome!" 
  
function drawDXText ( command ) 
    dxDrawText(find,sWidth-700,sHeight-200,sWidth-350,sHeight-100,tocolor(255,255,0),1.0,"bankgothic","right","top",false,false,false) 
end 
  
addCommandHandler ( "drawWel",  
    function() 
        addEventHandler ( "onClientRender", root, drawDXText ) 
    end 
) 

Link to comment

-- client side:

local sWidth,sHeight = guiGetScreenSize ( ) 
local find = "The Word: Welcome!" 
  
function drawDXText ( ) 
    dxDrawText ( find, sWidth - 700, sHeight - 200, sWidth - 350, sHeight - 100, tocolor ( 255, 255, 0 ), 1.0, "bankgothic", "right", "top", false, false, false ) 
end 
  
addEvent ( "drawTheText", true ) 
addEventHandler ( "drawTheText", root, 
    function ( ) 
        addEventHandler ( "onClientRender", root, drawDXText ) 
    end 
) 

-- server side:

addCommandHandler ( "drawWel", 
    function ( ) 
        for index, player in ipairs ( getElementsByType ( "player" ) ) do 
            triggerClientEvent ( player, "drawTheText", player ) 
        end 
    end 
) 

Link to comment

In triggerClientEvent, where recipient - root element, it's better with loop,in this case the function only finds the players in the element tree. But if you use loop then it creates additional packet in each request. Also if root element - source in trigger (Client/Server) Event this is bad. MTA loops all the elements in the element tree and attaches each handler to it for the event.

Edited by Guest
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...