remoteCC - Pick up coins remotely

Share and discuss custom LunaLua code and content packs for SMBX2.

Moderator: Userbase Moderators

Novarender
Tweeter
Tweeter
Posts: 145
Joined: Sat Aug 06, 2016 6:59 pm
Flair: Whoa

remoteCC - Pick up coins remotely

Postby Novarender » Sun Oct 25, 2020 7:10 pm

This is a script which allows you to collect coins remotely. Normally, coins can only be collected when a player touches them or they are bumped by a block from underneath. I've seen some people create some workarounds for this, so here's a proper script to do it for you! I've mostly created this for a work of my own.

Note: The script is capable of picking up all types of coins, including yoshi coins, starcoins, and dash/pop up coins with replicated effects. Other bonus items such as Cherries or Berries are not included.

Showcase:
Spoiler: show
Image
Image
Image

How to use:
Spoiler: show
The main feature of this library is the remoteCC.collect function. Its usage is:

Code: Select all

remoteCC.collect(c, w)
c is the coin you want to collect. w is optional; it is the object picking up the coin (player, NPC, etc.) This is mainly used for pop up/dash coins, since the coin won't tranform until the object colliding with it has moved out of its hitbox. You can also pass a table of objects as w so that the pop up coin won't transform until none of those objects are within its hitbox (for example, all players).

Aside from that, remoteCC has some functions and variables accessible externally. Most of them aren't important, but feel free to take a look. Here are the variables that are customizable:

Code: Select all

rCC.givesLivesAt -- What coin count to give lives at. Defaults to 100.
rCC.capCoins -- What coin count to cap at. Defaults to false (disabled).

--The following are (mapped) lists of ids. Defaults to every applicable basegame NPC.
rCC.coin	--Includes all basegame coin types -- Contains all NPC ids that can be collected with this script
rCC.blueCoin
rCC.redCoin
rCC.rupee
rCC.sonicRing
rCC.yoshiCoin
rCC.starcoin
rCC.dashcoin
Further explanation can be found in the script file. For the ID lists, you can put an empty table to disable.

Code example:
This code makes koopa shells able to collect any type of coin.

Code: Select all

local remoteCC = require("remoteCC")

function onTick()
    for _,v in ipairs(Colliders.getColliding{a=NPC.SHELL, atype = Colliders.NPC, btype = Colliders.NPC}) do
        if v[1]:mem(0x136,FIELD_BOOL) then --Is in projectile mode
            remoteCC.collect(v[2], v[1])
        end
    end
end
Explanation
Spoiler: show
While this might seem a fair bit complicated, and there's simpler way to do it, it's not really as complex as it seems. First, you load remoteCC in order to use it. The rest of the code is inside a getColliding check which checks for any NPCs colliding with Shell NPCs. And all that is inside a for loop looping over the NPCs colliding. v is a two-element table containing the Shell NPC and a colliding NPC. You can test this yourself with Misc.dialog().

Next, I have an if statement checking the offset of whether the Shell NPC is a projectile so that it can't collect coins when it's just sitting still.

Finally, nested within the center of the script is the line that actually collects the coin. v[2] is the coin and v[1] is the shell collecting it. remoteCC automatically filters out NPCs that are not coins, or those that are coins but can't be collected (for instance, if it's in a weed), so you don't have to worry about doing any of that on your own. Even here, it passes any colliding NPC to collect(), but nothing will happen if it's not a coin.


Download:
https://github.com/Novarender/remoteCC/archive/main.zip

Includes the script and a level utilizing the script, which features a new block: the Gold Ring Block.


If any images are broken, feel free to notify me so I can fix it. I hope this script helped and if it didn't, let me know what I can do! By the way, remoteCC stands for remote coin collection :]

CodeX
Bot
Bot
Posts: 50
Joined: Sat Mar 09, 2019 12:01 am
Flair: . . .

Re: remoteCC - Pick up coins remotely

Postby CodeX » Sat Nov 20, 2021 1:22 pm

Is it possible to collect a coin with a custom npc? Im trying to make a Yoshi level with MrDoubleA's Yoshi's Island-styled Yoshi and I want to have Eggs collect coins when thrown.


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari