Jump to content

[HELP] How to make a infinite loop function.


xuaNN

Recommended Posts

  • Moderators

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.

 

 

Link to comment

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)

 

Link to comment

 

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.

 

Link to comment

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