LUA Timing

Status
Not open for further replies.

CloudyTheFox

IT'S HIGH NOON
Hello there, I have recently made a little LUA script. (With the help of my friend)
How would one go about doing a timing via LUA.

Here's the code that my friend made up.
Code:
addHook("ThinkFrame", function()
 for player in players.iterate do
        if not player.tailscloak
        player.tailscloak = 0
        end
        if not (player.cmd.buttons & BT_CUSTOM1)
        and (player.tailscloak > 0)
        player.tailscloak = player.tailscloak-1
        end
        if player.mo and player.mo.skin =="tails"
           if (player.cmd.buttons & BT_CUSTOM1)
           and not (player.tailscloak > 350)
               player.mo.flags2 = $1|MF2_DONTDRAW
               player.pflags = $1|PF_INVIS
               player.tailscloak = player.tailscloak+1
           else
               player.mo.flags2 = $1 & ~MF2_DONTDRAW
               player.pflags = $1 & ~PF_INVIS
           end
        end
 end
end)

Basically, what happens is it hides the player. (Just Tails)
 
Well for one you should probably change any instance of "player.tailscloak +/- 1" to just "$1 +/- 1", because the $1 means whatever the value was before.

As for timing, you could just make a new variable (lets go with player.cloaktimer) and have the line "player.cloaktimer = $1 + 1" at the end, and elsewhere have a line saying "if player.cloaktimer == x (where x is how long you want the timer to be), then (insert what you want the timer to do here.)"

Hope that helps!

EDIT: Decided to edit to code above to show what i mean. Also added a few comments to make it easier to read.

Code:
addHook("ThinkFrame", function()
 for player in players.iterate do

//This space sets the two variables
        if player.tailscloak == nil
            player.tailscloak = 0
        end
        if player.cloaktimer ==nil
            player.cloaktimer = 0
        end

//Seems to be a cooloff for the ability below.
        if not (player.cmd.buttons & BT_CUSTOM1)
        and (player.tailscloak > 0)
        player.tailscloak = $1 - 1
        end

        if player.mo and player.mo.skin =="tails"
           if (player.cmd.buttons & BT_CUSTOM1)
           and not (player.tailscloak > 350)
               player.mo.flags2 = $1|MF2_DONTDRAW
               player.pflags = $1|PF_INVIS
               player.tailscloak = $1 + 1
           else
               player.mo.flags2 = $1 & ~MF2_DONTDRAW
               player.pflags = $1 & ~PF_INVIS
           end

//We bring the timer variable up by 1 every frame, setting up the code below.
           player.cloaktimer = $1 + 1

//This is where the effect of the timer goes.
           //if player.cloaktimer >= x
           //then x

        end
 end
end)
 
Last edited:
Ok thanks, Need to re-code, but I do have one more thing. Like, toggling it then once out of time, it can't be activated until it cools down?

Thanks, I'm still new but I'll give it a shot.

When I press Custom1 while holding it, the sprite shows up for 1 second. my guess is there needs to be a timer such as

player.tailscloak = 5

so, the timer goes

if player.tailscloak = 5
then tailscloak = -1

Something like that.
 
Last edited:
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top