Jump to content

Aborting; infinite running script in...


Recommended Posts

local allapot = "bekapcsolva"
while allapot == "bekapcsolva" do
    function pajzsLekerdezes()
        pajzs = getElementArmor (source)
        if pajzs >= 1 then
            setElementData (source, "lehetPajzsa", true)
        else
            setElementData (source "lehetPajzsa", false)
        end
    end
end


pajzsobject = createObject (1242, 0, 0, 1000)
function pajzsMegjelenitese()
    if getElementData (source, "lehetPajzsa") == true then
        setElementData (pajzsobject, "rogzitve", true)
        attachElements (pajzsobject, source)
    elseif getElementData (source, "lehetPajzsa") == false and getElementData (pajzsobject, "rogzitve") == true then
        destroyElement (pajzsobject)
    end
end
addEventHandler("", getRootElement())

I'd like to make a script, in which you have armor, an armor object would attach on you, else it would be destroyed or not shown. Aborts infinite loop?

Link to comment
  • Moderators

Loops are not meant to check if something has changed, they will keep running and delay all other processes until the system stops it. Loops are for processing multiple pieces of data during one action.

How about you use a timer instead? (if serverside)

https://wiki.multitheftauto.com/wiki/SetTimer

Or 'onClientRender' (if clientside)

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

  • Like 1
Link to comment
6 hours ago, IIYAMA said:

Why don't you start with learning how to create an infinity timer?

Just create it for fun and let it say something in the chat! :)

https://wiki.multitheftauto.com/wiki/SetTimer

https://wiki.multitheftauto.com/wiki/OutputChatBox

yes make sure u set it to 50ms so your server gets lagged xD

 

it would be like 

setTimer(function() do what you wanted to do end, 250, 0)

the 250 is delay, it will check that every 250ms, you probably can make it longer so that's less performance impact, and 0 means that it's infinite.

 

  • Like 1
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...