Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------
- ---Scien_Tific's CMND element script---
- --------------ver. 16419---------------
- --!!!Scroll down at own risk!!!
- --Variables
- local id = elements.allocate("cmndMod","cmnd")
- --Sparking function
- local function spark(i,e)
- if sim.partProperty(i,sim.FIELD_LIFE) == 0 then
- sim.partChangeType(i,elem.DEFAULT_PT_SPRK)
- sim.partProperty(i,sim.FIELD_LIFE,4)
- sim.partProperty(i,sim.FIELD_CTYPE,e)
- end
- end
- --Activating function
- local function activate(x,y)
- p = sim.partID(x + 1,y)
- if p ~= nil then
- if sim.partProperty(p,sim.FIELD_TYPE) == id and sim.partProperty(p,sim.FIELD_LIFE) == -2 then
- sim.partProperty(p,sim.FIELD_LIFE,-3)
- end
- end
- end
- --Decode function to change raw tmp data to something the CMND particle can use
- local function decode(tmp,cmd,tmp2)
- --placeone/ifexists
- if cmd == 0 or cmd == 6 then
- tmp = tostring(tmp)
- tmp = string.sub(tmp,2,string.len(tmp))
- decoded = {"",""}
- for i = 1,string.len(tmp),1 do
- if i <= 4 then
- decoded[1] = decoded[1]..string.sub(tmp,i,i)
- end
- if i >= 5 then
- decoded[2] = decoded[2]..string.sub(tmp,i,i)
- end
- end
- for i,s in pairs(decoded) do
- if string.sub(s,1,1) == "1" then
- decoded[i] = -tonumber(string.sub(s,2,string.len(s)))
- else
- decoded[i] = tonumber(s)
- end
- end
- return decoded
- end
- --placebox/placeclone/placecloneexcept
- if cmd >= 1 and cmd <= 3 then
- tmp = tostring(tmp)
- tmp = string.sub(tmp,2,string.len(tmp))
- tmp2 = tostring(tmp2)
- tmp2 = string.sub(tmp2,2,string.len(tmp2))
- decoded = {"","","",""}
- for i = 1,string.len(tmp),1 do
- if i <= 4 then
- decoded[1] = decoded[1]..string.sub(tmp,i,i)
- end
- if i >= 5 then
- decoded[2] = decoded[2]..string.sub(tmp,i,i)
- end
- end
- for i = 1,string.len(tmp2),1 do
- if i <= 4 then
- decoded[3] = decoded[3]..string.sub(tmp2,i,i)
- end
- if i >= 5 then
- decoded[4] = decoded[4]..string.sub(tmp2,i,i)
- end
- end
- for i,s in pairs(decoded) do
- if string.sub(s,1,1) == "1" then
- decoded[i] = -tonumber(string.sub(s,2,string.len(s)))
- else
- decoded[i] = tonumber(s)
- end
- end
- return decoded
- end
- --ifinradiusat
- if cmd == 5 then
- tmp = tostring(tmp)
- tmp = string.sub(tmp,2,string.len(tmp))
- decoded = {"","",""}
- for i = 1,string.len(tmp),1 do
- if i <= 4 then
- decoded[1] = decoded[1]..string.sub(tmp,i,i)
- end
- if i >= 5 then
- decoded[2] = decoded[2]..string.sub(tmp,i,i)
- end
- end
- for i,s in pairs(decoded) do
- if string.sub(s,1,1) == "1" then
- decoded[i] = -tonumber(string.sub(s,2,string.len(s)))
- else
- decoded[i] = tonumber(s)
- end
- end
- return decoded
- end
- --datachange
- if cmd == 7 then
- tmp = tostring(tmp)
- tmp = string.sub(tmp,2,string.len(tmp))
- decoded = {"","","",""}
- for i = 1,string.len(tmp),1 do
- if i <= 4 then
- decoded[1] = decoded[1]..string.sub(tmp,i,i)
- end
- if i >= 5 and i <= 8 then
- decoded[2] = decoded[2]..string.sub(tmp,i,i)
- end
- if i == 9 then
- decoded[3] = decoded[3]..string.sub(tmp,i,i)
- end
- end
- for i,s in pairs(decoded) do
- if i <= 2 then
- if string.sub(s,1,1) == "1" then
- decoded[i] = -tonumber(string.sub(s,2,string.len(s)))
- else
- decoded[i] = tonumber(s)
- end
- else
- decoded[i] = tonumber(s)
- end
- end
- return decoded
- end
- return {0,0,0,0}
- end
- --Command function that runs the different commands
- local function commands(i,x,y,cmd,data)
- if data ~= nil then
- --placeone
- if cmd == 0 then
- if sim.partProperty(i,sim.FIELD_CTYPE) ~= 0 then
- sim.partCreate(-1,data[1] + x,data[2] + y,sim.partProperty(i,sim.FIELD_CTYPE))
- else
- sim.partKill(data[1],data[2])
- end
- end
- --placebox
- if cmd == 1 then
- sim.createBox(data[1] + x,data[2] + y,data[3] + data[1] + x,data[4] + data[2] + y,sim.partProperty(i,sim.FIELD_CTYPE))
- end
- --placeclone
- if cmd == 2 then
- p = sim.partID(data[1] + x,data[2] + y)
- if p ~= nil then
- if sim.partProperty(p,sim.FIELD_TYPE) == sim.partProperty(i,sim.FIELD_CTYPE) or sim.partProperty(i,sim.FIELD_CTYPE) == 0 then
- c = sim.partCreate(-1,data[3] + x,data[4] + y,sim.partProperty(p,sim.FIELD_TYPE))
- if cid ~= -1 then
- sim.partProperty(c,sim.FIELD_CTYPE,sim.partProperty(p,sim.FIELD_CTYPE))
- sim.partProperty(c,sim.FIELD_TMP,sim.partProperty(p,sim.FIELD_TMP))
- sim.partProperty(c,sim.FIELD_TMP2,sim.partProperty(p,sim.FIELD_TMP2))
- sim.partProperty(c,sim.FIELD_LIFE,sim.partProperty(p,sim.FIELD_LIFE))
- sim.partProperty(c,sim.FIELD_VX,sim.partProperty(p,sim.FIELD_VX))
- sim.partProperty(c,sim.FIELD_VY,sim.partProperty(p,sim.FIELD_VY))
- sim.partProperty(c,sim.FIELD_DCOLOUR,sim.partProperty(p,sim.FIELD_DCOLOUR))
- sim.partProperty(c,sim.FIELD_TEMP,sim.partProperty(p,sim.FIELD_TEMP))
- end
- end
- end
- end
- --placecloneexcept
- if cmd == 3 then
- p = sim.partID(data[1] + x,data[2] + y)
- if p ~= nil then
- if sim.partProperty(p,sim.FIELD_TYPE) ~= sim.partProperty(i,sim.FIELD_CTYPE) then
- c = sim.partCreate(-1,data[3] + x,data[4] + y,sim.partProperty(p,sim.FIELD_TYPE))
- if cid ~= -1 then
- sim.partProperty(c,sim.FIELD_CTYPE,sim.partProperty(p,sim.FIELD_CTYPE))
- sim.partProperty(c,sim.FIELD_TMP,sim.partProperty(p,sim.FIELD_TMP))
- sim.partProperty(c,sim.FIELD_TMP2,sim.partProperty(p,sim.FIELD_TMP2))
- sim.partProperty(c,sim.FIELD_LIFE,sim.partProperty(p,sim.FIELD_LIFE))
- sim.partProperty(c,sim.FIELD_VX,sim.partProperty(p,sim.FIELD_VX))
- sim.partProperty(c,sim.FIELD_VY,sim.partProperty(p,sim.FIELD_VY))
- sim.partProperty(c,sim.FIELD_DCOLOUR,sim.partProperty(p,sim.FIELD_DCOLOUR))
- sim.partProperty(c,sim.FIELD_TEMP,sim.partProperty(p,sim.FIELD_TEMP))
- end
- end
- end
- end
- --ifinradius
- if cmd == 4 then
- for ni,n in pairs(sim.partNeighbours(x,y,sim.partProperty(i,sim.FIELD_TMP))) do
- if sim.partProperty(n,sim.FIELD_TYPE) == sim.partProperty(i,sim.FIELD_CTYPE) or sim.partProperty(i,sim.FIELD_CTYPE) == 0 then
- for ni,n in pairs(sim.partNeighbours(x,y,2,elem.DEFAULT_PT_METL)) do
- spark(n,elem.DEFAULT_PT_METL)
- end
- activate(x,y)
- break
- end
- end
- end
- --ifinradiusat
- if cmd == 5 then
- for ni,n in pairs(sim.partNeighbours(x + data[1],y + data[2],sim.partProperty(i,sim.FIELD_TMP2))) do
- if sim.partProperty(n,sim.FIELD_TYPE) == sim.partProperty(i,sim.FIELD_CTYPE) or sim.partProperty(i,sim.FIELD_CTYPE) == 0 then
- for ni,n in pairs(sim.partNeighbours(x,y,2,elem.DEFAULT_PT_METL)) do
- spark(n,elem.DEFAULT_PT_METL)
- end
- activate(x,y)
- break
- end
- end
- end
- --ifexists
- if cmd == 6 then
- p = sim.partID(data[1] + x,data[2] + y)
- if p ~= nil then
- if sim.partProperty(p,sim.FIELD_TYPE) == sim.partProperty(i,sim.FIELD_CTYPE) or sim.partProperty(i,sim.FIELD_CTYPE) == 0 then
- for ni,n in pairs(sim.partNeighbours(x,y,2,elem.DEFAULT_PT_METL)) do
- spark(n,elem.DEFAULT_PT_METL)
- end
- activate(x,y)
- end
- end
- end
- --datachange
- if cmd == 7 then
- p = sim.partID(data[1] + x,data[2] + y)
- if p ~= nil then
- --ctype
- if data[3] == 0 then
- sim.partProperty(p,sim.FIELD_CTYPE,sim.partProperty(i,sim.FIELD_CTYPE))
- end
- --tmp
- if data[3] == 1 then
- sim.partProperty(p,sim.FIELD_TMP,sim.partProperty(i,sim.FIELD_TMP2))
- end
- --life
- if data[3] == 2 then
- sim.partProperty(p,sim.FIELD_LIFE,sim.partProperty(i,sim.FIELD_TMP2))
- end
- --tmp2
- if data[3] == 2 then
- sim.partProperty(p,sim.FIELD_TMP2,sim.partProperty(i,sim.FIELD_TMP2))
- end
- --temp
- if data[3] == 2 then
- sim.partProperty(p,sim.FIELD_TEMP,sim.partProperty(i,sim.FIELD_TMP2))
- end
- end
- end
- end
- end
- --Update function that puts it all together (Defined before properties because Lua)
- local function update(i,x,y)
- if sim.partProperty(i,sim.FIELD_LIFE) > 1 then
- sim.partProperty(i,sim.FIELD_LIFE,sim.partProperty(i,sim.FIELD_LIFE) + 1)
- if sim.partProperty(i,sim.FIELD_LIFE) == 10 then
- sim.partProperty(i,sim.FIELD_LIFE,1)
- end
- end
- --Impulse
- if sim.partProperty(i,sim.FIELD_LIFE) == -1 then
- --Commands here
- commands(i,x,y,sim.partProperty(i,sim.FIELD_TEMP),decode(sim.partProperty(i,sim.FIELD_TMP),sim.partProperty(i,sim.FIELD_TEMP),sim.partProperty(i,sim.FIELD_TMP2)))
- sim.partKill(i)
- --Repeat
- elseif sim.partProperty(i,sim.FIELD_LIFE) == 0 then
- --Commands here
- commands(i,x,y,sim.partProperty(i,sim.FIELD_TEMP),decode(sim.partProperty(i,sim.FIELD_TMP),sim.partProperty(i,sim.FIELD_TEMP),sim.partProperty(i,sim.FIELD_TMP2)))
- --Sparked
- elseif sim.partProperty(i,sim.FIELD_LIFE) == 1 then
- for ni,n in pairs(sim.partNeighbors(x,y,1,elem.DEFAULT_PT_SPRK)) do
- --Commands here
- commands(i,x,y,sim.partProperty(i,sim.FIELD_TEMP),decode(sim.partProperty(i,sim.FIELD_TMP),sim.partProperty(i,sim.FIELD_TEMP),sim.partProperty(i,sim.FIELD_TMP2)))
- sim.partProperty(i,sim.FIELD_LIFE,2)
- break
- end
- --Activated
- elseif sim.partProperty(i,sim.FIELD_LIFE) == -3 then
- --Commands here
- commands(i,x,y,sim.partProperty(i,sim.FIELD_TEMP),decode(sim.partProperty(i,sim.FIELD_TMP),sim.partProperty(i,sim.FIELD_TEMP),sim.partProperty(i,sim.FIELD_TMP2)))
- sim.partProperty(i,sim.FIELD_LIFE,-2)
- end
- end
- --Element properties
- elem.property(id,"Name","CMND")
- elem.property(id,"Enabled",1)
- elem.property(id,"Description","Can do lots of stuff. Use carefully in small amounts.")
- elem.property(id,"Color",0xFFFF80)
- elem.property(id,"MenuVisible",1)
- elem.property(id,"MenuSection",elem.SC_SPECIAL)
- elem.property(id,"Properties",elem.TYPE_SOLID + elem.PROP_DRAWONCTYPE + elem.PROP_NOAMBHEAT + elem.PROP_NEUTPASS)
- elem.property(id,"Falldown",0)
- elem.property(id,"Advection",0)
- elem.property(id,"AirDrag",0)
- elem.property(id,"AirLoss",1)
- elem.property(id,"Loss",0)
- elem.property(id,"Collision",0)
- elem.property(id,"Gravity",0)
- elem.property(id,"Diffusion",0)
- elem.property(id,"HotAir",0)
- elem.property(id,"Flammable",0)
- elem.property(id,"Explosive",0)
- elem.property(id,"Meltable",0)
- elem.property(id,"Hardness",0)
- elem.property(id,"Weight",100)
- elem.property(id,"Temperature",sim.R_TEMP + 273.15)
- elem.property(id,"HeatConduct",0)
- elem.property(id,"State",elem.ST_SOLID)
- elem.property(id,"Update",update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement