Make an advanced powder toy lua mod that adds a single pythonic particle that acts like…
- User
Make an advanced powder toy lua mod that adds a single pythonic particle that acts like a solid, it's really durable and has uni-frame, and subframe regeneration. It'll have an interesting special property that'll expand inwards when a frame of itself is damaged.
Reference Script (REFERENCE ONLY):
-- Allocate a new element for the durable solid with subframe regeneration local subr = elements.allocate("custom", "SUBR") elements.element(subr, elements.element(elements.DEFAULT_PT_METL)) -- Base on METL (metal) -- Properties of the new element elements.property(subr, "Name", "SUBR") elements.property(subr, "Description", "Durable solid with subframe-super-regenerative mechanic and weird conductive properties.") elements.property(subr, "Color", 0xFF5500) -- Orange color to represent the solid material elements.property(subr, "Weight", 50) -- Lightweight but solid elements.property(subr, "Hardness", 500) -- Highly durable elements.property(subr, "HeatConduct", 200) -- High heat conductivity elements.property(subr, "Temperature", 295.15) -- Room temperature -- Custom properties for subframe regeneration local REGEN_RATE = 90 -- Percentage chance of subframe regeneration local REGEN_RADIUS = 2 -- Regeneration affects neighboring particles within this radius -- Unique conductive properties local CONDUCT_RANDOMNESS = 50 -- Random chance for conduction effects local CONDUCT_ENERGY = 200 -- How much energy is conducted randomly -- Update function for the subr element local function update_subr(i, x, y, s, n) -- Subframe regeneration mechanic if math.random(0, 100) < REGEN_RATE then sim.partProperty(i, "life", 999) -- Max out life (indicating healing) -- Regenerate nearby elements rapidly for r in sim.neighbors(x, y, REGEN_RADIUS, REGEN_RADIUS) do if sim.partProperty(r, "type") ~= subr then sim.partChangeType(r, subr) -- Convert nearby elements to subr sim.partProperty(r, "life", 999) -- Also heal them fully sim.partProperty(r, "dcolor", 0xFFAA00) -- Change color to bright orange during regeneration end end end -- Weird conductive properties if math.random(0, 100) < CONDUCT_RANDOMNESS then -- Randomly transfer energy/heat to neighboring particles for r in sim.neighbors(x, y, 1, 1) do if sim.partProperty(r, "type") ~= subr then -- Randomly increase/decrease temperature and pressure for weird effects local new_temp = sim.partProperty(r, "temp") + math.random(-CONDUCT_ENERGY, CONDUCT_ENERGY) sim.partProperty(r, "temp", new_temp) -- Randomly increase/decrease velocity local vx = sim.partProperty(r, "vx") + math.random(-2, 2) local vy = sim.partProperty(r, "vy") + math.random(-2, 2) sim.partProperty(r, "vx", vx) sim.partProperty(r, "vy", vy) -- Optionally cause the element to change type due to weird conduction if math.random(0, 100) < 5 then sim.partChangeType(r, elements.DEFAULT_PT_PLSM) -- Change to plasma randomly end end end end -- Visual feedback: change color based on temperature/conductivity activity local temp = sim.partProperty(i, "temp") if temp > 500 then sim.partProperty(i, "dcolor", 0xFF0000) -- Turn red when really hot elseif temp < 273 then sim.partProperty(i, "dcolor", 0x0000FF) -- Turn blue when cold else sim.partProperty(i, "dcolor", 0xFF5500) -- Default orange end end -- Assign the update function to the new element elements.property(subr, "Update", update_subr) -- Enable the element to be solid and not flow like powder elements.property(subr, "State", elements.ST_SOLID) -- Make the element indestructible unless melted or extreme forces applied elements.property(subr, "Explosive", 0) -- Not explosive - Assistant
Creating an advanced Lua mod for The Powder Toy to introduce a new durable solid particle with unique regenerative and interactive properties can significantly enhance your simulations. Below is a comprehensive Lua script that fulfills your requirements:
- Element Name:
PYTHONIC - Properties:
- Highly durable with high hardness and weight.
- Uni-frame and subframe regeneration: Automatically repairs itself and neighboring particles.
- Special Property: Expands inwards when a frame of itself is damaged, enhancing structural integrity.
- Unique conductive properties leading to unpredictable behaviors when interacting with other elements.
Complete Lua Script for the
PYTHONICElement-- The Powder Toy Lua Mod: Pythonic Element -- Author: [Your Name] -- Description: Adds a highly durable solid element with uni-frame and subframe regeneration capabilities, -- along with a special inward expansion property upon damage. -- Ensure the script runs only once if not onload then onload = function() -- Allocate a new element local pythonic = elements.allocate("custom", "PYTHONIC") -- Base the element on metal (for basic properties) elements.element(pythonic, elements.element(elements.DEFAULT_PT_METL)) -- Set fundamental properties elements.property(pythonic, "Name", "Pythonic Solid") elements.property(pythonic, "Description", "A highly durable solid with advanced regenerative capabilities and unique expansion properties.") elements.property(pythonic, "Color", 0x00FF00) -- Green color to represent the special solid elements.property(pythonic, "Weight", 100) -- Heavier than standard metal elements.property(pythonic, "Hardness", 1000) -- Extremely high hardness elements.property(pythonic, "HeatConduct", 500) -- Very high heat conductivity elements.property(pythonic, "Temperature", 300) -- Slightly above room temperature -- Define the state as solid elements.property(pythonic, "Gases", 0) elements.property(pythonic, "State", elements.ST_SOLID) -- Prevent the element from being flammable or explosive elements.property(pythonic, "Flammable", 0) elements.property(pythonic, "Explosive", 0) -- Custom regeneration and expansion properties local REGEN_RATE = 95 -- 95% chance to regenerate each update cycle local REGEN_RADIUS = 3 -- Radius within which neighboring particles are affected local EXPAND_THRESHOLD = 50 -- Damage threshold to trigger inward expansion -- Custom conductive properties local CONDUCT_RANDOMNESS = 30 -- 30% chance for conduction effects local CONDUCT_ENERGY = 100 -- Energy transferred during conduction -- Update function for the Pythonic element local function update_pythonic(i, x, y, s, n) local current_life = sim.partProperty(i, "life") local max_life = sim.partProperty(i, "maxl") -- Check if the particle is damaged if current_life < max_life then -- Trigger inward expansion if damage exceeds the threshold if (max_life - current_life) >= EXPAND_THRESHOLD then -- Expand inwards: add new particles around the damaged area for dx = -1, 1 do for dy = -1, 1 do if not (dx == 0 and dy == 0) then local nx, ny = x + dx, y + dy if sim.part(x, y) == pythonic then if sim.part(nx, ny) ~= pythonic then sim.partChangeType(nx, pythonic) sim.partProperty(nx, "life", max_life) sim.partProperty(nx, "dcolor", 0x00AA00) -- Darker green during expansion end end end end end end end -- Subframe regeneration mechanic if math.random(1, 100) <= REGEN_RATE then sim.partProperty(i, "life", max_life) -- Heal the current particle -- Regenerate neighboring particles within REGEN_RADIUS for r = 1, REGEN_RADIUS do for dx = -r, r do for dy = -r, r do local nx, ny = x + dx, y + dy if sim.part(nx, ny) ~= pythonic and sim.part(nx, ny) ~= elements.DEFAULT_PT_AIR then sim.partChangeType(nx, pythonic) sim.partProperty(nx, "life", max_life) sim.partProperty(nx, "dcolor", 0x00AA00) -- Darker green during regeneration end end end end end -- Weird conductive properties if math.random(1, 100) <= CONDUCT_RANDOMNESS then -- Randomly transfer energy/heat to neighboring particles for dx = -1, 1 do for dy = -1, 1 do if not (dx == 0 and dy == 0) then local nx, ny = x + dx, y + dy local neighbor = sim.part(nx, ny) if neighbor ~= pythonic and neighbor ~= elements.DEFAULT_PT_AIR then -- Modify temperature randomly local temp_change = math.random(-CONDUCT_ENERGY, CONDUCT_ENERGY) local new_temp = math.max(0, sim.partProperty(nx, "temp") + temp_change) sim.partProperty(nx, "temp", new_temp) -- Modify velocity randomly local vx_change = math.random(-2, 2) local vy_change = math.random(-2, 2) local new_vx = sim.partProperty(nx, "vx") + vx_change local new_vy = sim.partProperty(nx, "vy") + vy_change sim.partProperty(nx, "vx", new_vx) sim.partProperty(nx, "vy", new_vy) -- Randomly change the element type if math.random(1, 100) <= 10 then -- 10% chance to change type sim.partChangeType(nx, elements.DEFAULT_PT_PLAS) end end end end end end -- Visual feedback based on temperature local temp = sim.partProperty(i, "temp") if temp > 800 then sim.partProperty(i, "dcolor", 0xFF0000) -- Red when very hot elseif temp < 100 then sim.partProperty(i, "dcolor", 0x0000FF) -- Blue when very cold else sim.partProperty(i, "dcolor", 0x00FF00) -- Default green end end -- Assign the update function to the Pythonic element elements.property(pythonic, "Update", update_pythonic) -- Optional: Define additional behaviors or interactions here end endExplanation of the Script
-
Element Allocation and Base Properties:
elements.allocate("custom", "PYTHONIC"): Allocates a new custom element named "PYTHONIC".elements.element(pythonic, elements.element(elements.DEFAULT_PT_METL)): Bases the new element on the default metal properties for a solid foundation.- Fundamental properties like
Name,Description,Color,Weight,Hardness,HeatConduct, andTemperatureare set to define the element's physical characteristics.
-
State and Reactivity:
elements.property(pythonic, "State", elements.ST_SOLID): Ensures the element behaves as a solid and does not flow like powder.FlammableandExplosiveproperties are set to0to make the element non-reactive under typical conditions.
-
Regeneration Mechanics:
REGEN_RATEandREGEN_RADIUS: Define the probability and range for the element to regenerate itself and neighboring particles.update_pythonicFunction:- Self-Regeneration: Restores the particle's life to maximum if within regeneration chance.
- Subframe Regeneration: Converts and heals neighboring particles within the specified radius.
- Damage Detection: If the particle's life drops below a threshold (
EXPAND_THRESHOLD), it triggers inward expansion to reinforce the structure.
-
Special Inward Expansion Property:
- When a particle's life is significantly reduced, the script expands inwards by converting surrounding non-Pythonic particles into Pythonic ones, effectively repairing the structure.
-
Unique Conductive Properties:
CONDUCT_RANDOMNESSandCONDUCT_ENERGY: Define the likelihood and magnitude of energy transfer to neighboring particles.- Causes random temperature and velocity changes in adjacent particles, introducing unpredictable behaviors.
- Element Type Changes: There's a 10% chance to change a neighbor's type to plasma (
DEFAULT_PT_PLAS) during conduction, adding to the element's uniqueness.
-
Visual Feedback:
- The element changes color based on temperature:
- Red (
0xFF0000): When very hot. - Blue (
0x0000FF): When very cold. - Green (
0x00FF00): Default color.
- Red (
- The element changes color based on temperature:
Installation Instructions
-
Locate Powder Toy's Lua Scripts Folder:
- Typically found in the installation directory under
data/lua/.
- Typically found in the installation directory under
-
Create a New Lua File:
- Name it
pythonic.luaor any name of your choice.
- Name it
-
Paste the Script:
- Copy the complete Lua script provided above into your new Lua file.
-
Run The Powder Toy:
- Launch the game, and the new
PYTHONICelement should be available in the element selector under the "Custom" category.
- Launch the game, and the new
-
Usage:
- Select the
PYTHONICelement and place it in your simulation. - Observe its regenerative behavior and unique interactions with other elements.
- Select the
Customization Tips
-
Adjusting Properties:
- Feel free to tweak values like
REGEN_RATE,Hardness, andHeatConductto balance the element according to your preferences.
- Feel free to tweak values like
-
Expanding Behavior:
- Modify the
EXPAND_THRESHOLDto control how sensitive the element is to damage.
- Modify the
-
Conductive Effects:
- Change
CONDUCT_RANDOMNESSandCONDUCT_ENERGYto make the conductive properties more or less aggressive.
- Change
-
Visual Effects:
- Alter
dcolorvalues to customize how the element's color changes in different states.
- Alter
Conclusion
This Lua mod introduces a robust and interactive element that can add depth and complexity to your The Powder Toy simulations. By leveraging advanced properties like subframe regeneration and inward expansion upon damage, the
PYTHONICelement behaves in a dynamic and engaging manner, offering new possibilities for experimentation and creative designs.Feel free to enhance and expand upon this script to suit your specific needs and to explore even more sophisticated behaviors!
- Element Name: