Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wizard={}
- mana={}
- file=fs.open('grade','r')
- if not file then return end
- local line=file.readLine()
- while line do
- local username,grade=line:match('([_%w]+)%s+(%d+)')
- if username then
- print(username,' ',grade)
- wizard[username]=tonumber(grade)
- mana[username]=(grade+1)*10
- end
- line=file.readLine()
- end
- file.close()
- ami=peripheral.wrap("right")
- cb=peripheral.wrap("left")
- os.loadAPI("thread")
- local function nbtToTable(typ, val)
- if typ == "compound" then
- local rv = {}
- for _, key in ipairs(val.getKeys()) do
- local typ2, val2 = val.getValue(key)
- rv[key] = nbtToTable(typ2, val2)
- end
- return {type="compound", value=rv}
- elseif typ == "list" then
- local n = val.getSize()
- local rv = {}
- for k = 0, n - 1 do
- local typ2, val2 = val.get(k)
- rv[k+1] = nbtToTable(typ2, val2)
- end
- return {type="list", value=rv}
- elseif typ == "string" or typ == "double" or typ == "float" or typ == "byte" or typ == "short" or typ == "int" or typ == "long" then
- return {type=typ, value=val}
- elseif typ == "intArray" or typ == "byteArray" then
- local rv = {}
- for k = 0, val.getLength() - 1 do
- rv[k+1] = val.get(k)
- end
- return {type=typ, value=rv}
- else
- error("unimplemented tag type: "..typ)
- end
- end
- local function tableToNbt(typ, tag, tbl)
- assert(type(tag) == "table" and tbl.type == typ and tag.getType() == typ)
- if typ == "compound" then
- for _, key in ipairs(tag.getKeys()) do
- if not tbl.value[key] then
- tag.remove(key)
- end
- end
- for key, value in pairs(tbl.value) do
- if value.type == "compound" or value.type == "list" then
- tag.setValue(key, value.type)
- tableToNbt(value.type, select(2, tag.getValue(key)), value)
- elseif value.type == "intArray" or value.type == "byteArray" then
- tag.setValue(key, value.type, #value.value)
- tableToNbt(value.type, select(2, tag.getValue(key)), value)
- elseif value.type == "string" or value.type == "double" or value.type == "float" or value.type == "byte" or value.type == "short" or value.type == "int" then
- tag.setValue(key, value.type, value.value)
- elseif value.type == "long" then
- tag.setValue(key, value.type, value.value[1], value.value[2])
- else
- error("unimplemented tag type: "..value.type)
- end
- end
- elseif typ == "list" then
- while tag.getSize() > 0 do
- tag.remove(0)
- end
- for _, value in ipairs(tbl.value) do
- if value.type == "compound" or value.type == "list" then
- tag.add(tag.getSize(), value.type)
- tableToNbt(value.type, select(2, tag.get(tag.getSize() - 1)), value)
- elseif value.type == "intArray" or value.type == "byteArray" then
- tag.add(tag.getSize(), value.type, #value.value)
- tableToNbt(value.type, select(2, tag.get(tag.getSize() - 1)), value)
- elseif value.type == "string" or value.type == "double" or value.type == "float" or value.type == "byte" or value.type == "short" or value.type == "int" then
- tag.add(tag.getSize(), value.type, value.value)
- elseif value.type == "long" then
- tag.add(tag.getSize(), value.type, value.value[1], value.value[2])
- else
- error("unimplemented tag type: "..value.type)
- end
- end
- elseif typ == "intArray" or typ == "byteArray" then
- for k = 0, tag.getLength() - 1 do
- tag.set(k, tbl.value[k+1])
- end
- else
- error("unimplemented tag type: "..typ)
- end
- end
- local function readTileNBT(te)
- te.readNBT()
- return nbtToTable("compound", te.getNBT())
- end
- local function writeTileNBT(te, nbt)
- tableToNbt("compound", te.getNBT(), nbt)
- te.writeNBT()
- end
- local function getUserByName(name)
- local user={name=name, grade=wizard[name], mana=mana[name]}
- user.pl=ami.getPlayerByName(name)
- if user.pl then user.ent=user.pl.asEntity() end
- if user.ent then user.w=ami.getWorld(user.ent.getWorldID()) end
- if user.w then return user end
- end
- commands={}
- grade={}
- cost={}
- commands.flora=function(master)
- local id={{31,1},{37,0},{38,0},{38,1}}
- local x, y, z = master.ent.getPosition()
- local d=master.grade+1
- x=math.floor(x) y=math.floor(y) z=math.floor(z)
- for X=x-d,x+d do
- for Z=z-d,z+d do
- for Y=y-2,y+1 do
- if master.w.getBlockID(X, Y-1, Z)==2 and master.w.getBlockID(X, Y, Z)==0 then
- local item=math.random(#id)
- master.w.setBlock(X, Y, Z, id[item][1], id[item][2])
- end
- end
- end
- end
- end
- cost.flora=1
- function FrProc(master)
- master.pl.sendChat("On")
- local t=(master.grade+1)*5
- local w=master.w
- local x, y, z
- local memo={}
- for i=1,t do
- memo[i]={}
- x, y, z = master.ent.getPosition()
- x=math.floor(x+0.5) y=math.floor(y+0.5) z=math.floor(z+0.5)
- for X=x-1,x+1 do
- for Z=z-1,z+1 do
- for Y=y-2,y do
- if w.getBlockID(X, Y, Z)==9 and w.getBlockID(X, Y+1, Z)==0 then
- w.setBlock(X, Y, Z, 79, 0)
- table.insert(memo[i],{X, Y, Z})
- end
- end
- end
- end
- sleep(1)
- end
- master.pl.sendChat("Off")
- for i=1,t do
- for j=1,#memo[i] do
- x=memo[i][j][1] y=memo[i][j][2] z=memo[i][j][3]
- if w.getBlockID(x, y, z)==79 then
- w.setBlock(x, y, z, 9, 0)
- end
- end
- sleep(1)
- end
- end
- commands.freez=function(master)
- thread.create(FrProc,master)
- end
- commands.lumos=function(master)
- cb.setCommand("effect "..master.name.." 16 "..(master.grade+1)*5)
- cb.runCommand()
- end
- cost.lumos=1
- commands.informous=function(master)
- master.pl.sendChat('Your magic grade is '..master.grade..
- '. Quantity of mana is '..master.mana )
- end
- function PcProc(master)
- local x, y, z, t
- local col={14540253, 14384446, 11751612, 7047881, 11642407, 4304440,
- 13665433, 3042953, 3029133, 5190175, 3491355, 9843760}
- local maxcol=(master.grade+1)*2
- if maxcol>#col then maxcol=col end
- for i=0,master.grade do
- if master.ent.getWorldID()==0 then
- x, y, z = master.ent.getPosition()
- if master.grade>1 then t=math.random(2) else t=master.grade end
- cb.setCommand("summon FireworksRocketEntity "..x.." ".. y+2 .." "..z..
- " {LifeTime:20,FireworksItem:{id:401,Count:1,tag:{Fireworks:{Explosions:[{Flicker:1,Trail:1,Type:"..t..
- ",Colors:["..col[math.random(maxcol)]..
- "],FadeColors:["..col[math.random(maxcol)].."]}]}}}}")
- cb.runCommand()
- end
- sleep(3)
- end
- end
- commands.periculum=function(master)
- thread.create(PcProc,master)
- end
- commands.meteo=function(master,param)
- if param=="maxima" then cb.setCommand("weather thunder")
- elseif param=="" then cb.setCommand("weather rain")
- elseif param=="recanto" then cb.setCommand("weather clear")
- else return end
- cb.runCommand()
- end
- --[[
- commands.ghost=function()
- if master then master.pl.sendChat('Mode ghost switched on') end
- work=true
- while work do
- for _, user in pairs(masters) do
- local x, y, z = user.ent.getPosition()
- local dx, dy, dz = user.ent.getLooking()
- if math.abs(dx)>math.abs(dz) then
- dz=0 if dx>0 then dx=1 else dx=-1 end
- else
- dx=0 if dz>0 then dz=1 else dz=-1 end
- end
- if --user.w.getBlockID(x+dx,y,z+dz)~=0 and
- user.w.getBlockID(x+dx,y+1,z+dz)~=0 and
- --user.w.getBlockID(x+2*dx,y,z+2*dz)==0 and
- user.w.getBlockID(x+2*dx,y+1,z+2*dz)==0 then
- user.ent.setPosition(x + 2*dx, y , z + 2*dz)
- end
- end
- sleep(1)
- end
- if master then master.pl.sendChat('Mode ghost switched off') end
- end
- commands.fireball=function(master,pow)
- pow=tonumber(pow) or 1
- if pow>master.grade then pow=master.grade end
- local x, y, z = master.ent.getPosition()
- local dx, dy, dz = master.ent.getLooking()
- x=x+2*dx y=y+2*dy+1.6 z=z+2*dz
- -- for i=1,50 do
- -- x=x+dx y=y+dy z=z+dz
- -- if master.w.getBlockID(x, y, z)~=0 then break end
- ---- master.w.setBlock(x, y, z, 89, 0)
- ---- sleep(0.03)
- -- end
- -- master.w.explode(x, y, z, pow, true, true)
- cb.setCommand("summon Fireball "..x.." "..y.." "..z.." {ExplosionPower:"..pow..",direction:["..5*dx..","..5*dy..","..5*dz.."]}")
- cb.runCommand()
- end
- commands.fill=function(master,id)
- id=tonumber(id) or 2
- local x, y, z = master.ent.getPosition()
- local t={{x=math.floor(x),y=math.floor(y),z=math.floor(z)}}
- while #t>0 do
- if master.w.getBlockID(t[1].x, t[1].y, t[1].z)==0 and
- (t[1].x-x)*(t[1].x-x)+(t[1].y-y)*(t[1].y-y)+(t[1].z-z)*(t[1].z-z)<50*50 then
- master.w.setBlock(t[1].x, t[1].y, t[1].z, id, 0)
- if #t<1000 then
- table.insert(t,{x=t[1].x-1,y=t[1].y,z=t[1].z})
- table.insert(t,{x=t[1].x+1,y=t[1].y,z=t[1].z})
- table.insert(t,{x=t[1].x,y=t[1].y,z=t[1].z-1})
- table.insert(t,{x=t[1].x,y=t[1].y,z=t[1].z+1})
- table.insert(t,{x=t[1].x,y=t[1].y-1,z=t[1].z})
- end
- end
- table.remove(t,1)
- end
- master.ent.setPosition(x,y+1,z)
- end
- function give(user,id,num)
- local x, y, z = user.ent.getPosition()
- x=math.floor(x) y=math.floor(y+1) z=math.floor(z)
- user.w.setBlock(x, y, z, 54, 0)
- local te = user.w.getTileEntity(x, y, z)
- local nbt = readTileNBT(te)
- -- Add in slot 0
- table.insert(nbt.value.Items.value, {type="compound", value={id={type="short", value=id},
- Count={type="byte", value=num}, Damage={type="short", value=0}, Slot={type="byte", value=0}}})
- writeTileNBT(te, nbt)
- user.w.setBlock(x, y, z, 0, 0)
- print('Give to ',user.pl.getUsername(),' <',id,'> <',num,'>')
- end
- commands.give=function(master,param)
- local name,id,num=param:match('([%w_]+)%s+(%d+)%s*(%d*)')
- if name then
- id=tonumber(id) num=tonumber(num) or 1
- local user=getUserByName(name)
- if user then give(user,id,num) end
- end
- end
- grade.give=5
- commands.giveme=function(master,param)
- local id,num=param:match('(%d+)%s*(%d*)')
- if id then
- id=tonumber(id) num=tonumber(num) or 1
- give(master,id,num)
- end
- end
- grade.giveme=5
- commands.tp=function(master,name)
- local user=getUserByName(name)
- if user then
- local x, y, z = user.ent.getPosition()
- master.ent.setPosition(x, y, z)
- end
- end
- grade.tp=5
- ]]
- while true do
- local event,user,mess=os.pullEvent("chat_message")
- -- print(event,' ',user,' ',mess)
- if event=="chat_message" then
- if wizard[user] then
- command,params=mess:match('^$(%w*)%s*(.*)')
- if commands[command] then
- local master=getUserByName(user)
- if (cost[command] or 0)<=master.mana then
- print(user,' ',command)
- mana[user]=master.mana-(cost[command] or 0)
- commands[command](master,params)
- else
- master.pl.sendChat("You have not mana.")
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement