Advertisement
ustinjamesss

OP

May 19th, 2022
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.01 KB | None | 0 0
  1. --[[
  2.  
  3. Gas Station Simulator Autofarm
  4.  
  5. Made by TheSynapseGuy on V3rm ( SomethingElse#0024 on discord )
  6. Last tested for V1.0.2c
  7.  
  8. Default kebyinds
  9. P - Auto refuel
  10. L - Auto cashier
  11. M - Auto clean
  12. Z - Auto restock - restock works by detecting when a item is taken and replaces it
  13.  
  14. VV Settings below VV
  15. ]]
  16.  
  17. local TravelSpeed = 20 -- going too fast might get you kicked
  18.  
  19. local ToggleFuelKey = Enum.KeyCode.P
  20. local ToggleCleanKey = Enum.KeyCode.M
  21. local ToggleCashierKey = Enum.KeyCode.L
  22. local ToggleRestockKey = Enum.KeyCode.Z
  23.  
  24. local AllowFuelBuy = true -- For auto refuel
  25. local AllowItemsBuy = true -- For auto restocking
  26.  
  27. local MoneySource = "Station" -- Choose "Station" or "Client"
  28. local AllowSecondarySource = true
  29. local SecondaryMoneySource = "Client" -- If Primary Money source does not have enough it will use this
  30. local AllowStationSpendingDuringBankruptcy = false -- If enabled it allows the bot to purchase using station money even when near bankruptcy
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. -- Ignore everything below here
  38. local GasEnabled = false
  39. local CleaningEnabled = false
  40. local RestockEnabled = false
  41. local CashierEnabled = false
  42. local ItemRestockQueue = {}
  43. local ReplicatedStorage = game:GetService("ReplicatedStorage"); local Players = game:GetService("Players"); local LocalPlayer = Players.LocalPlayer; local RunService = game:GetService("RunService")
  44. local ActionRemote = ReplicatedStorage:WaitForChild("Remote")
  45. local PumpsFolder = workspace:WaitForChild("Pumps")
  46. local StorageFolder = workspace:WaitForChild("Storage")
  47. local ShelvesFolder = workspace:WaitForChild("Shelves")
  48. local StatsHolder = require(ReplicatedStorage:WaitForChild("StatHolder"))
  49. local InputService = game:GetService("UserInputService")
  50. local TweenService = game:GetService("TweenService")
  51.  
  52. local function GetPlayerCharacter() return LocalPlayer.Character or LocalPlayer.CharacterAdded:wait(); end
  53. local function GetStoreGasoline() return PumpsFolder:GetAttribute("Gasoline"); end
  54. local function GetMoneyOfSource(Source : StringValue) if Source == "Station" then return workspace.Station:GetAttribute("Money") elseif Source == "Client" then return LocalPlayer:GetAttribute("Money") end end
  55. local function FindItemCatergory(ItemName : StringValue)
  56. local ShopTable = StatsHolder.Shops
  57. for FirstName,FirstCatergory in pairs(ShopTable) do
  58. if FirstCatergory ~= "Syntin Petrol Co" then
  59. for SecondName,SecondCatergory in pairs(FirstCatergory) do
  60. if SecondCatergory[ItemName] ~= nil then
  61. return {
  62. ["Item"] = ItemName,
  63. ["ItemProvider"] = FirstName,
  64. ["ItemCatergory"] = SecondName,
  65. ["ItemPrice"] = SecondCatergory[ItemName][2]
  66. }
  67. end
  68. end
  69. end
  70. end
  71. end
  72. local function DecideSource(MinimumMoneyNeeded : IntValue)
  73. local PrimarySourceMoney = GetMoneyOfSource(MoneySource)
  74. if MoneySource == "Client" then
  75. if PrimarySourceMoney >= MinimumMoneyNeeded then
  76. return MoneySource
  77. end
  78. else
  79. local StationBankrupt = not (workspace.Station:GetAttribute("Money") > workspace.Station:GetAttribute("EstBills"))
  80. if (StationBankrupt and AllowStationSpendingDuringBankruptcy) or (not StationBankrupt) then
  81. if LocalPlayer:GetAttribute("Contributions") >= MinimumMoneyNeeded then
  82. if #game.Teams.Manager:GetPlayers() > 0 then
  83. if LocalPlayer.Team == game.Teams.Manager then
  84. return MoneySource
  85. end
  86. else
  87. return MoneySource
  88. end
  89. end
  90. end
  91. end
  92. if AllowSecondarySource then
  93. local SecondarySourceMoney = GetMoneyOfSource(SecondaryMoneySource)
  94. if SecondaryMoneySource == "Client" then
  95. if SecondarySourceMoney >= MinimumMoneyNeeded then
  96. return SecondaryMoneySource
  97. end
  98. else
  99. local StationBankrupt = not (workspace.Station:GetAttribute("Money") > workspace.Station:GetAttribute("EstBills"))
  100. if (StationBankrupt and AllowStationSpendingDuringBankruptcy) or (not StationBankrupt) then
  101. if LocalPlayer:GetAttribute("Contributions") >= MinimumMoneyNeeded then
  102. if #game.Teams.Manager:GetPlayers() > 0 then
  103. if LocalPlayer.Team == game.Teams.Manager then
  104. return SecondaryMoneySource
  105. end
  106. else
  107. return SecondaryMoneySource
  108. end
  109. end
  110. end
  111. end
  112. end
  113. return MoneySource
  114. end
  115. local function BuyFuel()
  116. ActionRemote:FireServer("BuyItem","Syntin Petrol Co","Gasoline 87", 1,DecideSource(9));
  117. end
  118. local function GetPlayerStamina() return LocalPlayer:GetAttribute("Stamina"); end
  119.  
  120. if _G.dAAcG3fvBqVoPzVnAFk == nil then _G.dAAcG3fvBqVoPzVnAFk = "" end function notify(a,b,c)local d=c or function()return end;local e=b or false;if a==_G.dAAcG3fvBqVoPzVnAFk and e==false then return end;spawn(function()for f,g in pairs(game.CoreGui:GetChildren())do spawn(function()if g.Name=="MNotify"then pcall(function()g.ImageButton.ZIndex=58;g.ImageButton.TextLabel.ZIndex=59;g.ImageButton:TweenPosition(UDim2.new(0.01,0,1,0),"Out","Quint",.7,true)game:GetService("TweenService"):Create(g.ImageButton.TextLabel,TweenInfo.new(0.8,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0),{TextTransparency=1})wait(1)g:Destroy()end)end end)end;_G.dAAcG3fvBqVoPzVnAFk=a;local d=c or function()return end;local function h(i,j)local k=Instance.new(i)for f,g in pairs(j)do k[f]=g end;return k end;local l=h('ScreenGui',{DisplayOrder=0,Enabled=true,ResetOnSpawn=true,Name='MNotify',Parent=game.CoreGui})local m=h('ImageButton',{Image='rbxassetid://1051186612',ImageColor3=Color3.new(0.129412,0.129412,0.129412),ImageRectOffset=Vector2.new(0,0),ImageRectSize=Vector2.new(0,0),ImageTransparency=0,ScaleType=Enum.ScaleType.Slice,SliceCenter=Rect.new(20,20,20,20),AutoButtonColor=true,Modal=false,Selected=false,Style=Enum.ButtonStyle.Custom,Active=true,AnchorPoint=Vector2.new(0,0),BackgroundColor3=Color3.new(1,1,1),BackgroundTransparency=1,BorderColor3=Color3.new(0.105882,0.164706,0.207843),BorderSizePixel=1,ClipsDescendants=false,Draggable=false,Position=UDim2.new(0.00999999978,0,1,0),Rotation=0,Selectable=true,Size=UDim2.new(0,234,0,40),SizeConstraint=Enum.SizeConstraint.RelativeXY,Visible=true,ZIndex=60,Name='ImageButton',Parent=l})local n=h('TextLabel',{Font=Enum.Font.SourceSansLight,FontSize=Enum.FontSize.Size24,Text=a,TextColor3=Color3.new(0.807843,0.807843,0.807843),TextScaled=false,TextSize=24,TextStrokeColor3=Color3.new(0,0,0),TextStrokeTransparency=1,TextTransparency=0,TextWrapped=false,TextXAlignment=Enum.TextXAlignment.Center,TextYAlignment=Enum.TextYAlignment.Center,Active=false,AnchorPoint=Vector2.new(0,0),BackgroundColor3=Color3.new(1,1,1),BackgroundTransparency=1,BorderColor3=Color3.new(0.105882,0.164706,0.207843),BorderSizePixel=1,ClipsDescendants=false,Draggable=false,Position=UDim2.new(0.132478639,0,0,0),Rotation=0,Selectable=false,Size=UDim2.new(0,174,0,40),SizeConstraint=Enum.SizeConstraint.RelativeXY,Visible=true,ZIndex=61,Name='TextLabel',Parent=m})local o=h('UIListLayout',{Padding=UDim.new(0,0),FillDirection=Enum.FillDirection.Vertical,HorizontalAlignment=Enum.HorizontalAlignment.Center,SortOrder=Enum.SortOrder.Name,VerticalAlignment=Enum.VerticalAlignment.Top,Name='UIListLayout',Parent=m})local p=1;if string.len(a)<=49 then m.Size=UDim2.new(0,game:GetService("TextService"):GetTextSize(a,24,Enum.Font.SourceSansLight,Vector2.new(500,900)).X+57,0,40)elseif string.len(a)>49 then p=math.ceil(string.len(string.sub(a,49))/9)m.Size=UDim2.new(0,game:GetService("TextService"):GetTextSize(a,24,Enum.Font.SourceSansLight,Vector2.new(500+p*100,900)).X+57,0,40)end;m:TweenPosition(UDim2.new(0.01,0,1,-60),"Out","Quint",.7,true)spawn(function()wait(6.7)pcall(function()m.ZIndex=58;n.ZIndex=59;m:TweenPosition(UDim2.new(0.01,0,1,0),"Out","Quint",.7,true)_G.dAAcG3fvBqVoPzVnAFk=""wait(1)l:Destroy()end)end)m.MouseButton1Up:Connect(function()if c==nil then return end;spawn(function()pcall(function()m.ZIndex=58;n.ZIndex=59;m:TweenPosition(UDim2.new(0.01,0,1,0),"Out","Quint",.7,true)_G.dAAcG3fvBqVoPzVnAFk=""wait(1)l:Destroy()end)end)d()end)end)end
  121. function roundNumber(num, numDecimalPlaces) -- https://devforum.roblox.com/t/rounding-to-1-decimal-point/673504
  122. return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
  123. end
  124.  
  125. local function TravelToCFrame(TargetCFrame : CFrame)
  126. local PlayerCharacter = GetPlayerCharacter()
  127. if PlayerCharacter then
  128. local DistanceBetweenPoints = ( PlayerCharacter.HumanoidRootPart.Position - TargetCFrame.Position ).Magnitude
  129. local TimeNeeded = roundNumber(DistanceBetweenPoints / TravelSpeed, 3)
  130. local Tween = TweenService:Create(
  131. PlayerCharacter.HumanoidRootPart,
  132. TweenInfo.new(
  133. TimeNeeded,
  134. Enum.EasingStyle.Linear,
  135. Enum.EasingDirection.Out
  136. ),
  137. {
  138. CFrame = TargetCFrame
  139. }
  140. )
  141. Tween:Play()
  142. task.wait(TimeNeeded)
  143. end
  144. end
  145.  
  146. local function RestoreEnergy(MinimumEnergy : IntValue)
  147. notify("Resting",true)
  148. local PlayerCharacter = GetPlayerCharacter()
  149. local PreviousCFrame = PlayerCharacter.HumanoidRootPart.CFrame
  150. TravelToCFrame(workspace.Ceilings.Sofa.Seat.CFrame)
  151. task.wait(2)
  152. while true do
  153. if GetPlayerStamina() >= MinimumEnergy then
  154. break
  155. end
  156. task.wait(0.5)
  157. end
  158. PlayerCharacter.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  159. TravelToCFrame(PreviousCFrame)
  160. end
  161.  
  162. local function FindPumpToCar(CarModel : Instance)
  163. local CarPosition = CarModel.PrimaryPart.Position
  164. local Pump
  165. local PumpDistance = 999
  166. for _,v in pairs(PumpsFolder:GetChildren()) do
  167. local DistanceBetweenPump = (CarPosition - v.Screen.Position).Magnitude
  168. if DistanceBetweenPump < PumpDistance then
  169. Pump = v
  170. PumpDistance = DistanceBetweenPump
  171. end
  172. end
  173. return Pump
  174. end
  175.  
  176. local function DoesPumpNeedToBeTakenOut(CarModel : Instance)
  177. if CarModel:FindFirstChild("Lid") then
  178. if CarModel.Lid:FindFirstChild("FinishFuel") then
  179. return true
  180. end
  181. end
  182. return false
  183. end
  184.  
  185. local function RefuelCar(CarModel : Instance)
  186. local CarPump = FindPumpToCar(CarModel)
  187. if DoesPumpNeedToBeTakenOut(CarModel) then
  188. TravelToCFrame(CarModel.Lid.CFrame)
  189. ActionRemote:FireServer("FinishFuel", CarModel, CarPump)
  190. return
  191. end
  192. if CarModel:GetAttribute("IsRefueld") or CarModel:GetAttribute("IsRefilling") then return end
  193. local RequiredFuel = CarModel:GetAttribute("RequiredFuel")
  194. local TotalAttempts = 0
  195. if AllowFuelBuy then
  196. while true do
  197. TotalAttempts += 1
  198. local StoreFuel = GetStoreGasoline()
  199. if StoreFuel >= RequiredFuel then
  200. break
  201. end
  202. notify("Attempting to buy 15L of fuel",true)
  203. BuyFuel()
  204. task.wait(1)
  205. if TotalAttempts > 10 then
  206. break
  207. end
  208. end
  209. end
  210. if GetPlayerStamina() < 5 then
  211. RestoreEnergy(95)
  212. end
  213. local StoreFuel = GetStoreGasoline()
  214. if StoreFuel >= RequiredFuel then
  215. if CarModel.Lid:FindFirstChild("Refuel") then
  216. TravelToCFrame(CarModel.Lid.CFrame)
  217. notify("Refilling "..CarModel.Name,true)
  218. ActionRemote:FireServer("FuelCustomer", CarModel, CarPump)
  219. task.wait(4)
  220. end
  221. end
  222. end
  223. local PreviousItem
  224. local function ScanItem(Item : Instance, CashierModel : Instance)
  225. if GetPlayerStamina() < 5 then
  226. RestoreEnergy(95)
  227. end
  228. if Item ~= PreviousItem then
  229. local DistanceFromItem = ( Item.Root.Position - GetPlayerCharacter().HumanoidRootPart.Position ).Magnitude
  230. if DistanceFromItem > 10 then
  231. notify("Too far away from cash register",true)
  232. TravelToCFrame(CFrame.new(1.46752572, 3, -6.53523779, 0.726744831, -4.74023416e-08, 0.68690753, 9.53963948e-08, 1, -3.19205924e-08, -0.68690753, 8.87266296e-08, 0.726744831))
  233. end
  234. if Item.Root:FindFirstChild("Scan") then
  235. if Item.Root:FindFirstChild("Scan").Enabled then
  236. if not CashierModel:GetAttribute("InUse") then
  237. notify("Scanning "..Item.Name,true)
  238. ActionRemote:FireServer("ScanItem",Item,CashierModel)
  239. Item.Root:FindFirstChild("Scan").Enabled = false
  240. PreviousItem = Item
  241. task.wait(3)
  242. end
  243. end
  244. end
  245. end
  246. end
  247. InputService.InputBegan:Connect(function(input, gameProcessedEvent)
  248. if not gameProcessedEvent then
  249. if input.KeyCode == ToggleFuelKey then
  250. GasEnabled = not GasEnabled
  251. notify("Fuel enabled: "..tostring(GasEnabled),true)
  252. end
  253. if input.KeyCode == ToggleCashierKey then
  254. CashierEnabled = not CashierEnabled
  255. notify("Cashier enabled: "..tostring(CashierEnabled),true)
  256. end
  257. if input.KeyCode == ToggleCleanKey then
  258. CleaningEnabled = not CleaningEnabled
  259. notify("Cleaning enabled: "..tostring(CleaningEnabled),true)
  260. end
  261. if input.KeyCode == ToggleRestockKey then
  262. RestockEnabled = not RestockEnabled
  263. notify("Restocking enabled: "..tostring(RestockEnabled),true)
  264. if not RestockEnabled then
  265. ItemRestockQueue = {}
  266. end
  267. end
  268. end
  269. end)
  270.  
  271. local function ItemRemoved(Item : Instance, Shelf : Instance)
  272. if RestockEnabled then
  273. table.insert(ItemRestockQueue,{
  274. ["ItemShelf"] = Shelf,
  275. ["ItemType"] = Item.Name,
  276. ["ItemCFrame"] = Item.PrimaryPart.CFrame - Vector3.new(0,Item.PrimaryPart.Size.Y/2,0)
  277. })
  278. end
  279. end
  280. local function NewShelfAdded(shelf : Instance)
  281. if shelf:FindFirstChild("Content") then
  282. shelf.Content.ChildRemoved:connect(function(Item)
  283. ItemRemoved(Item,shelf)
  284. end)
  285. end
  286. end
  287.  
  288. for _,v in pairs(ShelvesFolder:GetChildren()) do
  289. NewShelfAdded(v)
  290. end
  291. ShelvesFolder.ChildAdded:Connect(NewShelfAdded)
  292.  
  293. while true do
  294. task.wait(0.1)
  295. if GasEnabled then
  296. pcall(function()
  297. for _,v in pairs(workspace:GetChildren()) do
  298. if v.Name:sub(1,4) == "Car_" then
  299. RefuelCar(v)
  300. task.wait(1)
  301. end
  302. end
  303. end)
  304. end
  305. if CashierEnabled then
  306. pcall(function()
  307. for _,v in pairs(workspace.Checkouts:GetChildren()) do
  308. for _,h in pairs(v.Items:GetChildren()) do
  309. ScanItem(h,v)
  310. end
  311. end
  312. end)
  313. end
  314. if CleaningEnabled then
  315. pcall(function()
  316. if GetPlayerStamina() < 5 then
  317. RestoreEnergy(95)
  318. end
  319. for _,v in pairs(workspace.Windows:GetChildren()) do
  320. if v:FindFirstChild("Attachment") then
  321. if v.Attachment.Clean.Enabled then
  322. notify("Cleaning window",true)
  323. TravelToCFrame(v.CFrame)
  324. ActionRemote:FireServer("Clean",v.Attachment.Clean)
  325. task.wait(4)
  326. end
  327. end
  328. end
  329. for _,v in pairs(workspace:GetChildren()) do
  330. if v.Name == "Spot" then
  331. notify("Cleaning spot")
  332. TravelToCFrame(v.CFrame + Vector3.new(0,3,0))
  333. ActionRemote:FireServer("Clean",v.Clean)
  334. task.wait(1)
  335. end
  336. end
  337. end)
  338. end
  339. if RestockEnabled then
  340. pcall(function()
  341. if #ItemRestockQueue >= 1 then
  342. local ItemRestockQueueCache = ItemRestockQueue
  343. ItemRestockQueue = {}
  344. for _, iteminfo in pairs(ItemRestockQueueCache) do
  345. if GetPlayerStamina() < 5 then
  346. RestoreEnergy(95)
  347. end
  348. if StorageFolder:FindFirstChild(iteminfo["ItemType"]) then
  349. local RemainingItems = StorageFolder:FindFirstChild(iteminfo["ItemType"]):GetAttribute("Storage")
  350. if RemainingItems <= 0 then
  351. if AllowItemsBuy then
  352. ItemShopInfo = FindItemCatergory(iteminfo["ItemType"])
  353. local Attempts = 0
  354. while true do
  355. Attempts += 1
  356. RemainingItems = StorageFolder:FindFirstChild(iteminfo["ItemType"]):GetAttribute("Storage")
  357. if RemainingItems > 0 then
  358. break
  359. end
  360. if Attempts > 5 then
  361. break
  362. end
  363. notify("Attempting to buy "..iteminfo["ItemType"],true)
  364. ActionRemote:FireServer("BuyItem",ItemShopInfo["ItemProvider"],ItemShopInfo["ItemCatergory"], iteminfo["ItemType"],DecideSource(ItemShopInfo["ItemPrice"]));
  365. task.wait(1.5)
  366. end
  367. end
  368. end
  369. RemainingItems = StorageFolder:FindFirstChild(iteminfo["ItemType"]):GetAttribute("Storage")
  370. if RemainingItems > 0 then
  371. --TravelToCFrame(iteminfo["ItemShelf"].PrimaryPart.CFrame) not really needed
  372. ActionRemote:FireServer("PlaceProduct",iteminfo["ItemType"],iteminfo["ItemCFrame"])
  373. notify("Restocked "..iteminfo["ItemType"],true)
  374. else
  375. notify("Failed to restock "..iteminfo["ItemType"]..", not enough stock",true)
  376. end
  377. end
  378. end
  379. end
  380. end)
  381. end
  382. end
  383.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement