Make an advanced powder toy mod in lua that adds a supernova which is only a one-use…
- User
Make an advanced powder toy mod in lua that adds a supernova which is only a one-use particle that when spawned. It'll release a lot of subatomic particle, creating a massive supernova explosion.
Example Lua Mod, (THIS IS ONLY AN EXAMPLE. MAKE YOUR OWN LUA SCRIPT):
local smfb = elements.allocate("smallfubomb", "smfb") elements.element(smfb, elements.element(elements.DEFAULT_PT_DEST)) elements.property(smfb, "Name", "SMFB") elements.property(smfb, "Description", "Small Mother F***ing bomb. VERY DESTRUCTIVE") elements.property(smfb, "Temperature", 273.15) elements.property(smfb, "HeatConduct", 255) elements.property(smfb, "Weight", 500) local function explosion(i,x,y,s,nt) for r in sim.neighbors(x,y,1,1) do if sim.partProperty(r, "type") ~= smfb then sim.partProperty(r, "temp", 10000) sim.pressure(x/4, y/4, sim.pressure(x/4, y/4) + 10) if sim.partProperty(i, "life") == 0 then sim.partProperty(i, "life", 301) end if math.random(0, math.random(1, 25)) == 0 then sim.partChangeType(r, elem.DEFAULT_PT_HYGN) end if math.random(0, 50) == 0 then sim.partProperty(r, "life", 0) sim.partChangeType(r, smfb) end if math.random(0, 100) == 0 then sim.partChangeType(r, elem.DEFAULT_PT_DEST) end if math.random(0, 50) == 0 then sim.partChangeType(r, elem.DEFAULT_PT_GBMB) end if math.random(0, 50) == 0 then sim.partProperty(r, "tmp2", 10000) sim.partProperty(r, "life", 1000) sim.partChangeType(r,elem.DEFAULT_PT_WARP) end local ix = math.random(sim.partProperty(r, "x") - 1, sim.partProperty(r, "x") + 1) local iy = math.random(sim.partProperty(r, "y") - 1, sim.partProperty(r, "y") + 1) sim.partProperty(i, "x", ix) sim.partProperty(i, "y", iy) end if sim.partProperty(i, "life") < 61 and sim.partProperty(i, "life") ~= 0 then sim.partChangeType(r, elem.DEFAULT_PT_BOMB) end sim.partProperty(i, "vx", math.random(sim.partProperty(i, "vx") - 5, sim.partProperty(i, "vx") + 5)) sim.partProperty(i, "vy", math.random(sim.partProperty(i, "vy") - 5, sim.partProperty(i, "vy") + 5)) end end elements.property(smfb, "Update", explosion)These reference links are reference files:
https://github.com/The-Powder-Toy/The-Powder-Toy/raw/refs/heads/master/src/lua/TPTSTypes.cpp https://raw.githubusercontent.com/The-Powder-Toy/The-Powder-Toy/refs/heads/master/src/simulation/CoordStack.h https://github.com/The-Powder-Toy/The-Powder-Toy/raw/refs/heads/master/src/simulation/elements/BCLN.cpp
- Assistant
Certainly! Below is a Lua script for The Powder Toy that creates a new element called "Supernova" (abbreviated as "SNR"). When you place this element in the game, it will immediately trigger a massive explosion, releasing a multitude of subatomic particles like photons, neutrons, electrons, and positrons. The explosion also generates high pressure and temperature, simulating a supernova event.
-- Allocate a new element called Supernova local supernovaType = elements.allocate("supernova", "SNR") -- Use "NONE" as base to define custom properties elements.element(supernovaType, elements.element(elements.DEFAULT_PT_NONE)) -- Set properties for the Supernova element elements.property(supernovaType, "Name", "SNR") elements.property(supernovaType, "Description", "Supernova - releases subatomic particles, massive explosion") elements.property(supernovaType, "Colour", 0xFFAA00) elements.property(supernovaType, "MenuSection", elem.SC_SPECIAL) elements.property(supernovaType, "Weight", 80) elements.property(supernovaType, "Temperature", 1e9) -- Extremely hot -- Define the update function for Supernova local function snr_update(i, x, y, s, n) local life = sim.partProperty(i, "life") if life == 0 then -- Initialize the explosion sim.partProperty(i, "life", 1) -- Prevent re-triggering local radius = 50 -- Explosion radius local num_particles = 1000 -- Number of subatomic particles to release -- Release subatomic particles for p = 1, num_particles do -- Random angle and distance for particle placement local angle = math.random() * 2 * math.pi local distance = math.random() * radius local px = x + math.floor(distance * math.cos(angle)) local py = y + math.floor(distance * math.sin(angle)) -- Randomly select a subatomic particle type local particles = {elem.DEFAULT_PT_NEUT, elem.DEFAULT_PT_PHOT, elem.DEFAULT_PT_ELEC, elem.DEFAULT_PT_POSI} local particleType = particles[math.random(1, #particles)] -- Create the particle if the position is valid if sim.partCreate(-1, px, py, particleType) ~= -1 then local pi = sim.partID(px, py) if pi ~= nil then -- Assign high velocity and temperature to the particle local speed = math.random(50, 200) local vx = math.cos(angle) * speed local vy = math.sin(angle) * speed sim.partProperty(pi, "vx", vx) sim.partProperty(pi, "vy", vy) sim.partProperty(pi, "temp", 1e9) end end end -- Generate a pressure wave for dx = -radius, radius do for dy = -radius, radius do local dist = math.sqrt(dx*dx + dy*dy) if dist <= radius then sim.pressure((x+dx)//4, (y+dy)//4, 10) end end end -- Remove the Supernova particle to make it one-use sim.partKill(i) end end -- Assign the update function to the Supernova element elements.property(supernovaType, "Update", snr_update)How to Use:
-
Install the Script:
- Copy the script above.
- Open The Powder Toy.
- Press
Ctrl+Shift+Lto open the Lua console. - Paste the script into the console and press Enter.
-
Place the Supernova Element:
- You will find "SNR" under the "Special" section in the elements menu.
- Select "SNR" and place it anywhere in the simulation.
-
Observe the Explosion:
- As soon as you place the Supernova particle, it will trigger a massive explosion.
- You'll see a burst of subatomic particles spreading out rapidly.
- The explosion generates high pressure and temperature, affecting nearby particles.
Features of the Supernova Element:
- One-Use Particle: The Supernova particle self-destructs immediately after triggering the explosion.
- Subatomic Particle Release: It releases a large number of subatomic particles (photons, neutrons, electrons, positrons) in all directions.
- Massive Explosion: The explosion affects a large radius, applying high pressure and temperature, simulating the effect of a real supernova.
- Visual Effects: The high-speed particles and pressure wave create dramatic visual effects in the simulation.
Notes:
- Performance Warning: Due to the large number of particles and calculations, this script may cause slowdowns on less powerful machines.
- Safety Tip: It's recommended to save your simulation before placing the Supernova, as it can dramatically alter or destroy structures.
Enjoy experimenting with the Supernova in The Powder Toy!
-