brocky Posted October 22, 2015 Share Posted October 22, 2015 The problem with my code is that, I want to switch off the window. The code will explain what I mean. start = getTickCount() addEventHandler("onClientRender", getRootElement(), function() local now = getTickCount() loading = interpolateBetween(0,0,0,532,0,0, (now - start) / (( start + 10000 ) - start ) , "Linear" ) local rectangle = dxDrawRectangle(142, 222, loading, 41, tocolor(23, 23, 231, 255), false) if loading < 532 then givePlayerMoney(1) else givePlayerMoney(0) guiSetVisible(rectangle, false) end end ) I want to disable the dxDrawRectangle but guiSetVisible doesn't works. Whats the fucntion to disable a drawing ? Link to comment
Aristates Posted October 22, 2015 Share Posted October 22, 2015 onClientRendering is not working ! DirecTx working = onClientRender givePlayerMoney(1) server side. guiSetVisible don't dx functions. guiSetVisible Gui Functions ! -- #Client start = getTickCount() addEventHandler("onClientRender", getRootElement(), function() local now = getTickCount() loading = interpolateBetween(0,0,0,532,0,0, (now - start) / (( start + 10000 ) - start ) , "Linear" ) dxDrawRectangle(142, 222, loading, 41, tocolor(23, 23, 231, 255), false) end end ) -- #Server function(player) givePlayerMoney(player, 1) end dxDrawRectangleButton Event "onClientClick" DisableRenderEvent = "removeEventHandler" Link to comment
brocky Posted October 23, 2015 Author Share Posted October 23, 2015 Well, Thanks but can you post the full code exactly with the function you just mentioned? Idk if your english is bad, But I didn't understood you well. Link to comment
Dealman Posted October 23, 2015 Share Posted October 23, 2015 What he was trying to say is that all the gui-related functions only work with GUI elements. For example guiCreateWindow, guiCreateButton and the like. All of those return a GUI Element. DX drawings are drawings that are rendered each frame and as such does not return any elements. So this is why you can't use guiSetVisible to hide or show a DX drawing. Instead, you will have to use either addEventHandler or removeEventHandler. Or alternatively, you can simply use an if statement. Of course, you can write your own library to create custom elements using createElement. Thus, you can achieve the same behavior as you do with CEGUI but instead with DX Drawings. There are already a few of those out there, but I don't think either of them were ever finished. More so, if you read about dxDrawRectangle on the MTA Wiki, you'd see that it either returns true or false. So basically you would be doing this; guiSetVisible(true, false) When the correct usage would be; guiSetVisible(guiElement, false) Link to comment
brocky Posted October 23, 2015 Author Share Posted October 23, 2015 I tried every possible way that you described to me like using removeEventHandler, guiSetVisible(true, false) and I used the createElement function too and it didn't worked, Here is the code how I used it . start = getTickCount() addEventHandler("onClientRender", getRootElement(), function() local now = getTickCount() with = interpolateBetween(0,0,0,532,0,0, (now - start) / (( start + 10000 ) - start ) , "Linear" ) theElement = createElement(dxDrawRectangle(142, 222, with, 41, tocolor(23, 23, 231, 255), false)) if with < 532 then triggerServerEvent("payMoney", localPlayer) else guiSetVisbile(theElement, false) end end ) Please re-post the code again with the mistakes I did and post it back, so I would understand better. Link to comment
brocky Posted October 23, 2015 Author Share Posted October 23, 2015 OH! I didn't knew I was that noob, Anyway it worked with "removeEventHandler" after I made my own function to fill up the 3rd argument of "removeEventHandler". Thanks. Link to comment
Dealman Posted October 23, 2015 Share Posted October 23, 2015 I'd suggest you read thoroughly what I said before, you seem to have misunderstood all of it. First of all, dxDrawRectangle returns a boolean - either true or false. If it was drawn successfully it returns true, if not - it returns false. Secondly, you can't create an element using a boolean. Always read about the function on the wiki, don't just assume it will magically work. Also, I would advice against you trying to create elements as it's a very time consuming task, and it will only do you good if you make an entire library. Thirdly, I would advice you to structure your code differently. Writing it like that has no benefit and just ends up being harder to read, I'd suggest you read my tutorial. Fourth, you're using createElement inside onClientRender. Always keep in mind that rendering will be done at anywhere between 30 to 60 times per second(I think 100 FPS is the limit). So at 60 FPS, you would be trying to create a new element every ~16ms. Fifth, you were checking if the width was greater than 532. You're interpolating it between 0 and 532, thus, it would stop at 532 - and your if statement would never be triggered. Instead, you'd want to use greater than or equal to. Sixth, personally, this is how I would've written it; local startTick = getTickCount() function DrawProgress() local nowTick = getTickCount() local progressWidth = interpolateBetween(0, 0, 0, 532, 0, 0, (nowTick - startTick) / ((startTick + 10000) - startTick), "Linear") if(progressWidth >= 532) then triggerServerEvent("payMoney", localPlayer) removeEventHandler("onClientRender", root, DrawProgress) -- Progress has reached 1.0, trigger the event, and then remove the render event to stop rendering. else dxDrawRectangle(142, 222, progressWidth, 41, tocolor(23, 23, 231, 255), false) end end addEventHandler("onClientRender", root, DrawProgress) Edit: You beat me to it Link to comment
brocky Posted October 23, 2015 Author Share Posted October 23, 2015 Yes, This is the code how I did it. and I am sorry about my code layout, I am just used to it start = getTickCount() function loading() local now = getTickCount() with = interpolateBetween(0,0,0,532,0,0, (now - start) / (( start + 10000 ) - start ) , "Linear" ) dxDrawRectangle(142, 222, with, 41, tocolor(23, 23, 231, 255), false) if with < 532 then -- if the width is less then 532 then triggerServerEvent("payMoney", localPlayer) -- Keep giving the money to the play else -- Else if the width was bigger then 532 "Which simply means when it becomes full". removeEventHandler("onClientRender", getRootElement(), loading) -- Then stop the process and close the bar end end addEventHandler("onClientRender", getRootElement(), loading) Thanks anyway. 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