tosfera Posted February 15, 2013 Posted February 15, 2013 hey guys, I'm trying to create a text, for just a short amount of time (5 seconds). So what I'm basicly trying to do right now, is that a user enters a command (/et), the error msg will be drawn for 5 seconds on the client's screen. So far I got this; server: addCommandHandler("et", function ( source ) triggerClientEvent(source, "errorMsg", root, "test") end ) Client: function errorMsg ( errorStr ) addEventHandler("onClientRender", root, drawErrorMsg(errorStr) ) end addEvent( "errorMsg", true ) addEventHandler( "errorMsg", getRootElement(), errorMsg ) function drawErrorMsg (errorStr) dxDrawText ( errorStr, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) end it seems like the onClientRender doesn't rly work, cause it just creates the error for 1 frame... Thanks in advance! - Tosfera If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
DNL291 Posted February 15, 2013 Posted February 15, 2013 Try this (Clientside): function errorMsg ( errorStr ) addEventHandler("onClientRender", root, drawErrorMsg ) drawErrorMsg(errorStr) end addEvent( "errorMsg", true ) addEventHandler( "errorMsg", getRootElement(), errorMsg ) function drawErrorMsg (errorStr) dxDrawText ( tostring(errorStr), screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) end Please do not PM me with scripting related question nor support, use the forums instead.
Castillo Posted February 15, 2013 Posted February 15, 2013 That won't work either. errorMsg = "" function errorMsg ( errorStr ) errorMsg = errorStr addEventHandler("onClientRender", root, drawErrorMsg ) setTimer ( function ( ) removeEventHandler("onClientRender", root, drawErrorMsg ) end ,5000, 1 ) end addEvent( "errorMsg", true ) addEventHandler( "errorMsg", getRootElement(), errorMsg ) function drawErrorMsg ( ) dxDrawText ( errorMsg, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) end San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
tosfera Posted February 16, 2013 Author Posted February 16, 2013 Thanks Castillo, once again. Your script works! And when I'm looking at it, it looks so logic and easy.. If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
50p Posted February 16, 2013 Posted February 16, 2013 That won't work either. errorMsg = "" function errorMsg ( errorStr ) errorMsg = errorStr addEventHandler("onClientRender", root, drawErrorMsg ) setTimer ( function ( ) removeEventHandler("onClientRender", root, drawErrorMsg ) end ,5000, 1 ) end addEvent( "errorMsg", true ) addEventHandler( "errorMsg", getRootElement(), errorMsg ) function drawErrorMsg ( ) dxDrawText ( errorMsg, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) end Why create anonymous function if you can pass arguments to setTimer? setTimer ( removeEventHandler, 5000, 1, "onClientRender", root, drawErrorMsg ) - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
tosfera Posted February 16, 2013 Author Posted February 16, 2013 Ugh I hate to ask stupid questions but I hope this will be my last one! I'm getting a bad 'team' pointer on getTeamName. (trying to save the player teams and give them back when I restart my source) for id, player in ipairs(getElementsByType("player")) do local team = getTeamName ( getPlayerTeam ( player ) ) local account = getPlayerAccount(player) local teamEnd = getAccountData(account, "player-team", team) setPlayerTeam(player, getTeamFromName( teamEnd ) ) end If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
TAPL Posted February 16, 2013 Posted February 16, 2013 I didn't understand what you trying to do, can you explain somehow better? local teamEnd = getAccountData(account, "player-team", team) setPlayerTeam(player, getTeamFromName( teamEnd ) ) I am guess that you meant to use setAccountData not getAccountData or you forgot and put 3 arguments in getAccountData but it required 2 arguments only. but still if you was meant setAccountData, teamEnd will be a bool and you can't get team from bool, team name must be string lol.
Castillo Posted February 16, 2013 Posted February 16, 2013 That won't work either. errorMsg = "" function errorMsg ( errorStr ) errorMsg = errorStr addEventHandler("onClientRender", root, drawErrorMsg ) setTimer ( function ( ) removeEventHandler("onClientRender", root, drawErrorMsg ) end ,5000, 1 ) end addEvent( "errorMsg", true ) addEventHandler( "errorMsg", getRootElement(), errorMsg ) function drawErrorMsg ( ) dxDrawText ( errorMsg, screenWidth - (screenWidth /4), screenHeight - (screenHeight/2), screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1 ) end Why create anonymous function if you can pass arguments to setTimer? setTimer ( removeEventHandler, 5000, 1, "onClientRender", root, drawErrorMsg ) Last time I checked, it didn't work this way, haven't tested it since then. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
tosfera Posted February 16, 2013 Author Posted February 16, 2013 I didn't understand what you trying to do, can you explain somehow better? local teamEnd = getAccountData(account, "player-team", team) setPlayerTeam(player, getTeamFromName( teamEnd ) ) I am guess that you meant to use setAccountData not getAccountData or you forgot and put 3 arguments in getAccountData but it required 2 arguments only. but still if you was meant setAccountData, teamEnd will be a bool and you can't get team from bool, team name must be string lol. Thanks! works! If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]
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