Chaos Emerald abilities upon obtention ?

Fabulous99

Aw yeah ! This is happening !
Hi, is there a way to script a ability, visual effects and sprite swap when selecting a specific Chaos Emerald, if it even exists ?
 
It's hard to explain, but for example : by obtaining a Chaos Emerald, you get a hud where there's the Chaos Emerald you just got, and you get special powers from it, like for the CD Sonic addon. Here: https://mb.srb2.org/threads/cd-sonic.25597/ . And the more Chaos Emeralds you get, the more the hud will add them in the selection, cuz I'm planning a super awesome mod, but I don't know anything in lua, plus I don't think the wiki will give all the answers I need, so I made this thread.
 
It's hard to explain, but for example : by obtaining a Chaos Emerald, you get a hud where there's the Chaos Emerald you just got, and you get special powers from it, like for the CD Sonic addon. Here: https://mb.srb2.org/threads/cd-sonic.25597/ . And the more Chaos Emeralds you get, the more the hud will add them in the selection, cuz I'm planning a super awesome mod, but I don't know anything in lua, plus I don't think the wiki will give all the answers I need, so I made this thread.



Information taken from the wiki:
[...]
Given the two different systems of collecting Chaos Emeralds in-game detailed above, the internal storage methods for Chaos Emeralds also differ accordingly:
  • In Single Player/Coop, the Chaos Emeralds collected by all players are stored in the global variable emeralds, which can be accessed or modified with the use of Lua scripts.
  • In Match/Capture the Flag, the Chaos Emeralds collected by each player are stored using the player power pw_emeralds. In Lua, this power can be accessed or modified for a particular player with the code player.powers[pw_emeralds].
To store the collected emeralds in both of the above systems, the Chaos Emeralds themselves are represented by a series of toggles known as the Chaos Emerald flags. These are listed below:

ValueFlag nameEmeraldIcon
1EMERALD1Green EmeraldCEMGA0.png
2EMERALD2Purple EmeraldCEMGB0.png
4EMERALD3Blue EmeraldCEMGC0.png
8EMERALD4Light Blue EmeraldCEMGD0.png
16EMERALD5Orange EmeraldCEMGE0.png
32EMERALD6Red EmeraldCEMGF0.png
64EMERALD7Gray EmeraldCEMGG0.png
[...]

To replicate the behavior which you described you'd have to perform multiple checks on either the global variable emeralds or the player property pw_emeralds through player.powers[pw_emeralds] (depending on the gamemode) to verify if the value in either of these variables match the desired emerald flag.

Do keep in mind that if you want to check if the player possesses any combinations of emeralds you'll have to either do so through a combination of the flags (someone please correct me if I'm wrong):
Lua:
if player.powers[pw_emeralds] & EMERALD1 & EMERALD2 & EMERALD3 -- & EMERALD4... so on and so forth
-- You don't need to have them in order so EMERALD1 & EMERALD5 would also work, I believe.
    print("You have some emeralds!")
end

Or by their decimal values, which may be more complicated depending on who you ask:
Lua:
--[[
    EMERALD1 has a value of 1 and EMERALD2 has a value of 2 so:
    1 + 2 = 3 (duh)
]]
if player.powers[pw_emeralds] = 3 then
    print("You have the Green and Purple Emeralds!")
  
--[[
    EMERALD4's value is 8 and EMERALD7's value is 64 so:
    64 + 8 = 72
]]
elseif player.powers[pw_emeralds] = 72 then
    print("You have the Light Blue and Gray Emeralds!")
end

Since (I believe) you always get the Singleplayer/Coop Emeralds in order, a very down and dirty approach to checking for this would be (using the decimal values instead of the flags because I'm lazy. Also please, don't use this, it's probably very bad):
Lua:
-- Assuming you want the player(s) to retain the old abilities even though they get more emeralds
if emeralds >= 1 then --You have 1 emerald
    --do stuff
elseif emeralds >= 3 then --You have 2 emeralds
    --do stuff
elseif emeralds >= 7 then --You have 3 emer— okay I think you got it by now.
    --do stuff
-- Keep doing that until you've checked them all.
end

For Match/CTF gamemodes things will be more complicated since you can collect the Chaos Emeralds in a non-linear order. There'll be too many different cases to check for, and in my opinion, I'd advise against these mechanics in these gamemodes because having different abilities in those would put the game balance in jeopardy since you'd give players too much of an edge, arguably.

EDIT: Forgot to quote, oops. Also, spoilers so the code doesn't take up too much space.
 
Last edited:
Btw, Is there a way to add more than 1 transformation and select it ?

Not easily, but it's not impossible. Talking in hypotheticals you'd have to override how the game handles doing super transformations to include your own logic (assuming you mean you want both the default super transformation and your own to have the same criteria, i.e 7 Emeralds and 50 or more rings).

And that's thinking about game logic alone. I don't know anything about sprites and custom sprites admittedly, but if you want your own transformation(s) to have their own set of sprites I believe that's gonna be another ordeal as well.

Of course, not trying to discourage you! If you can make it work it'd be very creative (and the first time I've seen something like that done). But it might be very finnicky to implement without breaking regular super transformations for all other characters, and need fine tuning.
If you're up to the task I believe a good place to start would be checking out P_DoSuperTransformation, P_SuperReady, and maybe A_CustomPower. I'm not sure if you can override P_* functions (and if you can, I'm not sure it's even a good idea), but that should ease the workload.


EDIT
Just to be clear, you don't need to do a full override (if at all possible). If you want the other transformation to also have the regular Super's powers you could always work on top of it, verifying all the necessary checks.
 
Hm. Rather interesting. Honestly, I'm kinda new to the whole Lua thing and because of school, I don't have enough time. And is there a way to play both Special Stages separately (Co-Op and 1P) ? Cuz the separate SP thing is something I feel will be useful.
 
Hm. Rather interesting. Honestly, I'm kinda new to the whole Lua thing and because of school, I don't have enough time. And is there a way to play both Special Stages separately (Co-Op and 1P) ? Cuz the separate SP thing is something I feel will be useful.
Are you asking to play the MP Special Stages in the single player, or to play them both in the same campaign?
 
Unfortunately, tokens will no longer load Special Stages after you have seven Chaos Emeralds. This could be circumvented but it would be a complicated process without the implementation of Super Emeralds. There might be a mod for this already, I just am not aware of any.
 
The Super Emeralds are EXACTLY the idea I had. I was thinking Co-Op Special Stages for the Chaos Emeralds and Nights (1P) Special Stages for the Super Emeralds.
Post automatically merged:

Well, the way to make it is by making a script select menu of it.
How do I do that ?
 
Last edited:
The Super Emeralds are EXACTLY the idea I had. I was thinking Co-Op Special Stages for the Chaos Emeralds and Nights (1P) Special Stages for the Super Emeralds.
Post automatically merged:


How do I do that ?
Just like how CD Sonic (as maded by Lat in Mar 24, 2018), or use a reusable menu that is on the mb. Which you can edit and it will work.
 

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

Back
Top