How to limit SF_MULTIABILITY to a specific number of repetitions?

Maverick Finn

thought air was free, til I bought a bag of chips
If I don't give a character this flag, it can only do this ability once. If I do give this flag, it can abuse of the ability forever.
Let's say I want my character to be able to use his abilities only 3 times before he hits the ground, for example. What should I do?
 
If I don't give a character this flag, it can only do this ability once. If I do give this flag, it can abuse of the ability forever.
Let's say I want my character to be able to use his abilities only 3 times before he hits the ground, for example. What should I do?
you’re gonna have to need lua to do that, sorry.
 
You need to hold a custom counter inside the player, and decrease it every time they use their ability. If the counter hits 0, don't let them activate it again until they hit the ground, then reset the counter.

Lua:
local max_count = 3

local function PlayerAbilityCheck(p)
    --set counter if the variable doesn't exist
    if p.abilityused == nil then
        p.abilityused = max_count
    end

    --reset counter when touching the floor
    if P_IsObjectOnGround(p.mo) then
        p.abilityused = max_count
    end
end

addHook("PlayerThink", PlayerAbilityCheck)

local function AbilityControl(p)
    if (p.abilityused == 0) then
        return true --do nothing
    end

    --decrease counter by 1
    p.abilityused = $ - 1

    --not needed, but it shows that we're not overriding the normal ability
    return false
end

addHook("AbilitySpecial", AbilityControl)

I just wrote this off the dome piece and I cannot currently test it, so no guarantees it'll work, but it does show the hooks/logic on what you should do.
 
You need to hold a custom counter inside the player, and decrease it every time they use their ability. If the counter hits 0, don't let them activate it again until they hit the ground, then reset the counter.
I actually wanted this for two different characters, with two different max_count values. So, modified, the code looked like:
Lua Code:
local max_count_amy = 2
local max_count_metal = 3

local function PlayerAbilityCheckAmy(p)
    if p.mo and p.mo.valid and (p.mo.skin == "amy") then
        --set counter if the variable doesn't exist
        if p.abilityused == nil then
            p.abilityused = max_count_amy
        end

        --reset counter when touching the floor
        if P_IsObjectOnGround(p.mo) then
            p.abilityused = max_count_amy
        end
    end
end

local function PlayerAbilityCheckMetal(p)
    if p.mo and p.mo.valid and (p.mo.skin == "metalsonic") then
        if p.abilityused == nil then
            p.abilityused = max_count_metal
        end

        if P_IsObjectOnGround(p.mo) then
            p.abilityused = max_count_metal
        end
    end
end

addHook("PlayerThink", PlayerAbilityCheckAmy)

addHook("PlayerThink", PlayerAbilityCheckMetal)

local function AbilityControl(p)
    if (p.abilityused == 0) then
        return true --do nothing
    end

    --decrease counter by 1
    p.abilityused = $ - 1

    --not needed, but it shows that we're not overriding the normal ability
    return false
end

addHook("AbilitySpecial", AbilityControl)

But it still does not work... what do I do?
 

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

Back
Top