Jump to content

dxDraws are getting drawn on each other?


Recommended Posts

Hi!
I have dxDrawTextes which are getting drawn on each other and really dropping my FPS. I mean that the coordinates should stay the same, but the first one should disappear, then the other one should appear. And I have another problem as well, it says that the event is not added to clientside, meanwhile it is! And in the meta the client script starts before the server script!
Server:
 

function sendInformationToDebug()
	if isTimer(delay) then killTimer(delay) end
	delay = setTimer (function()
		triggerClientEvent ("recieveData", getRootElement(), state, robbery, drilling, stealthable)
	end, 100, 0)
end
addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), sendInformationToDebug)
addEventHandler ("onPlayerJoin", getRootElement(), sendInformationToDebug)

Client:
 

function recieveData(state, robbery, drilling, stealthable)
	if state == nil or robbery == nil or drilling == nil or stealthable == nil then
		data = false
	else
		data = true
		triggerEvent ("drawRecievedData", getRootElement(), state, robbery, drilling, stealthable)
	end
end
addEvent ("recieveData", true)
addEventHandler ("recieveData", getRootElement(), recieveData)

function drawRecievedData(state, robbery, drilling, stealthable)
	function render()
		local stateStatus = state
		local robberyStatus = robbery
		local drillingStatus = drilling
		local stealthableStatus = stealthable
		local X, Y = guiGetScreenSize()
		local myX, myY = 1600, 900

		if stateStatus == 0 then
			dxDrawText ("Safe: closed", 500, 500, _, _, _, _, roboto, _, _, _, _, _, true)
		elseif stateStatus == 1 then
			dxDrawText ("Safe: open", 500, 500, _, _, _, _, roboto, _, _, _, _, _, true)
		end
	end
	addEventHandler ("onClientRender", getRootElement(), render)
end
addEvent ("drawRecievedData", false)
addEventHandler ("drawRecievedData", getRootElement(), drawRecievedData)

How it looks:
ncKg2ZA.jpg

Edited by rusztamas
Link to comment

If i were you I'd do the two states in two separate functions and then use these things when needed:

https://wiki.multitheftauto.com/wiki/AddEventHandler

https://wiki.multitheftauto.com/wiki/RemoveEventHandler

So when you need it to be "open" you add the event handler for the open function. And when you want it to be "closed" you remove the event handler of the "open" function (this removes text) and you'll add the event handler for the "closed" function. And vice versa. 

Link to comment

In addition to what @koragg said, the issue is that when you first call onReceivedData you are adding the render function to the onClientRender event. You'll need to grab a hold of that render function (your render function atm is being defined globally), and execute removeEventHandler if the render function already exists.

You need to do these three things:

  • Before function drawReceivedData(...) write this line: local render;
  • This will set the scope of the render variable
  • Right after the function drawReceivedData(...) line, check if render exists (if not nil), and it does, run this: removeEventHandler("onClientRender", root, render)

Steps to improve general code:

  • Lift the state: make the render function a regular function (not one defined inside another function)
  • Make it refer to a safeStatus table
  • onReceivedData check if safeStatus is defined. If it isn't (is nil), define it, and add the event. It is already defined, redefine it (or just update fields) so the render function will print the updated fields.

Good luck!

  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...