Jump to content

Pls Correct


Scripting

Recommended Posts

Posted

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) 

Posted

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 
) 

lol

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

Yeah, I supposed someone was going to reply about that ;).

Anyway, getRootElement ( ) will trigger for everything, won't it? player, resources, vehicles?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
addCommandHandler ( "drawWel", 
    function ( uPlayer ) 
        triggerClientEvent ( root, "drawTheText", uPlayer ) 
    end 
) 

Better way.

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

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