Marzipan_at

sfserver program_01

Jun 15th, 2021 (edited)
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. --inizialising global constants
  2.  
  3. coorfile="coords-txt";
  4. redstoneside="top";
  5. coordoffset=1024;
  6. coordfactor=256;
  7. sensorside="back";
  8. startheight=64;
  9.  
  10. sensor=peripheral.wrap(sensorside);
  11.  
  12. while true do
  13.     event=os.pullEvent();
  14.     if redstone.getInput(redstoneside) then
  15.         playerlist=sensor.getPlayers();
  16.         if fs.exists(coorfile)==false then
  17.             data={len=0,name={},x={},y={}}
  18.            
  19.         else
  20.             file=fs.open(coorfile, "r");
  21.             data=textutils.unserialize(file.readAll());
  22.             file.close();
  23.            
  24.         end
  25.            
  26.         index=1
  27.         while playerlist[index]~= nil do
  28.             found=false;
  29.             if data.len>0 then
  30.                 for i=1,data.len do
  31.                     if data.name[i]==playerlist[index].name then
  32.                         found=true;
  33.                         foundat=i;
  34.                     end
  35.                 end
  36.             end
  37.            
  38.             if found then
  39.                 name=data.name[foundat];
  40.                 coordx=data.x[foundat];
  41.                 coordy=data.y[foundat];
  42.             else
  43.                 data.len=data.len+1;
  44.                 name=playerlist[index].name;
  45.                 data.name[index]=name;
  46.                 puffx=math.sqrt(data.len-1)+1;
  47.                 puffxround=math.floor(puffx);
  48.                 roundnumber=puffxround*puffxround-2*puffxround+2;
  49.                
  50.                 if puffx-puffxround>0.5 then
  51.                    
  52.                     data.y[data.len]=puffxround*coordfactor+coordoffset;
  53.                     data.x[data.len]=(1+data.len-roundnumber-puffxround)*coordfactor+coordoffset;
  54.                    
  55.                 else
  56.                     data.x[data.len]=puffxround*coordfactor+coordoffset;
  57.                     data.y[data.len]=(1+data.len-roundnumber)*coordfactor+coordoffset;
  58.                    
  59.                 end
  60.                 coordx=data.x[data.len];
  61.                 coordy=data.y[data.len];
  62.                
  63.                 commands.tp(name,coordx,startheight+10,coordy);
  64.                 os.sleep(1);
  65.                 commands.setblock(coordx,startheight,coordy, "minecraft:dirt");
  66.                 commands.give(name, "minecraft:sapling", 2);
  67.                 commands.give(name, "minecraft:log", 8);
  68.                 file=fs.open(coorfile, "w");
  69.                 file.write(textutils.serialize(data));
  70.                 file.close();
  71.                
  72.             end
  73.             commands.tp(name,coordx,startheight+1,coordy);
  74.            
  75.             index=index+1;
  76.         end
  77.        
  78.        
  79.        
  80.        
  81.     end
  82.     if event=="key" then
  83.         os.exit()
  84.     end
  85. end
  86.  
Add Comment
Please, Sign In to add comment