Jump to content

[HELP] triggerServerEvent help


Recommended Posts

Hello!

I have this code:

client.lua:

function clicksFunction(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement)
		....
	if isCursorInBox(x, y, 20, 20) then
		triggerServerEvent("serverEventName", resourceRoot, data)
	end
		....
end
addEventHandler("onClientClick", getRootElement(), clickInTheFarms)

server.lua:

local inUseData = {}

addEvent("serverEventName", true)
addEventHandler("serverEventName", resourceRoot, function(data)
  if not inUseData[data[1]] then
    inUseData[data[1]] = {}
  end

  if inUseData[data[1]] and inUseData[data[1]][data[2]] == true then return end

  inUseData[data[1]][data[2]] = true
    --some more code here to do things
end)

 

My problem is when two player clicks on client side, and triggering server event in the exact same time, then the 

  if inUseData[data[1]] and inUseData[data[1]][data[2]] == true then return end

not blocking the code execution under this line. So they can run the "--some more code here to do things" in the same time, and I don't want to allow this.

How can I solve this problem?

 

Link to comment
  • Moderators
3 hours ago, pixel77 said:
data[1]

What is inside of data[1] and data[2]? (to be more specific, what type is inside: table, string, number etc.)

And what are you clicking on?

Link to comment
9 hours ago, IIYAMA said:

What is inside of data[1] and data[2]? (to be more specific, what type is inside: table, string, number etc.)

And what are you clicking on?

data[1] and data[2] are numbers. 

For example: inUseData[12][5] = true

The client is clicking on a dxDraw button, that is rendered on the 3D World. 

Edited by pixel77
Link to comment
  • Moderators
3 hours ago, pixel77 said:

data[1] and data[2] are numbers. 

For example: inUseData[12][5] = true

The client is clicking on a dxDraw button, that is rendered on the 3D World. 

Then the code looks fine. Unless the numbers are a mixture of numbers and strings. 123 vs "123"

 

16 hours ago, pixel77 said:

So they can run the "--some more code here to do things" in the same time, and I don't want to allow this.

In theory it shouldn't be possible because this function is ran single threaded. There will always be one that is first. The whole function chain-call should have been ended before a new call can be made.

The following should be finished before the root function can be called again.

16 hours ago, pixel77 said:
--some more code here to do things

 

 

  • Thanks 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...