Deepu Posted February 10, 2014 Share Posted February 10, 2014 Castillo I've been in your server before the ban. I saw those DxDrawText things that gets updated each frame. can you explain and give an example of that? Cuz none of them could help me with that. and I dint understand in WiKi I made one but it makes DxDrawText over the first one and both of the texts are visible. If you know abt this please help me castillo thanks in advance Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 (edited) I had some spare time and made you a small example script on drawing. It's nothing too fancy, but it's something that you can understand and learn, hopefully. Read the comments I made, those explain what's happening on each step. Feel free to change and test the script as much as you want, that's the only way you can learn what something does and how it does it and such. local screenWidth, screenHeight = guiGetScreenSize( ) -- Get the client's screen width and height (absolute resolution) local transparency, transparencyStep, fadeSpeed = 255, true, 2 -- Define the default transparency, transparency step and fade speed local tick = getTickCount( ) -- Define the script's start tick count local textToDisplay = "nil" -- Define a default text to display local postGUI = false -- Define if the drawings should be drawn on top of GUI elements local tickTexts = { -- An array containing texts for the text drawings "This is a small test script for drawings.", "And this is an amazing tick count test.", "This is pretty fancy right?", "And the current transparency level is " } addEventHandler( "onClientRender", root, -- Initialize a renderer event function( ) if ( transparencyStep ) then -- If the transparency step is set to 'true' (fade out), then fade out with the speed we defined above transparency = transparency - math.min( 10, fadeSpeed ) -- Decrease transparency level and make a limit at 10 (so you can't make the speed 999999, which doesn't work) if ( transparency <= 0 ) then -- If the transparency level is equal to, or lower than 0, then set the transparency step to 'false' (fade in) transparencyStep = false end else -- If the transparency step is set to 'false' (fade in), then fade in with the speed we defined above transparency = transparency + math.min( 10, fadeSpeed ) -- Decrease transparency level and make a limit at 10 (so you can't make the speed 999999, which doesn't work) if ( transparency >= 255 ) then -- If the transparency level is equal to, or lower than 255, then set the transparency step to 'true' (fade out) transparencyStep = true end end if ( getTickCount( ) - tick >= 1500 ) and ( getTickCount( ) - tick < 4500 ) then -- If the ticks are equal to, or higher than 1500, but lower than 4500, then set the text to the array key 2 textToDisplay = tickTexts[ 2 ] elseif ( getTickCount( ) - tick >= 4500 ) and ( getTickCount( ) - tick < 6500 ) then -- If the ticks are equal to, or higher than 4500, but lower than 6500, then set the text to the array key 3 textToDisplay = tickTexts[ 3 ] elseif ( getTickCount( ) - tick >= 6500 ) then -- If the ticks are equal to, or higher than 6500, then set the text to the array key 4 textToDisplay = tickTexts[ 4 ] .. transparency else -- If the ticks are something else, then display the first key of the array textToDisplay = tickTexts[ 1 ] end -- Define the background color local backgroundColor = tocolor( 0, 0, 0, 100 ) -- Define the text's font size, family and color local textFontSize, textFontFamily, textColor = 1.5, "default-bold", tocolor( 238, 238, 238, transparency ) -- Transparency is fading in and out above local textWidth, textHeight = dxGetTextWidth( textToDisplay, textFontSize, textFontFamily ), dxGetFontHeight( textFontSize, textFontFamily ) -- Define the text width and height we're currently reading dxDrawRectangle( 0, 0, screenWidth, screenHeight, backgroundColor, postGUI ) -- Draw a rectangle on the whole screen with the transparency of 100 dxDrawText( textToDisplay, ( screenWidth - textWidth ) / 2 + 1, ( screenHeight - textHeight ) / 2 + 1, textWidth, textHeight, tocolor( 13, 13, 13, transparency ), textFontSize, textFontFamily, "center", "center", false, false, postGUI, false, false ) -- Draw a light shadow under the main text, which is drawn next dxDrawText( textToDisplay, ( screenWidth - textWidth ) / 2, ( screenHeight - textHeight ) / 2, textWidth, textHeight, textColor, textFontSize, textFontFamily, "center", "center", false, false, postGUI, false, false ) -- Draw the text we defined above end ) Edited February 10, 2014 by Guest Link to comment
Deepu Posted February 10, 2014 Author Share Posted February 10, 2014 (edited) WTF cool ! can u tell me the things that u did? I know about the variable and things but what you did? like getElementData? explain detailly pleaseeeeeeeeeee Edited February 10, 2014 by Guest Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 (edited) I made you a list of the main things I made in the script, these are the following: Screen width and height: I defined two variables for the screen width and height. I need those to center the text and draw the rectangle right on top of the absolute resolution of the client's window. Transparency, transparency step and fade speed: I defined the default transparency, step and speed in order for the fader part to work, otherwise it will throw indefinite errors because of undefined variables. Tick count: I defined a variable for the default tick. The default tick count is used to measure the milliseconds that the resource has been running, this is used because I want to change the text over time. Text to display: I defined the variable because again, it will throw errors otherwise. The variable is changed over time to the values defined in the text array. Tick texts: These text phrases are defined for the over time changing part. Rendering event: I initialized the render event in order to draw the stuff. If I didn't define the render event, it would display for one frame only, which means you'd see the whole thing popping up, and then closing very fast. This is why I use the render function, to draw it correspondingly to the client's frames per second count. Fader: I use the fader to fade the text in and out corresponding to the fader speed defined in the top of the script. When the transparency goes lower than the lowest amount you can have, then it will set the step to the opposite, and then continues fading in until it goes to the top (255) and then repeating the same again. This causes the fading animation on the texts. Ticks: The ticks are used as "timers" if you want to say so. This allows timing events without the need to use hardcoded timers, which aren't too efficient when there are a lot of timers around. Drawing: I use the draw functions to draw the background rectangle and texts on the screen, this is the display part of the code. The rest is simply just the magic behind the scenes. The texts are drawn in the middle of the screen with some simple calculations (screen width minus text width, divided by two; same thing for the height). The rendering functions are surprisingly efficient and very useful. I've used them in many applications, not just drawing stuff, but also calculations and other algorithms that need constant updates. Render events are only available client-side, because only clients are able to render graphics. Server is just the machine that provides clients with updated data. If you make all your scripts client-side, it means the server doesn't know anything about the client. Edited February 10, 2014 by Guest Link to comment
xXMADEXx Posted February 10, 2014 Share Posted February 10, 2014 Well, besides Social's example, SAUR uses interpolateBetween to make the login have the bouncing effect. Here is an example, I took it from one of my codes and edited it a bit, but it should still work: local sx, sy = guiGetScreenSize ( ) local width, height = 600, 500 local point_start = { (sx/2-width/2), -height } local point_end = { (sx/2-width/2), (sy/2-height/2) } addEventHandler ( "onClientRender", root, function ( ) if not startTime then startTime = getTickCount ( ) end if not endTime then endTime = getTickCount ( ) + 3000 end local now = getTickCount() local elapsedTime = now - startTime local duration = endTime - startTime local progress = elapsedTime / duration x1, y1 = unpack ( point_start ) x2, y2 = unpack ( point_end ) local x, y, _ = interpolateBetween ( x1, y1, 0, x2, y2, 0, progress, "OutBounce" ) dxDrawRectangle ( x, y, width, height, tocolor ( 0, 0, 0, 150 ) ) end ) Link to comment
Deepu Posted February 10, 2014 Author Share Posted February 10, 2014 but how do I change it to seeds? when I hit a marker it does "1/50" Link to comment
myonlake Posted February 10, 2014 Share Posted February 10, 2014 Explain better, please. 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