w9s66v09c8x5o1fl3p0

Rifbot Food Eater

Jan 11th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.36 KB | None | 0 0
  1. --[[
  2.     Script Name:        Food Eater
  3.     Description:        Eat food in game..
  4.     Author:             Ascer - example
  5. ]]
  6.  
  7. local MAIN_DELAY = {4, 9}          -- mintues between run antiidle function.
  8. local USE_DELAY = {200, 650}       -- miliseconds between use action.
  9. local USE_TRIES = {4, 7}           -- amount of times to use .
  10.  
  11. local FOOD = {                     -- add your id if need.
  12.     836, 841, 901, 904, 3577, 3578, 3579, 3580, 3581, 3582, 3583, 3584, 3585, 3586, 3587, 3588, 3589,
  13.     3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599, 3600, 3601, 3602, 3606, 3607, 3723,
  14.     3724, 3725, 3726, 3728, 3729, 3730, 3731, 3732, 5096, 5678, 6125, 6277, 6278, 6392, 6500, 6541,
  15.     6542, 6543, 6544, 6545, 6569, 6574, 7158, 7159, 7372, 7373, 7375, 8010, 8011, 8012, 8013, 8014,
  16.     8015, 8017, 8019, 8177, 8197, 10329, 12310, 14085, 17457, 17820, 17821, 21143, 21144, 21146
  17. }
  18.  
  19.  
  20. -- DONT'T EDIT BELOW THIS LINE
  21.  
  22. local mainTime, useTime, mainDelay, useDelay, tries, useTries = 0, 0, 0, 0, 0, 0
  23.  
  24.  
  25. ----------------------------------------------------------------------------------------------
  26. --> Function:        findFood(foods)
  27. --> Description:     Check equipment and containers for food.
  28. --> Params:          
  29. -->                  @foods - number or table with id of food.
  30. --> Returns:         number id of item or 0
  31. ----------------------------------------------------------------------------------------------
  32. function findFood(foods)
  33.     if type(foods) ~= "table" then -- create table if not.
  34.         foods = {foods}
  35.     end
  36.    
  37.     local eq = {
  38.         Self.Weapon(),   -- slots in eq
  39.         Self.Shield(),
  40.         Self.Ammo()
  41.     }
  42.    
  43.     for i = 1, #eq do -- check for id in equipment
  44.         local item = eq[i]
  45.         if table.find(foods, item.id) then
  46.             return item.id
  47.         end    
  48.     end
  49.  
  50.     local items = Container.getItems() -- load all items in containers
  51.     for i = 1, #items do
  52.         local container = items[i]
  53.         local contItems = container.items
  54.         for slot = 1, #contItems do
  55.             local item = contItems[slot]
  56.             if table.find(foods, item.id) then
  57.                 return item.id
  58.             end
  59.         end
  60.     end
  61.    
  62.     return 0 -- return 0 (food not found)              
  63. end
  64.  
  65. -- mod to run functions
  66. Module.New("Eat Food", function (mod)
  67.     if (os.clock() - mainTime) >= mainDelay then -- check for main func time
  68.         if useTries <= 0 then
  69.             useTries = math.random(USE_TRIES[1], USE_TRIES[2]) -- set random tries
  70.         else
  71.             if (os.clock() - useTime) >= useDelay and Self.isConnected() then -- check for time and connection
  72.                 local food = findFood(FOOD)
  73.                 if food > 0 then -- use only if food found, delay set default for release loop reading items.
  74.                     selfUseItem(food, false, 0)
  75.                 end    
  76.                 useTime = os.clock()
  77.                 useDelay = math.random(USE_DELAY[1], USE_DELAY[2])/1000
  78.                 tries = tries + 1
  79.                 if tries >= useTries then
  80.                     tries = 0
  81.                     useTries = 0
  82.                     mainTime = os.clock()
  83.                     mainDelay = math.random(MAIN_DELAY[1] * 60, MAIN_DELAY[2] * 60)
  84.                 end
  85.             end
  86.         end
  87.     end                    
  88.     mod:Delay(200, 350)
  89. end)
Add Comment
Please, Sign In to add comment