Last active
April 9, 2024 11:12
-
-
Save rdococ/d0ecfc7384b3e052e594fe41b84004d0 to your computer and use it in GitHub Desktop.
Chickens for TPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Chickens | |
yeah this script is stupid but i love it | |
]] | |
local elem, sim = elements, sim | |
local random, floor, min, max, sin, cos, atan2, sqrt, abs, ceil, exp = math.random, math.floor, math.min, math.max, math.sin, math.cos, math.atan2, math.sqrt, math.abs, math.ceil, math.exp | |
local pi = math.pi | |
local unpack = unpack | |
local partCreate, partProperty, partKill, partExists = sim.partCreate, sim.partProperty, sim.partKill, sim.partExists | |
local stickman = {} | |
for _, t in ipairs {elem.DEFAULT_PT_STKM, elem.DEFAULT_PT_STK2, elem.DEFAULT_PT_FIGH} do | |
stickman[t] = true | |
end | |
local EGG = elem.allocate("rdococ", "egg") | |
local CHCK = elem.allocate("rdococ", "chck") | |
local FEGG = elem.allocate("rdococ", "fegg") | |
local RCHK = elem.allocate("rdococ", "rchk") | |
local KFC = elem.allocate("rdococ", "kfc") | |
local BUG = elem.allocate("rdococ", "bug") | |
elem.element(EGG, elem.element(elem.DEFAULT_PT_DUST)) | |
elem.property(EGG, "Name", "EGG") | |
elem.property(EGG, "Description", "Egg. Hatches into chickens with warmth.") | |
elem.property(EGG, "Color", 0xFFAA77) | |
elem.property(EGG, "HighTemperature", math.huge) | |
elem.property(EGG, "Weight", 90) | |
elem.property(EGG, "Create", function (self, x, y, type, v) | |
partProperty(self, sim.FIELD_LIFE, random(500, 600)) | |
end) | |
elem.property(EGG, "Update", function (self, x, y, s, nt) | |
if partProperty(self, sim.FIELD_TEMP) >= 373.15 then | |
if random(1, 100) == 1 then | |
partKill(self) | |
partCreate(-3, x, y, FEGG) | |
end | |
elseif partProperty(self, sim.FIELD_TEMP) >= 300 then | |
local life = partProperty(self, sim.FIELD_LIFE) - 1 | |
partProperty(self, sim.FIELD_LIFE, life) | |
if life <= 0 then | |
partKill(self) | |
partCreate(-3, x, y, CHCK) | |
end | |
end | |
end) | |
elem.element(FEGG, elem.element(elem.DEFAULT_PT_DUST)) | |
elem.property(FEGG, "Name", "FEGG") | |
elem.property(FEGG, "Description", "Fried egg. Hearty breakfast, heals STKM.") | |
elem.property(FEGG, "Color", 0xFFCCAA) | |
elem.property(FEGG, "Update", function (self, x, y, s, nt) | |
for part, nx, ny in sim.neighbors(x, y, 1, 1) do | |
local ptype = partProperty(part, sim.FIELD_TYPE) | |
if stickman[ptype] then | |
partKill(self) | |
partProperty(part, sim.FIELD_LIFE, min(partProperty(part, sim.FIELD_LIFE) + 1, 100)) | |
end | |
end | |
end) | |
elem.element(CHCK, elem.element(elem.DEFAULT_PT_DUST)) | |
elem.property(CHCK, "Name", "CHCK") | |
elem.property(CHCK, "Description", "Chicken. Warm, likes to wander around. Chicks will grow and hens will lay eggs after eating BUG.") | |
elem.property(CHCK, "Color", 0xFFFFFF) | |
elem.property(CHCK, "Temperature", 273.15 + 41) | |
elem.property(CHCK, "LowTemperature", 273.15 + 0) | |
elem.property(CHCK, "LowTemperatureTransition", RCHK) | |
elem.property(CHCK, "HighTemperature", 273.15 + 50) | |
elem.property(CHCK, "HighTemperatureTransition", KFC) | |
elem.property(CHCK, "Update", function (self, x, y, s, nt) | |
local state, timer, age, life = partProperty(self, sim.FIELD_TMP), partProperty(self, sim.FIELD_TMP2), partProperty(self, sim.FIELD_TMP3), partProperty(self, sim.FIELD_LIFE) | |
if state == 1 then | |
partProperty(self, sim.FIELD_VX, -0.25) | |
elseif state == 2 then | |
partProperty(self, sim.FIELD_VX, 0.25) | |
elseif life > 0 then | |
life = life - 1 | |
partProperty(self, sim.FIELD_LIFE, life) | |
if age < 30 then | |
age = age + 1 | |
partProperty(self, sim.FIELD_TMP3, age) | |
else | |
local eggLaid = false | |
for nx = x - 1, x + 1 do | |
for ny = y, y + 1 do | |
if not sim.pmap(nx, ny) then | |
partCreate(-3, nx, ny, EGG) | |
eggLaid = true | |
break | |
end | |
end | |
if eggLaid then break end | |
end | |
end | |
end | |
if timer <= 0 then | |
partProperty(self, sim.FIELD_TMP, random(0, 2)) | |
partProperty(self, sim.FIELD_TMP2, random(100, 200)) | |
partProperty(self, sim.FIELD_VY, -2) | |
else | |
partProperty(self, sim.FIELD_TMP2, timer - 1) | |
end | |
local temp = partProperty(self, sim.FIELD_TEMP) | |
if temp < 273.15 + 41 then | |
partProperty(self, sim.FIELD_TEMP, temp + 1) | |
elseif temp > 273.15 + 42 then | |
partProperty(self, sim.FIELD_TEMP, temp - 1) | |
end | |
for part, nx, ny in sim.neighbors(x, y, 1, 1) do | |
local ptype = partProperty(part, sim.FIELD_TYPE) | |
if ptype == BUG then | |
partKill(part) | |
partProperty(self, sim.FIELD_LIFE, min(life + 1, 10)) | |
elseif ptype == CHCK and nx ~= 0 then | |
partProperty(self, sim.FIELD_VX, (x - nx) * 0.25) | |
end | |
end | |
end) | |
elem.property(CHCK, "Graphics", function (self, r, g, b) | |
if sim.partProperty(self, sim.FIELD_TMP3) < 30 then r, g, b = 255, 255, 0 end | |
return 0, ren.PMODE_FLAT, 255, r, g, b, 255, r, g, b | |
end) | |
elem.element(RCHK, elem.element(elem.DEFAULT_PT_DUST)) | |
elem.property(RCHK, "Name", "RCHK") | |
elem.property(RCHK, "Description", "Raw chicken. Do not feed to STKM!") | |
elem.property(RCHK, "Color", 0xFF5555) | |
elem.property(RCHK, "Flammable", 0) | |
elem.property(RCHK, "HighTemperature", 273.15 + 60) | |
elem.property(RCHK, "HighTemperatureTransition", KFC) | |
elem.property(RCHK, "Update", function (self, x, y, s, nt) | |
for part, nx, ny in sim.neighbors(x, y, 1, 1) do | |
local ptype = partProperty(part, sim.FIELD_TYPE) | |
if stickman[ptype] then | |
partKill(self) | |
partProperty(part, sim.FIELD_LIFE, partProperty(part, sim.FIELD_LIFE) - 1) | |
end | |
end | |
end) | |
elem.element(KFC, elem.element(elem.DEFAULT_PT_DUST)) | |
elem.property(KFC, "Name", "KFC") | |
elem.property(KFC, "Description", "Fried chicken. Finger-lickin' good, heals STKM.") | |
elem.property(KFC, "Color", 0xFF9933) | |
elem.property(KFC, "Flammable", 0) | |
elem.property(KFC, "HighTemperature", 273.15 + 100) | |
elem.property(KFC, "HighTemperatureTransition", elem.DEFAULT_PT_DUST) | |
elem.property(KFC, "Update", function (self, x, y, s, nt) | |
for part, nx, ny in sim.neighbors(x, y, 1, 1) do | |
local ptype = partProperty(part, sim.FIELD_TYPE) | |
if stickman[ptype] then | |
partKill(self) | |
partProperty(part, sim.FIELD_LIFE, min(partProperty(part, sim.FIELD_LIFE) + 1, 100)) | |
end | |
end | |
end) | |
elem.element(BUG, elem.element(elem.DEFAULT_PT_DUST)) | |
elem.property(BUG, "Name", "BUG") | |
elem.property(BUG, "Description", "Bugs! Eats into WOOD, will multiply if fed PLNT or RCHK.") | |
elem.property(BUG, "Color", 0x444444) | |
elem.property(BUG, "Temperature", 273.15 + 20) | |
elem.property(BUG, "LowTemperature", 273.15 + 0) | |
elem.property(BUG, "LowTemperatureTransition", elem.DEFAULT_PT_DUST) | |
elem.property(BUG, "HighTemperature", 273.15 + 110) | |
elem.property(BUG, "HighTemperatureTransition", elem.DEFAULT_PT_DUST) | |
elem.property(BUG, "Update", function (self, x, y, s, nt) | |
local state, timer, life = partProperty(self, sim.FIELD_TMP), partProperty(self, sim.FIELD_TMP2), partProperty(self, sim.FIELD_LIFE) | |
if state == 1 then | |
partProperty(self, sim.FIELD_VX, -0.5) | |
elseif state == 2 then | |
partProperty(self, sim.FIELD_VX, 0.5) | |
elseif life > 0 then | |
life = life - 1 | |
partProperty(self, sim.FIELD_LIFE, life) | |
local bugMade = false | |
for nx = x - 1, x + 1 do | |
for ny = y - 1, y + 1 do | |
if not sim.pmap(nx, ny) then | |
partCreate(-3, nx, ny, BUG) | |
bugMade = true | |
break | |
end | |
end | |
if bugMade then break end | |
end | |
end | |
if timer <= 0 then | |
partProperty(self, sim.FIELD_TMP, random(0, 2)) | |
partProperty(self, sim.FIELD_TMP2, random(100, 200)) | |
else | |
partProperty(self, sim.FIELD_TMP2, timer - 1) | |
end | |
for part, nx, ny in sim.neighbors(x, y, 1, 1) do | |
local ptype = partProperty(part, sim.FIELD_TYPE) | |
if ptype == elem.DEFAULT_PT_PLNT or ptype == RCHK then | |
partKill(part) | |
partProperty(self, sim.FIELD_LIFE, life + 1) | |
elseif ptype == elem.DEFAULT_PT_WOOD then | |
partKill(part) | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment