Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LAG: Lag tester!
- -- This is just an edited version of my energy converter.
- -- Definition
- local lag = elements.allocate("lag", "lag")
- elements.element(lag, elements.element(elements.DEFAULT_PT_DMG))
- elements.property(lag, "Name", "LAG")
- elements.property(lag, "Colour", 0x808080) -- Boring gray
- elements.property(lag, "Description", "Unstoppable lag.")
- elements.property(lag, "MenuSection", elem.SC_SPECIAL)
- elements.property(lag, "Properties", elem.TYPE_SOLID)
- local function lag_update(i,x,y,s,nt)
- local mytmp = math.huge --sim.partProperty(i, sim.FIELD_TMP)
- local target = sim.partProperty(i, sim.FIELD_LIFE)
- local flags = sim.partProperty(i, sim.FIELD_TMP2)
- local diff = 0
- local mult = 0
- -- Energy stealing
- for r in sim.parts() do -- Ugly line incoming!
- if (sim.partProperty(r, sim.FIELD_TYPE) ~= elem.DEFAULT_PT_VIBR) and (bit.bor(flags, 4) > 0) then
- mytmp = mytmp + sim.partProperty(r, sim.FIELD_TMP)
- sim.partProperty(r, sim.FIELD_LIFE, 0)
- sim.partProperty(r, sim.FIELD_TMP, 0)
- sim.partProperty(r, sim.FIELD_TMP2, 0)
- sim.partProperty(r, sim.FIELD_TMP2, 0)
- end
- end
- -- Energy absorption
- if bit.bor(flags, 1) > 0 then
- diff = sim.partProperty(i, sim.FIELD_TEMP) - target
- mytmp = mytmp + math.floor(diff / 3)
- sim.partProperty(i, sim.FIELD_TEMP, (diff % 3) + target)
- end
- if bit.bor(flags, 2) > 0 then
- diff = get_pressure(x, y) - target
- if diff < 0 then mult = 2 else mult = 7 end
- mytmp = mytmp + math.floor(diff) * mult
- set_pressure(x, y, (diff % 1) + target)
- end
- -- Energy emission
- if bit.bor(flags, 8) > 0 then
- diff = sim.partProperty(i, sim.FIELD_TEMP) + (mytmp * 3)
- sim.partProperty(i, sim.FIELD_TEMP, diff)
- end
- if bit.bor(flags, 16) > 0 then
- if mytmp < 0 then mult = 2 else mult = 7 end
- diff = get_pressure(x, y) + (mytmp / mult)
- set_pressure(x, y, diff)
- end
- if bit.bor(flags, 32) > 0 then
- diff = math.floor(mytmp / 20)
- mytmp = mytmp % 20
- for i=1,diff,1 do
- sim.partCreate(-3, x, y, i)
- end
- end
- end
- -- Apply update function
- elements.property(lag, "Update", lag_update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement