Advertisement
glitchdetector

Tycoon Net Fishing Zones

Sep 2nd, 2018
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.96 KB | None | 0 0
  1. local alamo_tug_fish = {
  2.     "fish_salmon",
  3.     "fish_mackerel",
  4.     "fish_trout",
  5. }
  6.  
  7. local tugging_locations = {
  8.     {id = "AS_01", name = "Alamo Sea", x = 2088.3854980469, y = 4279.0024414063, z = 30.0, capacity = 100, current = 0, size = 250.0, bonuses = {}, itemset = alamo_tug_fish},
  9. }
  10.  
  11. local WITHIN_ZONE = false
  12. local CURRENT_ZONE = nil
  13.  
  14. function GiveFishFromSet(location, min, max)
  15.     local itemset = location.itemset
  16.     local item = itemset[math.random(#itemset)]
  17.     local amount = math.random(min, max)
  18.     if amount > 0 then
  19.         -- Code to give items
  20.         TriggerEvent("gd_utils:notify", "Got " .. amount .. "x " .. item)
  21.     end
  22. end
  23.  
  24. -- Main Loop
  25. Citizen.CreateThread(function()
  26.     while true do
  27.         Wait(0)
  28.         local ped = GetPlayerPed(-1)
  29.         WITHIN_ZONE = false
  30.         CURRENT_ZONE = nil
  31.         if IsVehicleModel(GetVehiclePedIsIn(ped, false), "TUG") then
  32.             local pos = GetEntityCoords(ped, false)
  33.             for _, location in next, tugging_locations do
  34.                 if not location.world_blip then
  35.                     local blip = AddBlipForCoord(location.x, location.y, location.z)
  36.                     SetBlipSprite(blip, 400)
  37.                     SetBlipColour(blip, 25)
  38.                     SetBlipAsShortRange(blip, true)
  39.                     exports['omni_common']:SetBlipName(blip, "Net Fishing Zone")
  40.                     location.world_blip = blip
  41.                 end
  42.                 if not WITHIN_ZONE then
  43.                     -- Check if we are within the fishing area
  44.                     local dist = #(vector3(location.x, location.y, location.z) - pos)
  45.                     if dist < location.size + 150.0 then
  46.                         -- Within a fishing area
  47.                         DrawMarker(1, location.x, location.y, location.z, 0, 0, 0, 0, 0, 0, location.size * 2, location.size * 2, 2.0, 255, 255, 255, 255)
  48.  
  49.                         -- Make the radius blip if no present
  50.                         if not location.blip then
  51.                             local blip = AddBlipForRadius(location.x, location.y, location.z, location.size)
  52.                             SetBlipAlpha(blip, 150)
  53.                             SetBlipColour(blip, 25)
  54.                             location.blip = blip
  55.                         end
  56.  
  57.                         -- Check if we are within the zone itself
  58.                         if dist < location.size then
  59.                             -- Within the fishing zone
  60.  
  61.                             -- Mark as current zone (for fishing generator and bonus generator)
  62.                             WITHIN_ZONE = true
  63.                             CURRENT_ZONE = location
  64.  
  65.                             -- Check and draw bonuses
  66.                             for _bonus_id, bonus in next, location.bonuses do
  67.                                 -- Create bonus blip if not present
  68.                                 if not bonus.blip then
  69.                                     local blip = AddBlipForCoord(bonus.x, bonus.y, location.z)
  70.                                     exports['omni_common']:SetBlipName(blip, "Net Fishing Bonus")
  71.                                     bonus.blip = blip
  72.                                 end
  73.                                 -- Draw Marker on water (fancy!!)
  74.                                 local _, h = GetWaterHeight(bonus.x, bonus.y, 100.0)
  75.                                 DrawMarker(1, bonus.x, bonus.y, h, 0, 0, 0, 0, 0, 0, bonus.size * 2, bonus.size * 2, 2.0, 255, 255, 255, 255)
  76.  
  77.                                 -- Check distance
  78.                                 local dist = #(vector3(bonus.x, bonus.y, location.z) - pos)
  79.                                 if dist < bonus.size then
  80.                                     RemoveBlip(bonus.blip)
  81.                                     bonus.blip = nil
  82.                                     GiveFishFromSet(location, 3, 8)
  83.                                     table.remove(location.bonuses, _bonus_id)
  84.                                 end
  85.                             end
  86.                         end
  87.                     else
  88.                         -- Not within a fishing area
  89.  
  90.                         -- Remove area blip
  91.                         if location.blip then
  92.                             RemoveBlip(location.blip)
  93.                             location.blip = nil
  94.                         end
  95.                         -- Remove bonus blips
  96.                         for _, bonus in next, location.bonuses do
  97.                             if bonus.blip then
  98.                                 RemoveBlip(bonus.blip)
  99.                                 bonus.blip = nil
  100.                             end
  101.                         end
  102.                     end
  103.                 end
  104.             end
  105.         else
  106.             -- Not in a tug
  107.             -- Remove blips
  108.             for _, location in next, tugging_locations do
  109.                 if location.world_blip then
  110.                     RemoveBlip(location.world_blip)
  111.                     location.world_blip = nil
  112.                 end
  113.                 if location.blip then
  114.                     RemoveBlip(location.blip)
  115.                     location.blip = nil
  116.                 end
  117.                 for _, bonus in next, location.bonuses do
  118.                     if bonus.blip then
  119.                         RemoveBlip(bonus.blip)
  120.                         bonus.blip = nil
  121.                     end
  122.                 end
  123.             end
  124.         end
  125.     end
  126. end)
  127.  
  128. -- Fish Generator Loop
  129. local last_pos = vector3(0.0, 0.0, 0.0)
  130. Citizen.CreateThread(function()
  131.     while true do
  132.         Wait(2500)
  133.         local ped = GetPlayerPed(-1)
  134.         if WITHIN_ZONE then
  135.             local pos = GetEntityCoords(ped, false)
  136.             local dist = #(pos - last_pos)
  137.             if dist > 55.0 then
  138.                 last_pos = pos
  139.                 -- Make me a fish
  140.                 -- INSERT CODE TO GIVE FISHES
  141.                 GiveFishFromSet(CURRENT_ZONE, -2, 2)
  142.             end
  143.         end
  144.     end
  145. end)
  146.  
  147. -- Bonus Generator Loop
  148. local bonus_wait_time = 35 * 1000
  149. Citizen.CreateThread(function()
  150.     while true do
  151.         if WITHIN_ZONE then
  152.             local zone = CURRENT_ZONE
  153.             local bonus = {}
  154.             -- Make sure the position is never outside the zone
  155.             local function gen()
  156.                 bonus.x = zone.x + math.random(-zone.size, zone.size)
  157.                 bonus.y = zone.y + math.random(-zone.size, zone.size)
  158.                 local dist = #(vector3(bonus.x, bonus.y, 0.0) - vector3(zone.x, zone.y, 0.0))
  159.                 if dist > zone.size then
  160.                     gen()
  161.                 end
  162.             end
  163.             gen()
  164.             bonus.size = 8.0
  165.             table.insert(zone.bonuses, bonus)
  166.             if #zone.bonuses > 5 then
  167.                 if zone.bonuses[1].blip then
  168.                     RemoveBlip(zone.bonuses[1].blip)
  169.                 end
  170.                 table.remove(zone.bonuses, 1)
  171.             end
  172.         end
  173.         Wait(bonus_wait_time)
  174.     end
  175. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement