Results 1 to 2 of 2

Thread: How to decrease or increase ring count?

  1. #1
    Join Date
    March 26th, 2019
    Posts
    1
    Level
    1

    How to decrease or increase ring count?

    I was searching in the net about how to decrease or increase ring count, and didn't found anything. I'm new at SRB2 modding, so i can't get it by myself. Can someone please write the code: when we press custom1 button, ring count decreases by 5?
    Sorry for my bad english.

  2. #2
    Join Date
    March 25th, 2010
    Posts
    1,367
    Level
    42
    You need to use Lua: https://wiki.srb2.org/wiki/Lua

    Here's Lua code that subtracts 5 rings from the player with Custom Button 1:

    Code:
    local cooldown = 0 // If there's no button cooldown, you'll just rapidly drain rings.
    
    local function ringDrain(mobj)
        local player = mobj.player
        
        if cooldown > 0 // If there's a cooldown...
            cooldown = $1 - 1 // Decrease it.
        end
        
        if (player.cmd.buttons & BT_CUSTOM1) // Player is pressing Custom Button 1...
        and cooldown == 0 // and there's no cooldown...
        and player.mo.health > 1 // Player has at least 1 ring.
        
            if player.mo.health > 5 // If the player has at least 5 rings.
                player.mo.health = $1 - 5 // Remove 5 rings off the player.
                player.health = $1 - 5 // Remove 5 rings off the HUD counter. Player rings and HUD rings are separate, so change both together.
                cooldown = 3*TICRATE // Set a cooldown of 3 seconds.
                
            else // Otherwise, we'll just subtract the rings you have.
                player.mo.health = $1 - ($1 - 1) // If you have 0 rings, you have 1 health. We'll offset that to subtract the correct amount of rings.
                player.health = $1 - ($1 - 1) // Don't forget to remove it off the HUD too.
                cooldown = 3*TICRATE // Set a cooldown of 3 seconds.
            end
            
        end
    end
    
    addHook("MobjThinker", ringDrain, MT_PLAYER) // Add the ringDrain function as a MobjThinker for the player object.
    If you want a script that gives 5 rings when pressing Custom Button 1:
    Code:
    local cooldown = 0 // If there's no button cooldown, you'll just rapidly add rings.
    
    local function ringIncrease(mobj)
        local player = mobj.player
        
        if cooldown > 0 // If there's a cooldown...
            cooldown = $1 - 1 // Decrease it.
        end
        
        if (player.cmd.buttons & BT_CUSTOM1) // Player is pressing Custom Button 1...
        and cooldown == 0 // and there's no cooldown...
            player.mo.health = $1 + 5 // Add 5 rings to the player.
            player.health = $1 + 5 // Add 5 rings to the HUD counter. Player rings and HUD rings are separate, so change both together.
            cooldown = 3*TICRATE // Set a cooldown of 3 seconds.
        end
    end
    
    addHook("MobjThinker", ringIncrease, MT_PLAYER) // Add the ringDrain function as a MobjThinker for the player object.
    I've added comments in the code to help you understand how it works.

    Hopefully this works out for you! Please be aware that I did the code for you because it sounds like you're new to Lua scripting - I won't do full code for you in the future.
    Quote Originally Posted by SRB2
    <Mystyc Cheez> I ****ING QUIT
    Mystyc Cheez left the game
    <~Sky> Am I too awesome or something?
    <X\Wind> Why is everyone on red...
    <X\Wind> Is Sky that awesome?
    Quote Originally Posted by Steam
    20:48 - Sky: one does not simply ban him
    20:49 - Wind: we must gather the chaos emeralds and blast him

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •