Scripting Posted April 15, 2012 Posted April 15, 2012 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)
Smart. Posted April 15, 2012 Posted April 15, 2012 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 )
Castillo Posted April 15, 2012 Posted April 15, 2012 -- 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 )
Kenix Posted April 15, 2012 Posted April 15, 2012 (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 April 15, 2012 by Guest
Castillo Posted April 15, 2012 Posted April 15, 2012 Yeah, I supposed someone was going to reply about that . Anyway, getRootElement ( ) will trigger for everything, won't it? player, resources, vehicles?
MTA Team qaisjp Posted April 15, 2012 MTA Team Posted April 15, 2012 you cant trigger events on elements other than players, mta sorts that out for you
Kenix Posted April 15, 2012 Posted April 15, 2012 addCommandHandler ( "drawWel", function ( uPlayer ) triggerClientEvent ( root, "drawTheText", uPlayer ) end ) Better way.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now