Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How i can create a Combo?

Asked by 5 years ago
Edited 5 years ago

Sorry for my Bad english;

Hi guys, how i can create a Combo when, if a player click mouse between 0.01/ 0.2 sec they go in second animation ecc ecc? And, if the player is slow. the combo reset to the first animation?

Example:

--(when the guy press the first time)
tool.Activated:connect(function()
    if canSwing then
        canSwing = false
        canattack.Value = true
    Request:FireServer("Power") 
    Request:FireServer("Money") 
        swing1animation:Play()
        wait(.2)
    -- Now, they need press another time for create the condition for continue the Combo between  0.01 and 0.2 secs, or the condition fail and the resete combo)
    swingsound:Play()
    if (condition is create) then
            swingsound:Play()
        Request:FireServer("Power") 
        Request:FireServer("Money") 
                swing2animation:Play()
                wait(.2)
                swingsound:Play()
        if (second condition is create)
            swingsound:Play()
            Request:FireServer("Power") 
            Request:FireServer("Money") 
                    swing3animation:Play()
                    wait(.2)
                    swingsound:Play()
        elseif (second condition fail) then
            return
        end
    elseif (first condition fail) then
        return
        end
        spawn(function()
            wait(DEBOUNCE_TIME)
            canSwing = true
        end)
end)

tool.Deactivated:connect(function()
    canattack.Value = true
end)

i write it so fast, sorry for the errors, how i can set the time between the guy need click for continue the combo? Ty

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

First things first, I recommend reading about Animation Events because it can easily be one of the best ways to do this: GetMarkerReachedSignal

And one thing you should know is tick(). now tick() is a time function that's local and very inconsistent (use os.time() if you want an actual good, global time measurement) but for the sake of this example tick() will work perfectly.

Now you can use tick() to do something like this:

start = tick()
timeInSeconds = 3

while (tick() - start) >= timeInSeconds do
    -- this code will **ONLY** run when 3 seconds have passed since start has been updated
    wait()
end

-- and maybe something like this
while (tick() - start) <= timeInSeconds do
    -- this code will **ONLY** run as long as 3 seconds have passed since start has been updated
    -- now obv this code will not run because of the above code but you get the idea
    wait()
end

You see where I am going? Using this way we can see whether or not the player has pressed at a decent time (eg. 0.01/0.2)

Now I am no expert in this nor did I try doing this but let me try, alright?

We will start with input, you will have to listen to when the player presses (and keep track of it) which you are doing rn. And we have to keep track of when the player first pressed. so it will be similar to this:

playingAnim = false
timeOfPlay = nil

LCD = 0.01 -- LEAST_COMBO_DELAY
MCD = 0.2 -- MAX_COMBO_DELAY

function startPlaying()
    playingAnim = true
    timeOfPlay = tick() -- we are recording this to have a good measure of time
end


function press()
    if not playingAnim then -- if this condition passes then the player is trying to hit their first hit (no combo whatsoever)
        startPlaying()
    else -- if this condition passes then the player is trying to hit again while the first animation is playing (in other words, they want to start a combo)
        if (tick() - timeOfPlay) >= LCD then -- recall when we stored timeOfPlay? this means that 0.01 secs have passed
            if (tick() - timeOfPlay) <= MCD then -- this means that the time passed is less than (or =) to the MAX time (0.2)
                -- here we will repeat the same process with each applicable hit, make sure the player can't make a combo with 300 hits though lol
                -- now remember when I asked you to read that animation thing, you should use it here, only if you want a smooth and cool transition (and probably no lag too)
            animTrack:GetKeyframeReachedSignal("ComboCanBePlayedHere"):Wait()
                -- make sure to add the part that can be transitioned from and call it whatever you want but make sure to change it here too
            end
        end
    end
end
0
This is by no means a perfect code or even one that you can use in your game, it's to give you an idea of one way to do it. I missed some things like debounce and how you play other combo attacks because I am sure you can do them yourself :D Good luck and I hope this helped :) GGRBXLuaGG 417 — 5y
0
If anything is unclear please let me know. I will do my best to make is otherwise. GGRBXLuaGG 417 — 5y
Ad

Answer this question