Jump to content

triggerClientEvent vs setElementData ?


louie999

Recommended Posts

So I was making a safe zone system, I was just wondering, what is better, triggerClientEvent or setElementData?, my safe zone script works but I don't which of those is more efficient. :|

Both of them are useful in my opinion, it's just up to which data you want to trigger

Link to comment
triggering a client event will use more CPU power, of course.

And you base this on what? It all depends on how it's set up. If you use setElementData and leave it as default - it will sync between all players. If you use triggerClientEvent you can simply trigger it for one client. All the server has to do is trigger the event, the client takes care of the rest of the event.

While both work, I sincerely doubt triggerClientEvent uses "more CPU" than setElementData.

Link to comment
triggering a client event will use more CPU power, of course.

And you base this on what? It all depends on how it's set up. If you use setElementData and leave it as default - it will sync between all players. If you use triggerClientEvent you can simply trigger it for one client. All the server has to do is trigger the event, the client takes care of the rest of the event.

While both work, I sincerely doubt triggerClientEvent uses "more CPU" than setElementData.

There's a difference between sync(ing) and trigger(ing).

Link to comment
  • Moderators

This is circa my list of benefits between those two.

triggerClientEvent

  • Faster. (priority)
  • Can have a sending to > target.

  • Uses more bandwidth per player.
  • Because of the high priority it can cause de-sync/time-outs when it is used frequently. (more than 30 per second, depending on your internet speed)

setElementData

  • Uses less bandwidth per player. (a lot less)
  • Can be easier used between other scripts.

  • Doesn't have a sending to > target.
  • Uses more bandwidth depending on the player count.(total)
  • Is slower. (priority)

  • Remains intact after the resource stops.

Legend:

Good

Not good

Both

Link to comment
This is circa my list of benefits between those two.

triggerClientEvent

  • Because of the high priority it can cause de-sync/time-outs when it is used frequently. (more than 30 per second, depending on your internet speed)

As far as i know there's no relation between internet speed and trigger events ,the relation between them is the CPU and it's up to computer's processor

Link to comment
  • Moderators

Oh there is.

You can simply test that by using an amount of triggerServerEvent's on the rate of the "onClientRender" event.

If you have a normal pc, you will get disconnected before your game starts to crash.

Link to comment
Oh there is.

If you have a normal pc, you will get disconnected before your game starts to crash.

Yes, it happen when you enter to some servers are not scripted professionally, you feel with the FPS drop each time, if the FPS dropped that mean the usage of CPU used alot

Link to comment
  • Moderators
Oh there is.

If you have a normal pc, you will get disconnected before your game starts to crash.

Yes, it happen when you enter to some servers are not scripted professionally, you feel with the FPS drop each time, if the FPS dropped that mean the usage of CPU used alot

This has nothing to do with it. My fps will not drop when I execute a trigger event 100 times per second.

Disconnecting and crashing is not the same thing. You will get disconnected when you lose connection with the server. And you will crash when your cpu can't handle it any more.

And I don't crash, I only get disconnected. Which means my cpu is doing just fine.

The only way you can know this, is by thinking logic or test it yourself.

Link to comment

This has nothing to do with it. My fps will not drop when I execute a trigger event 100 times per second.

Disconnecting and crashing is not the same thing. You will get disconnected when you lose connection with the server. And you will crash when your cpu can't handle it any more.

And I don't crash, I only get disconnected. Which means my cpu is doing just fine.

The only way you can know this, is by thinking logic or test it yourself.

i'm talking about the normal computers

Link to comment
i'm talking about the normal computers

I think you mean things like the specific server having a lot of DX drawings or possibly using a lot of memory (storing large tables in memory etc).

Thanks guys for the answers, I think I'll go with triggerClientEvent for my safe zone script :D

You could make your safe zone script entirely client-sided if you just wanted to stop player damage within a zone.

Edit: changed a word because DirectX is in fact not an element

Edited by Guest
Link to comment
  • Moderators
i'm talking about the normal computers

New pc's only have more cores or a little bit extra ghz. But mta only uses 1 core. So also normal pc's can do that too.

I am sure your pc can run this without crashing:

setTimer(function () 
    for i=1, 100 do 
        triggerServerEvent("serverEvent",localPlayer) 
    end 
end,1000,0) 

addEvent("serverEvent",true) 
addEventHandler("serverEvent",root, 
function () 
end) 

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