PDA

View Full Version : How to decrease or increase ring count?



_Demo4YT_
March 27th, 2019, 09:33
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.

Sky
March 27th, 2019, 22:52
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:


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:

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.