xuaNN

[HELP] How to make a infinite loop function.

Recommended Posts


what do I need to do for a function to work continuously?

Share this post


Link to post

I am very sure that you do not want to make a infinity loop. It is a very bad thing after all.

 

This is an infinity loop:

while true do

end

Never ending execution of code, which at the end gets abort because the game starts to freeze.

 

And this is what you probably want:

setTimer(function () end, 1000, 0)

Executing the function once per second.

 

 

Share this post


Link to post
2 hours ago, xuaNN said:


what do I need to do for a function to work continuously?

Depends on what you want to do

Share this post


Link to post

I wanna make a health checker. If player health under 15hp,

The camera starts to shake. I actually did the coding. But i can't make the check function. There is code;

local hp = getElementHealth( localPlayer )

function healthshake ()
if hp <= 15 then 
setCameraShakeLevel(255)
   else if hp > 15 then
setCameraShakeLevel(0)
     end
  end
end

setTimer(healthshake,500,0)

 

Share this post


Link to post

move line 1, in the healthshake function.

The value of the variable `hp` doesn't change by itself. It has to be done every 500ms.

Share this post


Link to post

 

I want automatically get the health value from the player, how can I do it?

Quote
1 minute ago, xuaNN said:

 

I want automatically get the health value from the player, how can I do it?

Okey okey okey, i understand the problem. Thank you.

 

Share this post


Link to post
Posted (edited)

For this you can use onClientPlayerDamage event to check the player's health each time they take damage.

Something like this

function camShake ( attacker, weapon, bodypart, loss )
    local health = getElementHealth( localPlayer ) -- get the player's health
    -- check health
    -- set shake etc...
end
addEventHandler ( "onClientPlayerDamage", localPlayer, camShake )

 

Edited by Mr.Loki

Share this post


Link to post

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.