Advertisement
ZNZNCOOP

Magic

Jul 17th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.83 KB | None | 0 0
  1. wizard={}
  2. mana={}
  3. file=fs.open('grade','r')
  4. if not file then return end
  5. local line=file.readLine()
  6. while line do
  7.   local username,grade=line:match('([_%w]+)%s+(%d+)')
  8.   if username then
  9.     print(username,' ',grade)
  10.     wizard[username]=tonumber(grade)
  11.     mana[username]=(grade+1)*10
  12.   end
  13.   line=file.readLine()
  14. end
  15. file.close()
  16.  
  17. ami=peripheral.wrap("right")
  18. cb=peripheral.wrap("left")
  19. os.loadAPI("thread")
  20.  
  21. local function nbtToTable(typ, val)
  22.         if typ == "compound" then
  23.                 local rv = {}
  24.                 for _, key in ipairs(val.getKeys()) do
  25.                         local typ2, val2 = val.getValue(key)
  26.                         rv[key] = nbtToTable(typ2, val2)
  27.                 end
  28.                 return {type="compound", value=rv}
  29.         elseif typ == "list" then
  30.                 local n = val.getSize()
  31.                 local rv = {}
  32.                 for k = 0, n - 1 do
  33.                         local typ2, val2 = val.get(k)
  34.                         rv[k+1] = nbtToTable(typ2, val2)
  35.                 end
  36.                 return {type="list", value=rv}
  37.         elseif typ == "string" or typ == "double" or typ == "float" or typ == "byte" or typ == "short" or typ == "int" or typ == "long" then
  38.                 return {type=typ, value=val}
  39.         elseif typ == "intArray" or typ == "byteArray" then
  40.                 local rv = {}
  41.                 for k = 0, val.getLength() - 1 do
  42.                         rv[k+1] = val.get(k)
  43.                 end
  44.                 return {type=typ, value=rv}
  45.         else
  46.                 error("unimplemented tag type: "..typ)
  47.         end
  48. end
  49.  
  50. local function tableToNbt(typ, tag, tbl)
  51.         assert(type(tag) == "table" and tbl.type == typ and tag.getType() == typ)
  52.         if typ == "compound" then
  53.                 for _, key in ipairs(tag.getKeys()) do
  54.                         if not tbl.value[key] then
  55.                                 tag.remove(key)
  56.                         end
  57.                 end
  58.                 for key, value in pairs(tbl.value) do
  59.                         if value.type == "compound" or value.type == "list" then
  60.                                 tag.setValue(key, value.type)
  61.                                 tableToNbt(value.type, select(2, tag.getValue(key)), value)
  62.                         elseif value.type == "intArray" or value.type == "byteArray" then
  63.                                 tag.setValue(key, value.type, #value.value)
  64.                                 tableToNbt(value.type, select(2, tag.getValue(key)), value)
  65.                         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
  66.                                 tag.setValue(key, value.type, value.value)
  67.                         elseif value.type == "long" then
  68.                                 tag.setValue(key, value.type, value.value[1], value.value[2])
  69.                         else
  70.                                 error("unimplemented tag type: "..value.type)
  71.                         end
  72.                 end
  73.         elseif typ == "list" then
  74.                 while tag.getSize() > 0 do
  75.                         tag.remove(0)
  76.                 end
  77.                 for _, value in ipairs(tbl.value) do
  78.                         if value.type == "compound" or value.type == "list" then
  79.                                 tag.add(tag.getSize(), value.type)
  80.                                 tableToNbt(value.type, select(2, tag.get(tag.getSize() - 1)), value)
  81.                         elseif value.type == "intArray" or value.type == "byteArray" then
  82.                                 tag.add(tag.getSize(), value.type, #value.value)
  83.                                 tableToNbt(value.type, select(2, tag.get(tag.getSize() - 1)), value)
  84.                         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
  85.                                 tag.add(tag.getSize(), value.type, value.value)
  86.                         elseif value.type == "long" then
  87.                                 tag.add(tag.getSize(), value.type, value.value[1], value.value[2])
  88.                         else
  89.                                 error("unimplemented tag type: "..value.type)
  90.                         end
  91.                 end
  92.         elseif typ == "intArray" or typ == "byteArray" then
  93.                 for k = 0, tag.getLength() - 1 do
  94.                         tag.set(k, tbl.value[k+1])
  95.                 end
  96.         else
  97.                 error("unimplemented tag type: "..typ)
  98.         end
  99. end
  100.  
  101. local function readTileNBT(te)
  102.         te.readNBT()
  103.         return nbtToTable("compound", te.getNBT())
  104. end
  105.  
  106. local function writeTileNBT(te, nbt)
  107.         tableToNbt("compound", te.getNBT(), nbt)
  108.         te.writeNBT()
  109. end
  110.  
  111. local function getUserByName(name)
  112.   local user={name=name, grade=wizard[name], mana=mana[name]}
  113.   user.pl=ami.getPlayerByName(name)
  114.   if user.pl then user.ent=user.pl.asEntity() end
  115.   if user.ent then user.w=ami.getWorld(user.ent.getWorldID()) end
  116.   if user.w then return user end
  117. end
  118.  
  119. commands={}
  120. grade={}
  121. cost={}
  122.  
  123. commands.flora=function(master)
  124.   local id={{31,1},{37,0},{38,0},{38,1}}
  125.   local x, y, z = master.ent.getPosition()
  126.   local d=master.grade+1
  127.   x=math.floor(x) y=math.floor(y) z=math.floor(z)
  128.   for X=x-d,x+d do
  129.     for Z=z-d,z+d do
  130.       for Y=y-2,y+1 do
  131.         if master.w.getBlockID(X, Y-1, Z)==2 and master.w.getBlockID(X, Y, Z)==0 then
  132.           local item=math.random(#id)
  133.           master.w.setBlock(X, Y, Z, id[item][1], id[item][2])
  134.         end
  135.       end
  136.     end
  137.   end
  138. end
  139. cost.flora=1
  140.  
  141. function FrProc(master)
  142.   master.pl.sendChat("On")
  143.  local t=(master.grade+1)*5
  144.  local w=master.w
  145.  local x, y, z
  146.  local memo={}
  147.  for i=1,t do
  148.   memo[i]={}
  149.   x, y, z = master.ent.getPosition()
  150.   x=math.floor(x+0.5) y=math.floor(y+0.5) z=math.floor(z+0.5)
  151.   for X=x-1,x+1 do
  152.     for Z=z-1,z+1 do
  153.       for Y=y-2,y do
  154.         if w.getBlockID(X, Y, Z)==9 and w.getBlockID(X, Y+1, Z)==0 then
  155.           w.setBlock(X, Y, Z, 79, 0)
  156.           table.insert(memo[i],{X, Y, Z})
  157.         end
  158.       end
  159.     end
  160.   end
  161.   sleep(1)
  162.  end
  163.   master.pl.sendChat("Off")
  164.  for i=1,t do
  165.   for j=1,#memo[i] do
  166.     x=memo[i][j][1] y=memo[i][j][2] z=memo[i][j][3]
  167.     if w.getBlockID(x, y, z)==79 then
  168.       w.setBlock(x, y, z, 9, 0)
  169.     end
  170.   end
  171.   sleep(1)
  172.  end
  173. end
  174.  
  175. commands.freez=function(master)
  176.   thread.create(FrProc,master)
  177. end
  178.  
  179. commands.lumos=function(master)
  180.   cb.setCommand("effect "..master.name.." 16 "..(master.grade+1)*5)
  181.   cb.runCommand()
  182. end
  183. cost.lumos=1
  184.  
  185. commands.informous=function(master)
  186.   master.pl.sendChat('Your magic grade is '..master.grade..
  187.   '. Quantity of mana is '..master.mana )
  188. end
  189.  
  190. function PcProc(master)
  191.   local x, y, z, t
  192.   local col={14540253, 14384446, 11751612, 7047881, 11642407, 4304440,
  193.              13665433, 3042953, 3029133, 5190175, 3491355, 9843760}
  194.   local maxcol=(master.grade+1)*2
  195.   if maxcol>#col then maxcol=col end
  196.   for i=0,master.grade do
  197.     if master.ent.getWorldID()==0 then
  198.       x, y, z = master.ent.getPosition()
  199.       if master.grade>1 then t=math.random(2) else t=master.grade end
  200.       cb.setCommand("summon FireworksRocketEntity "..x.." ".. y+2 .." "..z..
  201.       " {LifeTime:20,FireworksItem:{id:401,Count:1,tag:{Fireworks:{Explosions:[{Flicker:1,Trail:1,Type:"..t..
  202.       ",Colors:["..col[math.random(maxcol)]..
  203.       "],FadeColors:["..col[math.random(maxcol)].."]}]}}}}")
  204.       cb.runCommand()
  205.     end
  206.     sleep(3)
  207.   end
  208. end
  209.  
  210. commands.periculum=function(master)
  211.   thread.create(PcProc,master)
  212. end
  213.  
  214. commands.meteo=function(master,param)
  215.   if param=="maxima" then cb.setCommand("weather thunder")
  216.   elseif param=="" then cb.setCommand("weather rain")
  217.   elseif param=="recanto" then cb.setCommand("weather clear")
  218.   else return end
  219.   cb.runCommand()
  220. end
  221.  
  222. --[[
  223. commands.ghost=function()
  224.   if master then master.pl.sendChat('Mode ghost switched on') end
  225.   work=true
  226.   while work do
  227.     for _, user in pairs(masters) do
  228.       local x, y, z = user.ent.getPosition()
  229.       local dx, dy, dz = user.ent.getLooking()
  230.       if math.abs(dx)>math.abs(dz) then
  231.         dz=0 if dx>0 then dx=1 else dx=-1 end
  232.       else
  233.         dx=0 if dz>0 then dz=1 else dz=-1 end
  234.       end
  235.       if --user.w.getBlockID(x+dx,y,z+dz)~=0 and
  236.          user.w.getBlockID(x+dx,y+1,z+dz)~=0 and
  237.          --user.w.getBlockID(x+2*dx,y,z+2*dz)==0 and
  238.          user.w.getBlockID(x+2*dx,y+1,z+2*dz)==0 then
  239.          user.ent.setPosition(x + 2*dx, y , z + 2*dz)
  240.       end
  241.     end
  242.     sleep(1)
  243.   end
  244.   if master then master.pl.sendChat('Mode ghost switched off') end
  245. end
  246.  
  247. commands.fireball=function(master,pow)
  248.   pow=tonumber(pow) or 1
  249.   if pow>master.grade then pow=master.grade end
  250.   local x, y, z = master.ent.getPosition()
  251.   local dx, dy, dz = master.ent.getLooking()
  252.   x=x+2*dx y=y+2*dy+1.6 z=z+2*dz
  253. --  for i=1,50 do
  254. --    x=x+dx y=y+dy z=z+dz
  255. --    if master.w.getBlockID(x, y, z)~=0 then break end
  256. ----    master.w.setBlock(x, y, z, 89, 0)
  257. ----    sleep(0.03)
  258. --  end
  259. --  master.w.explode(x, y, z, pow, true, true)
  260.   cb.setCommand("summon Fireball "..x.." "..y.." "..z.." {ExplosionPower:"..pow..",direction:["..5*dx..","..5*dy..","..5*dz.."]}")
  261.   cb.runCommand()
  262. end
  263.  
  264. commands.fill=function(master,id)
  265.   id=tonumber(id) or 2
  266.   local x, y, z = master.ent.getPosition()
  267.   local t={{x=math.floor(x),y=math.floor(y),z=math.floor(z)}}
  268.   while #t>0 do
  269.     if master.w.getBlockID(t[1].x, t[1].y, t[1].z)==0 and
  270.        (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
  271.       master.w.setBlock(t[1].x, t[1].y, t[1].z, id, 0)
  272.       if #t<1000 then
  273.         table.insert(t,{x=t[1].x-1,y=t[1].y,z=t[1].z})
  274.         table.insert(t,{x=t[1].x+1,y=t[1].y,z=t[1].z})
  275.         table.insert(t,{x=t[1].x,y=t[1].y,z=t[1].z-1})
  276.         table.insert(t,{x=t[1].x,y=t[1].y,z=t[1].z+1})
  277.         table.insert(t,{x=t[1].x,y=t[1].y-1,z=t[1].z})
  278.       end
  279.     end
  280.     table.remove(t,1)
  281.   end
  282.   master.ent.setPosition(x,y+1,z)
  283. end
  284.  
  285. function give(user,id,num)
  286.     local x, y, z = user.ent.getPosition()
  287.     x=math.floor(x) y=math.floor(y+1) z=math.floor(z)
  288.     user.w.setBlock(x, y, z, 54, 0)
  289.     local te = user.w.getTileEntity(x, y, z)
  290.     local nbt = readTileNBT(te)
  291.     -- Add in slot 0
  292.     table.insert(nbt.value.Items.value, {type="compound", value={id={type="short", value=id},
  293.     Count={type="byte", value=num}, Damage={type="short", value=0}, Slot={type="byte", value=0}}})
  294.     writeTileNBT(te, nbt)
  295.     user.w.setBlock(x, y, z, 0, 0)    
  296.     print('Give to ',user.pl.getUsername(),' <',id,'> <',num,'>')
  297. end
  298.  
  299. commands.give=function(master,param)
  300.   local name,id,num=param:match('([%w_]+)%s+(%d+)%s*(%d*)')
  301.   if name then
  302.     id=tonumber(id) num=tonumber(num) or 1
  303.     local user=getUserByName(name)
  304.     if user then give(user,id,num) end
  305.   end
  306. end
  307. grade.give=5
  308.  
  309. commands.giveme=function(master,param)
  310.   local id,num=param:match('(%d+)%s*(%d*)')
  311.   if id then
  312.     id=tonumber(id) num=tonumber(num) or 1
  313.     give(master,id,num)
  314.   end
  315. end
  316. grade.giveme=5
  317.  
  318. commands.tp=function(master,name)
  319.   local user=getUserByName(name)
  320.   if user then
  321.     local x, y, z = user.ent.getPosition()
  322.     master.ent.setPosition(x, y, z)
  323.   end
  324. end
  325. grade.tp=5
  326. ]]
  327.  
  328. while true do
  329.   local event,user,mess=os.pullEvent("chat_message")
  330. --  print(event,' ',user,' ',mess)
  331.   if event=="chat_message" then
  332.     if wizard[user] then
  333.       command,params=mess:match('^$(%w*)%s*(.*)')
  334.       if commands[command] then
  335.         local master=getUserByName(user)
  336.         if (cost[command] or 0)<=master.mana then
  337.           print(user,' ',command)
  338.           mana[user]=master.mana-(cost[command] or 0)
  339.           commands[command](master,params)
  340.         else
  341.           master.pl.sendChat("You have not mana.")
  342.         end
  343.       end
  344.     end
  345.   end
  346. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement