Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
3,657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. --[[
  2.    
  3. Alien Microcontroller code
  4. Make sure to set up the microcontroller and ports properly!
  5.  
  6. Port 1 - Gyro + Position Instrument
  7.  
  8. Port 2 - Toggle weapon fire (use transformers to fire weapons)
  9.  
  10. Port 3 - Thrusters
  11.  
  12. Port 4 - Life Sensors
  13.    
  14. --]]
  15. local Gyro = GetPartFromPort(1, "Gyro")
  16. local PositionInstrument = GetPartFromPort(1, "Instrument")
  17. local WeaponSwitch = GetPartFromPort(2, "Switch")
  18. local Thrusters = GetPartFromPort(3, "Thruster") or GetPartFromPort(3, "IonRocket") or GetPartFromPort(3, "IonDrive")
  19. local LifeSensor = GetPartFromPort(4, "LifeSensor")
  20.  
  21. local function GetNearestOrganism()
  22.     local Readings = LifeSensor:GetReading()
  23.     local CurrentPosition = PositionInstrument:GetReading(6)
  24.     local OrganismName, Position;
  25.     local NearestDistance = 5000000;
  26.    
  27.     for Organism, RootPos in next, Readings do
  28.         local RootDistance = (RootPos - CurrentPosition).Magnitude
  29.         if RootDistance < NearestDistance then
  30.             NearestDistance = RootDistance
  31.             OrganismName = Organism
  32.             Position = RootPos
  33.         end
  34.     end
  35.    
  36.     return OrganismName, Position
  37. end
  38.  
  39. local function EngageThrusters(Speed)
  40.     Thrusters:Configure({Propulsion = Speed})
  41. end
  42.  
  43. local function ActivateWeapons(Boolean)
  44.     WeaponSwitch:Configure({SwitchValue = Boolean})
  45. end
  46.  
  47. while true do
  48.     local CurrentPosition = PositionInstrument:GetReading(6)
  49.     local NearestOrganism, Position = GetNearestOrganism()
  50.    
  51.     if not NearestOrganism then ActivateWeapons(false) EngageThrusters(0) wait(5) else
  52.         local RandomSpotAroundPlayer = CFrame.new(Position, Position + Vector3.new(math.random(-200, 200), math.random(-10, 200), math.random(-200, 200)))
  53.         * CFrame.new(0, 0, math.random(200, 400))
  54.         local RandomSpotPos = RandomSpotAroundPlayer.Position
  55.        
  56.         print(RandomSpotPos, Position)
  57.         local Tick = 0;
  58.         repeat wait(0.25)
  59.             CurrentPosition = PositionInstrument:GetReading(6)
  60.             EngageThrusters(100)
  61.             Gyro:PointAt(RandomSpotAroundPlayer)
  62.             Tick = Tick + 0.25
  63.         until (RandomSpotPos - CurrentPosition).Magnitude <= 25 or Tick >= 5
  64.        
  65.         EngageThrusters(0)
  66.         wait(1)
  67.        
  68.         for i = 1, math.random(6, 10) do
  69.             local NewNearestOrganism, NewPosition = GetNearestOrganism()
  70.             if NewNearestOrganism then
  71.                 ActivateWeapons(true)
  72.                 Gyro:PointAt(NewPosition)
  73.                 wait(math.random())
  74.             else
  75.                 ActivateWeapons(false)
  76.             end
  77.         end
  78.     end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement