Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #######################################
- -- Summon MobTower
- -- required Command Computer in ComputerCraft 1.7 or over.
- -- version 0.1, License MIT
- -- Twitter: @hevohevo
- -- #######################################
- -- Functions
- local function tbl2TagStr(tbl)
- local str = string.gsub(textutils.serializeJSON(tbl),"\"", "")
- return str
- end
- local function head(array)
- return array[1]
- end
- local function rest(array)
- return {select(2,unpack(array))}
- end
- local function _makeOptsTbl(array)
- local tmp_tbl = {}
- if type(array)~="table" or #array==0 then
- return nil
- else
- tmp_tbl=head(array)
- tmp_tbl["Riding"]=_makeOptsTbl(rest(array))
- return tmp_tbl
- end
- end
- -- 上から順番に
- -- tbl = {{id="Slime",Size=1},{id="Slime",Size=1.5},{id="Slime",Size=2}}
- function summonMobTower(tbl, x,y,z)
- assert(tbl[1] and tbl[1]["id"], "invalid arguments")
- local top_mob = tbl[1]
- local data_tags = {}
- for k,v in pairs(top_mob) do
- if k ~= "id" then
- data_tags[k]=v
- end
- end
- if #tbl>1 then
- data_tags["Riding"]=_makeOptsTbl(rest(tbl))
- end
- local text = string.format("summon %s %d %d %d %s", top_mob["id"], x,y,z, tbl2TagStr(data_tags))
- print(text)
- commands.exec(text)
- end
- -- #######################################
- -- Main
- -- 上から順に配列で指定
- -- opts = {{id="Slime",Size=1, CustomName:"hoge"},
- -- {id="Slime",Size=1},
- -- {id="Villager"}}
- -- summonMobTower(opts, x,y,z)
- function Test()
- local cx,cy,cz = commands.getBlockPosition()
- local x, y, z = cx, cy+1, cz
- local tower_tbl = {}
- for i=3,0,-0.2 do
- table.insert(tower_tbl, {id="Slime",Size=i})
- end
- summonMobTower(tower_tbl, x,y,z)
- end
- for i=1,20 do
- Test()
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement