xuaNN Posted January 1, 2019 Posted January 1, 2019 what do I need to do for a function to work continuously?
Moderators IIYAMA Posted January 1, 2019 Moderators Posted January 1, 2019 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.
Feche1320 Posted January 1, 2019 Posted January 1, 2019 2 hours ago, xuaNN said: what do I need to do for a function to work continuously? Depends on what you want to do
xuaNN Posted January 1, 2019 Author Posted January 1, 2019 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)
Moderators IIYAMA Posted January 2, 2019 Moderators Posted January 2, 2019 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.
xuaNN Posted January 2, 2019 Author Posted January 2, 2019 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.
Mr.Loki Posted January 3, 2019 Posted January 3, 2019 (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 January 3, 2019 by Mr.Loki
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now