Jump to content

Why timer is inaccurate?


Recommended Posts

Posted

Ok.

client side:

addEventHandler("onClientPlayerWasted", localPlayer, function()
  setTimer(function(source)
  	triggerServerEvent("spawnWastedPlayer", resourceRoot, source)
  end, 60000, 1, source)
end)

server side

addEvent("spawnWastedPlayer", true)
addEventHandler("spawnWastedPlayer", resourceRoot, function(source)
    spawnPlayer(source, 0, 0, 0)
end)

why practically never waiting for a spawn takes 1 minute, but it's "randomly", but never longer than that 1 minute?

  • Moderators
Posted (edited)
40 minutes ago, NoviceWithManyProblems said:

why practically never waiting for a spawn takes 1 minute, but it's "randomly", but never longer than that 1 minute?

Because the moment of execution is aligned with your fps. (Or internal clock)

I assume this decision is made in order to reduce constantly activity of the CPU and not blocking processes of other applications.

 

 

Edited by IIYAMA

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
49 minutes ago, IIYAMA said:

Because the moment of execution is aligned with your fps. (Or internal clock)

I assume this decision is made in order to reduce constantly activity of the CPU and not blocking processes of other applications.

 

 

How can I better deduct this time?

  • Moderators
Posted
1 hour ago, NoviceWithManyProblems said:

How can I better deduct this time?

You can tighten the timing a little bit by align it manual.

 

https://wiki.multitheftauto.com/wiki/OnClientPreRender

https://wiki.multitheftauto.com/wiki/OnClientRender

See example on the following page: https://wiki.multitheftauto.com/wiki/GetTickCount

 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
addEventHandler("onClientPlayerWasted", localPlayer, function()
  setTimer(function ()
  	triggerServerEvent("spawnWastedPlayer", resourceRoot)
  end, 60000, 1)
end)
addEvent("spawnWastedPlayer", true)
addEventHandler("spawnWastedPlayer", resourceRoot, function ()
    spawnPlayer(source, 0, 0, 0)
end)

Non tested

UDC:RPG Owner
13 Years Experience
______________________________________

 

Posted
21 hours ago, xMKHx said:

addEventHandler("onClientPlayerWasted", localPlayer, function()
  setTimer(function ()
  	triggerServerEvent("spawnWastedPlayer", resourceRoot)
  end, 60000, 1)
end)

addEvent("spawnWastedPlayer", true)
addEventHandler("spawnWastedPlayer", resourceRoot, function ()
    spawnPlayer(source, 0, 0, 0)
end)

Non tested

source of your server-side event is a resource, not a player.


Dê um THANKS se minha ajuda ou comentário foi útil para você.   spacer.png 

Posted
2 hours ago, KronoS Lettify said:

source of your server-side event is a resource, not a player.

Try this

addEventHandler("onClientPlayerWasted", localPlayer, function()
  local name = getPlayerName(localPlayer)
  setTimer(function ()
  	triggerServerEvent("spawnWastedPlayer", resourceRoot, name)
  end, 60000, 1)
end)
addEvent("spawnWastedPlayer", true)
addEventHandler("spawnWastedPlayer", resourceRoot, function (name)
    spawnPlayer(getPlayerFromName(name), 0, 0, 0)
end)

 

UDC:RPG Owner
13 Years Experience
______________________________________

 

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