Absence2 Posted March 4, 2012 Share Posted March 4, 2012 Hello, I'm just wondering if it is possible to use OnPlayerJoin and OnPlayerQuit together with dxDrawText somehow, including other server sided functions, such as onPlayerStealthKill Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 You want create if player quit or join draw it? Use: https://wiki.multitheftauto.com/wiki/OnClientPlayerJoin https://wiki.multitheftauto.com/wiki/OnClientPlayerQuit Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 You want create if player quit or join draw it?Use: https://wiki.multitheftauto.com/wiki/OnClientPlayerJoin https://wiki.multitheftauto.com/wiki/OnClientPlayerQuit I ended up with this, no idea if it works as I can't see myself is this right?: addEventHandler("onClientResourceStart",resourceRoot, function() end ) -- Direct X Drawing addEventHandler("onClientRender",root, function() function remotePlayerJoin() dxDrawText("* " .. getPlayerName(source) .. " has joined the server",618.0,6.0,795.0,27.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) end addEventHandler("onClientPlayerJoin", getRootElement(), remotePlayerJoin) end ) -- Direct X Drawing addEventHandler("onClientRender",root, function() function remotePlayerJoin() dxDrawText("* " .. getPlayerName(source) .. " has left the server ("..reason..")",618.0,6.0,795.0,27.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) end addEventHandler("onClientPlayerJoin", getRootElement(), remotePlayerJoin) end ) addEventHandler("onClientResourceStart",resourceRoot, function() end ) -- Direct X Drawing addEventHandler("onClientRender",root, function() dxDrawRectangle(631.0,7.0,160.0,20.0,tocolor(0,0,0,150),false) end ) I also noticed that this caused a LOT of server lags for some reason Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 Learn viewtopic.php?f=91&t=40809 https://wiki.multitheftauto.com/wiki/Scr ... troduction Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 Learn viewtopic.php?f=91&t=40809https://wiki.multitheftauto.com/wiki/Scr ... troduction I am trying, that is why I'm here. function quiterPlayer ( quitReason ) local quiterPlayerName = getPlayerName ( source ) local root = getRootElement() local rootChildren = getElementChildren( root ) dxDrawText("#FFFFFFServer: #FFFFFF"..quiterPlayerName .. " has left the server (" .. quitReason .. ")",388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) end addEventHandler ( "onClientPlayerQuit", getRootElement(), quiterPlayer ) addEventHandler("onClientResourceStart",resourceRoot, function() end ) -- Direct X Drawing addEventHandler("onClientRender",root, function() dxDrawRectangle(631.0,7.0,160.0,20.0,tocolor(0,0,0,150),false) end ) what about this then? though, this error turned up, input:8: attempt to call global 'getRootElement' (a nil value) Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 Why you use it in event? local root = getRootElement() local rootChildren = getElementChildren( root ) root is predefined variable. viewtopic.php?f=91&t=39678 getRootElement is root Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 Why you use it in event? local root = getRootElement() local rootChildren = getElementChildren( root ) root is predefined variable. viewtopic.php?f=91&t=39678 getRootElement is root I tested with and without it, both of them, separete and so on, always returned nil, wasn't sure what to do and left them in there. I am completely lost Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 local sText, sReason = '','' local uTimer addEventHandler ( 'onClientPlayerQuit', root, function( quitReason ) sText, sReason = getPlayerName( source ), quitReason if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( '#FFFFFFServer: #FFFFFF'.. sText .. ' has left the server (' .. sReason .. ')',388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) And why you not update text in render? Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 local sText, sReason = '','' local uTimer addEventHandler ( 'onClientPlayerQuit', root, function( quitReason ) sText, sReason = getPlayerName( source ), quitReason if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( '#FFFFFFServer: #FFFFFF'.. sText .. ' has left the server (' .. sReason .. ')',388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) And why you not update text in render? (And I'll test it soon, thanks, imposible to figure that out by myself..) What do you mean? Like a row? like: name name name or when another guy logs in the previous name goes off? Also, this would be the playerjoin right? local sText = '' local uTimer addEventHandler ( 'onClientPlayerJoin', root, function() sText = getPlayerName( source ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( '#FFFFFFServer: #FFFFFF'.. sText .. ' has joined the server ',388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) Just have to make sure, your scripts are bit different from the other ones I have seen o_o Link to comment
drk Posted March 4, 2012 Share Posted March 4, 2012 I think this is more easy to understand... local join = '' local quit = '' addEventHandler('onClientRender',root, function() dxDrawText(join,x,y,width,height,color,size,font,left,top,clip,wordbreak,postGUI) dxDrawText(quit,x,y,width,height,color,size,font,left,top,clip,wordbreak,postGUI) end ) addEventHandler('onClientPlayerJoin',root, function() join = getPlayerName(source).." has joined the game!" setTimer( function() join = '' end, 5000,1) end ) addEventHandler('onClientPlayerQuit',root, function(reason) quit = getPlayerName(source).." has left the game! Reason: "..reason setTimer( function() quit = '' end, 5000,1) end ) Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 local sText = '' local uTimer addEventHandler ( 'onClientPlayerQuit', root, function( quitReason ) sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has left the server (%s) \n',getPlayerName( source ), quitReason ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) Example output: Server: Kenix has left the server (Timed out) Server: Draken has left the server (Quit) Server: RainyLawyer has left the server (Quit) I think this is more easy to understand... Nope string.format easy understand P.S 2000 post Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 It's really hard to test this script without anyone around ._. Anyways, since that doesn't seem to stick to one spot on "every" resolution, I tried this: local sText, sReason = '','' local uTimer addEventHandler ( 'onClientPlayerQuit', root, function( quitReason ) sText, sReason = getPlayerName( source ), quitReason if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) local screenWidth, screenHeight = guiGetScreenSize() local nSw,nSh = guiGetScreenSize( ) local rootElement = getRootElement() local x,y = guiGetScreenSize() -- Get players resolution. if sText ~= '' then dxDrawText( '#FFFFFFServer: #FFFFFF'.. sText .. ' has left the server (' .. sReason .. ')',nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.55,"bankgothic","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) local sText = '' local uTimer addEventHandler ( 'onClientPlayerJoin', root, function() sText = getPlayerName( source ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) local screenWidth, screenHeight = guiGetScreenSize() local nSw,nSh = guiGetScreenSize( ) local rootElement = getRootElement() local x,y = guiGetScreenSize() -- Get players resolution. if sText ~= '' then dxDrawText( '#FFFFFFServer: #FFFFFF'.. sText .. ' has joined the server ',nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.55,"bankgothic","left","top",false,false,false) dxDrawRectangle ( x/3.4, y/1.6, x/2.13, y/4.2, tocolor ( 0, 0, 0, 150 ) ) end end ) Will this work or is it just rubbish Oh and by the way, how the hell do I calculate the positions? I have to try for like ages until I get it right PLUS I have to test when players login or quit, so it's very hard Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 (edited) is it just rubbish Use my code Which one you posted two & what's the difference between those two? Edited March 4, 2012 by Guest Link to comment
drk Posted March 4, 2012 Share Posted March 4, 2012 It's really hard to test this script without anyone around ._.Anyways, since that doesn't seem to stick to one spot on "every" resolution, I tried this: local sText, sReason = '','' local uTimer addEventHandler ( 'onClientPlayerQuit', root, function( quitReason ) sText, sReason = getPlayerName( source ), quitReason if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) local screenWidth, screenHeight = guiGetScreenSize() local nSw,nSh = guiGetScreenSize( ) local rootElement = getRootElement() local x,y = guiGetScreenSize() -- Get players resolution. if sText ~= '' then dxDrawText( '#FFFFFFServer: #FFFFFF'.. sText .. ' has left the server (' .. sReason .. ')',nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.55,"bankgothic","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) local sText = '' local uTimer addEventHandler ( 'onClientPlayerJoin', root, function() sText = getPlayerName( source ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) local screenWidth, screenHeight = guiGetScreenSize() local nSw,nSh = guiGetScreenSize( ) local rootElement = getRootElement() local x,y = guiGetScreenSize() -- Get players resolution. if sText ~= '' then dxDrawText( '#FFFFFFServer: #FFFFFF'.. sText .. ' has joined the server ',nSw/3, nSh/1.47, nSw, nSh,tocolor(255,255,255,185),0.55,"bankgothic","left","top",false,false,false) dxDrawRectangle ( x/3.4, y/1.6, x/2.13, y/4.2, tocolor ( 0, 0, 0, 150 ) ) end end ) Will this work or is it just rubbish Oh and by the way, how the hell do I calculate the positions? I have to try for like ages until I get it right PLUS I have to test when players login or quit, so it's very hard local sx, sy = guiGetScreenSize() dxDrawText(join,(posX/yourResolutionX)*sx,(posY/yourResolutionY)*sy,(width/yourResolutionX)*sx,(height/yourResolutionY)*sy,tocolor(255,255,255,255),0.6,"pricedown","left","top",false,false,true) Example: local sx, sy = guiGetScreenSize() dxDrawText("My text",(10/800)*sx,(200/600)*sy,(10/800)*sx,(200/600)*sy,tocolor(255,255,255,255),0.6,"pricedown","left","center",false,false,true) Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 is it just rubbish Use my code Which one you posted two & what's the difference between those two? Example output:Server: Kenix has left the server (Timed out) Server: Draken has left the server (Quit) Server: RainyLawyer has left the server (Quit) This. Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 Oh, okay, fantastic but I'm still worried about the resolution, or should it work fine on any resolution? Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 Just use my function. function dxDrawRelativeText( text,posX,posY,right,bottom,color,scale,mixed_font,alignX,alignY,clip,wordBreak,postGUI ) local resolutionX = 1280 local resolutionY = 1024 local sWidth,sHeight = guiGetScreenSize( ) return dxDrawText( tostring( text ), ( posX/resolutionX )*sWidth, ( posY/resolutionY )*sHeight, ( right/resolutionX )*sWidth, ( bottom/resolutionY)*sHeight, color,( sWidth/resolutionX )*scale, mixed_font, alignX, alignY, clip, wordBreak, postGUI ) end The arguments are the same as in dxDrawText. Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 Just use my function. function dxDrawRelativeText( text,posX,posY,right,bottom,color,scale,mixed_font,alignX,alignY,clip,wordBreak,postGUI ) local resolutionX = 1280 local resolutionY = 1024 local sWidth,sHeight = guiGetScreenSize( ) return dxDrawText( tostring( text ), ( posX/resolutionX )*sWidth, ( posY/resolutionY )*sHeight, ( right/resolutionX )*sWidth, ( bottom/resolutionY)*sHeight, color,( sWidth/resolutionX )*scale, mixed_font, alignX, alignY, clip, wordBreak, postGUI ) end The arguments are the same as in dxDrawText. Oh, like this then: local sText = '' local uTimer addEventHandler ( 'onClientPlayerJoin', root, function() sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has joined the server (%s) \n',getPlayerName( source ) ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end ) addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawRelativeText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRelativeRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) Also the onClientPlayerJoin, doesn't work, it gave error at line 34 about the string format (I can't login atm so I can't check exactly >.<) Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 (edited) Yes, because you change it. sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has left the server (%s) \n',getPlayerName( source ), quitReason ) Example: print( string.format( "I am %s. I going %s",'Kenix','finish my votemanager.' ) ) Output: I am Kenix. I going finish my votemanager. You use Example print( string.format( "I am %s, going %s",'Kenix' ) ) Output: bad argument #3 to 'format' (no value) Because you not use 2 regular expression. Read it please ! viewtopic.php?f=91&t=40809 Edited March 4, 2012 by Guest Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 Yes, because you change it. sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has left the server (%s) \n',getPlayerName( source ), quitReason ) Example: print( string.format( "I am %s. I going %s",'Kenix','finish my votemanager.' ) ) output: I am Kenix. I going finish my votemanager. You use Example print( string.format( "I am %s, going %s",'Kenix' ) ) Output: input:1: bad argument #3 to 'format' (no value) But I can't keep quitreason if it's playerjoin, or can I? Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 Very easy local sText = '' local uTimer function fDraw( ) sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has %s the server %s \n', getPlayerName( source ), eventName == 'onClientPlayerQuit' and 'left' or eventName == 'onClientPlayerJoin' and 'join', eventName == 'onClientPlayerQuit' and '(' .. quitReason .. ')' or '' ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) addEventHandler ( 'onClientPlayerQuit', root, fDraw ) addEventHandler ( 'onClientPlayerJoin', root, fDraw ) Updated. eventName is predefined variable. Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 (edited) Very easy local sText = '' local uTimer function fDraw( ) sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has %s the server %s \n', getPlayerName( source ), eventName == 'onClientPlayerQuit' and 'left' or eventName == 'onClientPlayerJoin' and 'join', eventName == 'onClientPlayerQuit' and '(' .. quitReason .. ')' or '' ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) addEventHandler ( 'onClientPlayerQuit', root, fDraw ) addEventHandler ( 'onClientPlayerJoin', root, fDraw ) Updated. eventName is predefined variable. it does look nice but it doesn't seem to work, asked a guy to login / logout and no text was shown. Scratch that, it does work, thank you so much for your help I really appreciate it! And I guess I missed something with the relative - it's nil. local sText = '' local uTimer function fDraw( ) sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has %s the server %s \n', getPlayerName( source ), eventName == 'onClientPlayerQuit' and 'left' or eventName == 'onClientPlayerJoin' and 'join', eventName == 'onClientPlayerQuit' and '(' .. quitReason .. ')' or '' ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawRelativeText( sText,254.0,0.0,585.0,25.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRelativeRectangle( 258.0,0.0,328.0,21.0,tocolor( 0,0,0,150 ),false ) end end ) addEventHandler ( 'onClientPlayerQuit', root, fDraw ) addEventHandler ( 'onClientPlayerJoin', root, fDraw ) I guess I'm supposed to add something else but didn't you say like this earlier , also I "figured it out", join works, quit doesn't, it's something quitreason, saying it's nil or something Do I just add this: function dxDrawRelativeText( text,posX,posY,right,bottom,color,scale,mixed_font,alignX,alignY,clip,wordBreak,postGUI ) local resolutionX = 1280 local resolutionY = 1024 local sWidth,sHeight = guiGetScreenSize( ) return dxDrawText( tostring( text ), ( posX/resolutionX )*sWidth, ( posY/resolutionY )*sHeight, ( right/resolutionX )*sWidth, ( bottom/resolutionY)*sHeight, color,( sWidth/resolutionX )*scale, mixed_font, alignX, alignY, clip, wordBreak, postGUI ) end in the .lua file or what? Edited March 4, 2012 by Guest Link to comment
Kenix Posted March 4, 2012 Share Posted March 4, 2012 local sText = '' local uTimer function fDraw( quitReason ) sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has %s the server %s \n', getPlayerName( source ), eventName == 'onClientPlayerQuit' and 'left' or eventName == 'onClientPlayerJoin' and 'join', eventName == 'onClientPlayerQuit' and '(' .. quitReason .. ')' or '' ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) addEventHandler ( 'onClientPlayerQuit', root, fDraw ) addEventHandler ( 'onClientPlayerJoin', root, fDraw ) My bad. I forgot add argument quitReason to function fDraw. It should work. Link to comment
Absence2 Posted March 4, 2012 Author Share Posted March 4, 2012 local sText = '' local uTimer function fDraw( quitReason ) sText = sText..string.format( '#FFFFFFServer: #FFFFFF%s has %s the server %s \n', getPlayerName( source ), eventName == 'onClientPlayerQuit' and 'left' or eventName == 'onClientPlayerJoin' and 'join', eventName == 'onClientPlayerQuit' and '(' .. quitReason .. ')' or '' ) if isTimer( uTimer ) then killTimer( uTimer ) end uTimer = setTimer( function( ) sText = '' end, 5000, 1 ) end addEventHandler( 'onClientRender', root, function( ) if sText ~= '' then dxDrawText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) end end ) addEventHandler ( 'onClientPlayerQuit', root, fDraw ) addEventHandler ( 'onClientPlayerJoin', root, fDraw ) My bad. I forgot add argument quitReason to function fDraw. It should work. Do I just change dxDrawText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) to dxDrawRelativeText( sText,388.0,134.0,558.0,163.0,tocolor(255,255,255,255),1.0,"default","left","top",false,false,false) dxDrawRelativeRectangle( 631.0,7.0,160.0,20.0,tocolor( 0,0,0,150 ),false ) Because I tried and it goes nil everytime, not really sure what to do with "Relative", never seen in any script I've bumped in to so far. Link to comment
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