Advertisement
ChanServ

metastruct autominer

Jul 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.52 KB | None | 0 0
  1. --[[
  2. To the extent possible under law, the author has dedicated all copyright
  3. and related and neighboring rights to this software to the public domain
  4. worldwide. This software is distributed without any warranty. You should
  5. have received a copy of the CC0 Public Domain Dedication along with this
  6. software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.
  7. ]]
  8.  
  9. --[[
  10.     Autominer (for Meta Construct)
  11.     Created by NickServ
  12.     Version 3.2 (official)
  13.     ¡¡¡ CHANGE THE ABOVE TEXT IF YOU MODIFY THIS SCRIPT !!!
  14.    
  15.     This script works, but it's buggy and shittily written.
  16.     If you can improve it, please do!
  17.     (Still better code quality than most MPGH-tier cheats!)
  18.    
  19.     Changelog
  20.         Key
  21.             + Addition
  22.             - Removal
  23.             = Change
  24.             * Bug fix
  25.         Version 1
  26.             * Initial release.
  27.         Version 2
  28.             + The bot will now detect if you are dead and will automatically revive you.
  29.             + There is now help text in the main window.
  30.             = The panic message when trying to open the menu after vgui_cleanup is now clearer.
  31.             * You will no longer be stuck attacking or moving after quitting.
  32.         Version 3
  33.             + Will teleport back to mine when idle to make sure we're in bounds.
  34.             - No longer shows target entity class on HUD.
  35.             = Increased maximum range for attempting to mine.
  36.             = Help text now prints to console.
  37.             * Fixed the autominer command.
  38.             * Fixed a sentence in the help text.
  39.         Version 3.1
  40.             = Will no longer advertise if not enabled.
  41.             = Changed advert text slightly.
  42.             * Will now stop advertising if you quit the script.
  43.             * You will no longer be stuck attacking or moving after quitting. (Again)
  44.         Version 3.2
  45.             + Idiot check: Won't run if already running
  46.         Version 3.3
  47.             * Use print instead of MsgC for the help text.
  48. ]]
  49.  
  50. if AUTOMINER then
  51.     print("You can only run one instance of this script at a time! Remember, it's \"autominer\" to bring up the menu again and \"autominer_quit\" to unload the script.")
  52.     return
  53. end
  54.  
  55. AUTOMINER = true
  56.  
  57. local window = vgui.Create("DFrame")
  58. window:SetTitle("Autominer")
  59. window:SetDeleteOnClose(false)
  60. window:SetScreenLock(true)
  61. window:SetMinHeight(360/2)
  62. window:SetMinWidth(480/2)
  63. window:SetSizable(true)
  64. window:SetIcon("icon16/script.png")
  65. window:SetSize(360, 480)
  66. window:Center()
  67. window:MakePopup()
  68.  
  69. local panel = vgui.Create("DPanel", window)
  70. panel:DockMargin(0, 3, 0, 1)
  71. panel:DockPadding(3, 3, 3, 3)
  72. panel:Dock(FILL)
  73.  
  74. local quit = function()
  75.     timer.Destroy("Automine")
  76.     timer.Destroy("Automine_ad")
  77.     hook.Remove("Think", "Automine")
  78.     hook.Remove("HUDPaint", "Automine")
  79.     RunConsoleCommand("-attack")
  80.     RunConsoleCommand("-forward")
  81.     concommand.Remove("autominer")
  82.     concommand.Remove("autominer_quit")
  83.     if window then
  84.         window:SetDeleteOnClose(true)
  85.         window:Close()
  86.     end
  87.     AUTOMINER = false
  88.     print("The autominer has been quit. If you want to use it again, reload the script")
  89. end
  90.  
  91. local quit_button = vgui.Create("DButton", panel)
  92. quit_button:SetText("Quit")
  93. quit_button:Dock(TOP)
  94. quit_button.DoClick = quit
  95.  
  96. concommand.Add("autominer", function()
  97.     if window then
  98.         window:SetSizable(true)
  99.         window:Center()
  100.         window:MakePopup()
  101.         window:SetVisible(true)
  102.         -- what the FUCK why do i need to do this
  103.         -- if i don't do it the window doesn't come up
  104.     else
  105.         print("PANIC! The window could not be found and the autominer will now quit. Did you do vgui_cleanup?")
  106.         quit()
  107.     end
  108. end)
  109.  
  110. concommand.Add("autominer_quit", function()
  111.     quit()
  112. end)
  113.  
  114. local enabled = false
  115. local verbose = true
  116. local draw_bounding_boxes = true
  117. local advertise = true
  118.  
  119. local buyer = 1931
  120. local area_min = Vector(7509, 4030, -15904)
  121. local area_max = Vector(12248, -3355, -15084)
  122.  
  123. local me = LocalPlayer()
  124.  
  125. local classes = {
  126.     mining_ore = true,
  127.     mining_rock = true
  128. }
  129.  
  130. local old_print = print
  131. local print = function(...)
  132.     if verbose then
  133.         old_print(...)
  134.     end
  135. end
  136.  
  137. local set_noclip = function(bool)
  138.     --print("Setting noclip to "..tostring(bool))
  139.     local noclip = me:GetMoveType() == MOVETYPE_NOCLIP
  140.     if bool ~= noclip then
  141.         RunConsoleCommand("noclip")
  142.         noclip = bool
  143.     end
  144. end
  145. local attacking = false
  146. local set_attacking = function(bool)
  147.     local trace = util.QuickTrace(me:GetShootPos(), me:GetAngles():Forward()*100, me)
  148.     if trace.Entity and trace.Entity:IsPlayer() then
  149.         print("Player in the way! Refusing to attack")
  150.         bool = false
  151.     end
  152.     --print("Setting attacking to "..tostring(bool))
  153.     if bool ~= attacking then
  154.         if bool then
  155.             RunConsoleCommand("+attack")
  156.         else
  157.             RunConsoleCommand("-attack")
  158.         end
  159.         attacking = bool
  160.     end
  161. end
  162. local moving = false
  163. local set_moving = function(bool)
  164.     --print("Setting moving to "..tostring(bool))
  165.     if bool ~= moving then
  166.         if bool then
  167.             RunConsoleCommand("+forward")
  168.         else
  169.             RunConsoleCommand("-forward")
  170.         end
  171.         moving = bool
  172.     end
  173. end
  174. local mode
  175.  
  176. local ad_text = "NICKSERV'S  AUTOMINER  "
  177. local ad_text_len = #ad_text
  178. local ad_pos = 1
  179. timer.Create("Automine_ad", 0.5, 0, function()
  180.     if enabled and advertise and not me:IsTyping() then
  181.         rtchat.StartChat()
  182.         rtchat.ChatTextChanged(
  183.             string.sub(ad_text, ad_text_len-ad_pos, ad_text_len)..
  184.             string.sub(ad_text, 0, ad_text_len-ad_pos)
  185.         )
  186.         ad_pos = ad_pos-1
  187.         if ad_pos < 1 then
  188.             ad_pos = ad_text_len
  189.         end
  190.     end
  191. end)
  192.  
  193. timer.Create("Automine", 300, 0, function()
  194.     if enabled then
  195.         print("Beginning auto-sell")
  196.         enabled = false
  197.         set_attacking(false)
  198.         set_moving(false)
  199.         set_noclip(false)
  200.         mode = "Selling"
  201.         timer.Simple(0.5, function()
  202.             RunConsoleCommand("aowl", "goto", buyer)
  203.         end)
  204.         timer.Simple(1.0, function()
  205.             RunConsoleCommand("+use")
  206.         end)
  207.         timer.Simple(1.5, function()
  208.             RunConsoleCommand("-use")
  209.         end)
  210.         timer.Simple(2.0, function()
  211.             RunConsoleCommand("aowl", "goto", "mine")
  212.         end)
  213.         timer.Simple(2.5, function()
  214.             enabled = true
  215.         end)
  216.     else
  217.         print("Not enabled, not auto-selling")
  218.     end
  219. end)
  220. local candidate
  221. local candidate_pos
  222. local candidate_class
  223. local distance
  224. local teleported_back = false
  225. hook.Add("Think", "Automine", function()
  226.     if enabled then
  227.         if not me:Alive() then
  228.             RunConsoleCommand("aowl", "revive")
  229.             timer.Simple(1, function()
  230.                 input.SelectWeapon(me:GetWeapon("weapon_crowbar"))
  231.             end)
  232.             return
  233.         end
  234.        
  235.         local distance_from_candidate
  236.         local user_pos = me:GetShootPos()
  237.         for _, ent in pairs(ents.FindInBox(area_min, area_max)) do
  238.             local found = false
  239.             if not IsValid(ent) then continue end
  240.             --if ent == me then continue end
  241.             if ent:IsPlayer() then continue end
  242.             if not classes[ent:GetClass()] then continue end
  243.            
  244.             local ent_pos
  245.             local minimum, maximum = ent:GetModelBounds()
  246.             ent_pos = LerpVector(0.5, minimum, maximum)
  247.             ent_pos:Rotate(ent:GetAngles())
  248.             ent_pos:Add(ent:GetPos())
  249.            
  250.             local distance_from_ent = user_pos:DistToSqr(ent_pos)
  251.             if distance_from_candidate and distance_from_ent > distance_from_candidate then
  252.                 continue
  253.             end
  254.             candidate = ent
  255.             candidate_pos = ent_pos
  256.             candidate_class = ent:GetClass()
  257.             distance_from_candidate = distance_from_ent
  258.             distance = distance_from_candidate
  259.         end
  260.         if candidate_pos then
  261.             teleported_back = false
  262.             distance = user_pos:DistToSqr(candidate_pos)
  263.             local near = distance < 300
  264.             if near and not IsValid(candidate) then
  265.                 print("We've arrived at the rock but it seems to have vanished; ignoring it (we're probably just out of bounds)")
  266.                 candidate_pos = nil
  267.                 return
  268.             end
  269.             if candidate_class == "mining_rock" then
  270.                 set_attacking(true)
  271.                 set_moving(true)
  272.                 if near then
  273.                     mode = "Mining"
  274.                     set_noclip(false)
  275.                 else
  276.                     mode = "Going to rock"
  277.                     set_noclip(true)
  278.                 end
  279.             elseif candidate_class == "mining_ore" then
  280.                 mode = "Collecting ore"
  281.                 set_attacking(false)
  282.                 set_moving(true)
  283.                 set_noclip(true)
  284.             else
  285.                 mode = "!?"
  286.             end
  287.             me:SetEyeAngles( (candidate_pos - user_pos):Angle() )
  288.         else
  289.             if not teleported_back then
  290.                 mode = "Idle"
  291.                 set_attacking(false)
  292.                 set_moving(false)
  293.                 set_noclip(false)
  294.                 RunConsoleCommand("aowl", "goto", "mine")
  295.                 teleported_back = true
  296.             end
  297.         end
  298.     end
  299. end)
  300. local movetype = {
  301.     "Isometric",
  302.     "Walk",
  303.     "Step",
  304.     "Fly (No gravity)",
  305.     "Fly (Gravity)",
  306.     "Physics",
  307.     "Push",
  308.     "Noclip",
  309.     "Ladder",
  310.     "Spectator",
  311.     "Custom"
  312. }
  313. movetype[0] = "None"
  314. hook.Add("HUDPaint", "Automine", function()
  315.     local text = {
  316.         enabled and "Enabled" or "Disabled",
  317.         mode,
  318.         --candidate_class or "nil",
  319.         movetype[me:GetMoveType()],
  320.         distance and math.floor(distance) or "nil"
  321.     }
  322.     for i=1, #text do
  323.         local font
  324.         if i==1 then
  325.             font = "TargetID"
  326.         else
  327.             font = "TargetIDSmall"
  328.         end
  329.         draw.SimpleTextOutlined(
  330.             text[i],
  331.             font,
  332.             ScrW()/2,
  333.             ScrH()/2+12*i,
  334.             Color(255, 255, 255, 255),
  335.             TEXT_ALIGN_CENTER,
  336.             TEXT_ALIGN_TOP,
  337.             0,
  338.             Color(0, 0, 0, 255)
  339.         )
  340.     end
  341.     if draw_bounding_boxes then
  342.         cam.Start3D()
  343.             render.DrawWireframeBox(Vector(), Angle(), area_min, area_max, Color(255, 255, 255, 63))
  344.            
  345.             if IsValid(candidate) then
  346.                 local minimum, maximum = candidate:GetModelBounds()
  347.                 render.DrawWireframeBox(candidate:GetPos(), candidate:GetAngles(), minimum, maximum)
  348.             end
  349.         cam.End3D()
  350.     end
  351. end)
  352. if panel then
  353.     local enabled_checkbox = vgui.Create("DCheckBoxLabel", panel)
  354.     enabled_checkbox:SetValue(enabled)
  355.     enabled_checkbox:SetText("Enabled")
  356.     enabled_checkbox:SetDark(1)
  357.     enabled_checkbox.OnChange = function(_, state)
  358.         enabled = state
  359.         teleported_back = false
  360.         if not enabled then
  361.             set_attacking(false)
  362.             set_moving(false)
  363.             set_noclip(false)
  364.         end
  365.     end
  366.     enabled_checkbox:DockMargin(0, 3, 0, 0)
  367.     enabled_checkbox:Dock(TOP)
  368.    
  369.     local verbose_checkbox = vgui.Create("DCheckBoxLabel", panel)
  370.     verbose_checkbox:SetValue(verbose)
  371.     verbose_checkbox:SetText("Verbose")
  372.     verbose_checkbox:SetDark(1)
  373.     verbose_checkbox.OnChange = function(_, state)
  374.         verbose = state
  375.     end
  376.     verbose_checkbox:DockMargin(0, 3, 0, 0)
  377.     verbose_checkbox:Dock(TOP)
  378.    
  379.     local boxes_checkbox = vgui.Create("DCheckBoxLabel", panel)
  380.     boxes_checkbox:SetValue(draw_bounding_boxes)
  381.     boxes_checkbox:SetText("Draw bounding boxes")
  382.     boxes_checkbox:SetDark(1)
  383.     boxes_checkbox.OnChange = function(_, state)
  384.         draw_bounding_boxes = state
  385.     end
  386.     boxes_checkbox:DockMargin(0, 3, 0, 0)
  387.     boxes_checkbox:Dock(TOP)
  388.    
  389.     local ad_checkbox = vgui.Create("DCheckBoxLabel", panel)
  390.     ad_checkbox:SetValue(advertise)
  391.     ad_checkbox:SetText("Advertise")
  392.     ad_checkbox:SetTooltip('Displays "'..ad_text..'" above your head in the form of an rtchat marquee. Won\'t display when typing in chat.')
  393.     ad_checkbox:SetDark(1)
  394.     ad_checkbox.OnChange = function(_, state)
  395.         advertise = state
  396.     end
  397.     ad_checkbox:DockMargin(0, 3, 0, 0)
  398.     ad_checkbox:Dock(TOP)
  399.    
  400.     local buyer_cluster = vgui.Create("DPanel", panel)
  401.     buyer_cluster:SetPaintBackground(false)
  402.     buyer_cluster:Dock(TOP)
  403.    
  404.     local buyer_entry = vgui.Create("DNumberWang", buyer_cluster)
  405.     buyer_entry:SetMin(1)
  406.     buyer_entry:SetMax(32000)
  407.     buyer_entry:SetValue(buyer)
  408.     buyer_entry.OnValueChanged = function(_, value)
  409.         print("Changed buyer index to ", value)
  410.         buyer = tonumber(value)
  411.     end
  412.     buyer_entry:Dock(LEFT)
  413.    
  414.     local buyer_label = vgui.Create("DLabel", buyer_cluster)
  415.     buyer_label:SetDark(1)
  416.     buyer_label:SetText("Buyer EntIndex")
  417.     buyer_label:Dock(3, 3, 3, 0)
  418.     buyer_label:Dock(FILL)
  419.    
  420.     local help_text = vgui.Create("RichText", panel)
  421.     help_text:Dock(0, 3, 0, 0)
  422.     help_text:Dock(FILL)
  423.    
  424.     local text = {
  425.         false,
  426.         "Welcome to my autominer. You must follow my instructions to use this bot effectively.",
  427.         "• Go to the woman who collects the ore, look directly at her and type the following in chat:",
  428.         true,
  429.         "\t/lm Say(this:EntIndex())",
  430.         false,
  431.         "You will say a number in the chat. Put that number exactly as it is into the 'Buyer EntIndex' box. It may change if the server restarts or you reconnect.",
  432.         "• Enter the mine and equip your crowbar. Make sure you're in god mode. When you have done these two things, check the 'Enabled' box.",
  433.         "• You may use the console and chat while the bot is running, but you should not attempt to change weapons, look around, or move. If you want to do something else, uncheck the 'Enabled' box.",
  434.         "• When you are done with the autominer, click the 'Quit' button. You will need to reload the script to use the autominer again.",
  435.         "• To bring up this menu again, type 'autominer' in the console or say '/cmd autominer' in chat."
  436.     }
  437.     for i=1, #text do
  438.         if text[i] == true then
  439.             help_text:InsertColorChange(255, 0, 0, 255)
  440.         elseif text[i] == false then
  441.             help_text:InsertColorChange(0, 0, 0, 255)
  442.         else
  443.             print(text[i], "\n")
  444.             help_text:AppendText(text[i].."\n")
  445.         end
  446.     end
  447. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement