--time delay after a fail/successful catch before next fishing attempt starts local fishing_delay = 1000 --how long you get to press e for until time expires local catch_time = 3750 --adjusts how far infront of you rod will appear local rod_distance = 30 --adjusts how high infront of you rod will appear local rod_height = 5 --adjusts how much the rod wobbles while in "bite" state local rod_wobble = 10 --how close the fish should get when fully reeled in (just stops swimming closer at this range - doesnt really have any effect on outcome) min_fish_distance = 680 fish_caught = 0 local select_bait = 0 rod = {} rods_collected = 0 bait_collected = 0 state = {} pressed = 0 current_rod = 0 current_bait = 0 local no_bait = 0 local catch_count = 0 local bite_chance = 0 local bite = 0 local counted = 0 local prompt = 0 local catch_count = 0 local struggle = 0 local no_fishing = 0 local show_prompt = 0 local wobble_delay = 20 local up = 0 local x = rod_wobble/2 local prompt_delay = 2000 fish_name = {} fishing_rod = nil local fish = {} player_bait_quantity = {} function fishing_init_name(e,name) fish_name[e] = name player_bait_quantity[1] = 0 player_bait_quantity[2] = 0 player_bait_quantity[3] = 0 player_bait_quantity[4] = 0 state[e] = "wait" rod[0] = "None" bait_type[0] = "None" --bait[0] = "None" player_bait_quantity[0] = "None" Hide(e) CollisionOff(e) end function fishing_main(e) if fish_name[e] ~= "" and fish[e] == nil then for a = 1,9999 do if g_Entity[a] ~= nil and a ~= e then if fish_name[a] ~= nil then if fish_name[a] == fish_name[e] then fish[e] = a break end end end end end Hide(e) CollisionOff(e) if PlayerLooking(e,200,45) == 1 then if state[e] == "wait" then no_fishing = 0 catch_count = 0 bite_chance = 0 bite = 0 counted = 0 prompt = 0 catch_count = 0 Prompt("Press E to fish") if rods_collected > 0 then no_bait = 0 if bait_collected > 0 then for a = 1,max_bait_types do if player_bait_quantity[a] > 0 then else no_bait = no_bait + 1 end end else Prompt("You need bait to fish with") no_fishing = 1 end if no_bait >= max_bait_types then Prompt("You need bait to fish with") no_fishing = 1 end else Prompt("You need a rod to fish with") no_fishing = 1 end if no_fishing == 0 then if GetScancode() == 18 and pressed == 0 then pressed = 1 if rods_collected > 1 then state[e] = "select rod" else select_bait = 0 for a = 1,max_bait_types do if player_bait_quantity[a] > 0 then select_bait = select_bait + 1 end end if select_bait > 1 or player_bait_quantity[current_bait] < 1 then state[e] = "select bait" else state[e] = "fish" end end end end --select a rod --scancodes 51 & 52 elseif state[e] == "select rod" then if fishing_rod ~= nil then if GetPlayerDistance(fishing_rod) < rod_distance then MoveForward(fishing_rod,100) elseif GetPlayerDistance(fishing_rod) > rod_distance * 1.1 then SetPosition(fishing_rod,g_PlayerPosX,g_PlayerPosY+rod_height,g_PlayerPosZ) end SetRotation(fishing_rod,0,g_PlayerAngY,0) Show(fishing_rod) end Prompt("Please select a fishing rod with '<' & '>' and confirm with 'E'") if pressed == 0 then if GetScancode() == 52 then pressed = 1 repeat if current_rod < max_rod_types then current_rod = current_rod + 1 else current_rod = 1 end until rod_collected[current_rod] == 1 elseif GetScancode() == 51 then pressed = 1 repeat if current_rod > 1 then current_rod = current_rod - 1 else current_rod = max_rod_types end until rod_collected[current_rod] == 1 elseif GetScancode() == 18 then pressed = 1 select_bait = 0 for a = 1,max_bait_types do if player_bait_quantity[a] > 0 then select_bait = select_bait + 1 current_bait = a end end if select_bait > 1 then state[e] = "select bait" else state[e] = "fish" end end end --select bait elseif state[e] == "select bait" then if show_prompt == 0 or GetTimer(e) > prompt_delay then show_prompt = 0 Prompt("Please select a fishing bait with '<' & '>' and confirm with 'E'") end if pressed == 0 then if GetScancode() == 52 then pressed = 1 if current_bait < max_bait_types then current_bait = current_bait + 1 else current_bait = 1 end elseif GetScancode() == 51 then pressed = 1 if current_bait > 1 then current_bait = current_bait - 1 else current_bait = max_bait_types end elseif GetScancode() == 18 then pressed = 1 if player_bait_quantity[current_bait] > 0 then state[e] = "fish" else prompt_delay = GetTimer(e) + 1200 show_prompt = 1 PromptDuration("No "..bait_type[current_bait].." bait left",2500) end end end elseif state[e] == "fish" then if fish[e] ~= nil then SetActivated(fish[e],1) end if fishing_rod ~= nil then if GetPlayerDistance(fishing_rod) < rod_distance then MoveForward(fishing_rod,100) elseif GetPlayerDistance(fishing_rod) > rod_distance * 1.1 then SetPosition(fishing_rod,g_PlayerPosX,g_PlayerPosY+rod_height,g_PlayerPosZ) end SetRotation(fishing_rod,0,g_PlayerAngY,0) Show(fishing_rod) end if GetTimer(e) > fishing_delay then prompt = prompt + 1 StartTimer(e) bite_chance = math.random(0,100 - bait_success_rate[current_bait]) if bite_chance <= bite then wobble_delay = GetTimer(e) struggle = GetTimer(e) + (catch_time/4) prompt = 0 bite = 0 state[e] = "bite" player_bait_quantity[current_bait] = player_bait_quantity[current_bait] - 1 catch_count = 0 new_catch_time = GetTimer(e) + catch_time else if bite < bait_success_rate[current_bait] then bite = bite + 1 end end end if prompt < 3 then Prompt("Fishing...") elseif prompt < 6 then Prompt("Fishing.....") elseif prompt < 10 then Prompt("Fishing.........") else Prompt("Fishing.................") end elseif state[e] == "bite" then if fish[e] ~= nil then SetActivated(fish[e],2) end if fishing_rod ~= nil then if GetPlayerDistance(fishing_rod) < rod_distance then MoveForward(fishing_rod,100) elseif GetPlayerDistance(fishing_rod) > rod_distance * 1.1 then SetPosition(fishing_rod,g_PlayerPosX,g_PlayerPosY+rod_height,g_PlayerPosZ) end Show(fishing_rod) end catch_needed = math.floor((catch_count / (100-(rod_success_rate[current_rod] + (bait_success_rate[current_bait]/4))))*100) Prompt("Bite! Repeatedly press 'E' to catch the fish. "..catch_needed.."%") if GetTimer(e) < catch_time and catch_count < 100 - (rod_success_rate[current_rod] + (bait_success_rate[current_bait]/4)) then if GetTimer(e) > wobble_delay then wobble_delay = GetTimer(e) + 20 if up == 1 then if x < rod_wobble then x = x + 1 else up = 0 end elseif up == 0 then if x > 0 then x = x - 1 else up = 1 end end end SetRotation(fishing_rod,x,g_PlayerAngY,x) if GetTimer(e) > struggle then catch_count = catch_count - math.floor(math.random(rod_success_rate[current_rod]/10,rod_success_rate[current_rod]/5)) struggle = GetTimer(e) + (catch_time/4) end counted = 0 if GetScancode() == 18 and pressed == 0 then pressed = 1 catch_count = catch_count + math.floor((rod_success_rate[current_rod]/5)) end else SetRotation(fishing_rod,0,g_PlayerAngY,0) if catch_count > 100 - (rod_success_rate[current_rod] + (bait_success_rate[current_bait]/4)) then PromptDuration("You caught the fish!",2500) if counted == 0 then PlaySound(e,0) fish_caught = fish_caught + 1 counted = 1 end else if counted == 0 then PlaySound(e,1) counted = 1 end PromptDuration("Unlucky, this one got away",2500) end if GetTimer(e) > catch_time + 1750 then catch_count = 0 StartTimer(e) if fish[e] ~= nil then SetActivated(fish[e],1) end if player_bait_quantity[current_bait] > 0 then state[e] = "fish" else if fishing_rod ~= nil then Hide(fishing_rod) end state[e] = "wait" end end end end --state Panel(72,0,100,20) TextCenterOnX(86,3,3,"Fishing Rod Type : ") TextCenterOnX(86,7,3,rod[current_rod]) TextCenterOnX(86,13,3,"Fishing Bait Type / Quantity : ") TextCenterOnX(86,17,3,bait_type[current_bait].." / "..player_bait_quantity[current_bait]) Panel(40,0,60,10) TextCenterOnX(50,3,3,"Fish Caught : ") TextCenterOnX(50,7.2,3,fish_caught) else if fish[e] ~= nil then SetActivated(fish[e],1) end state[e] = "wait" if fishing_rod ~= nil then Hide(fishing_rod) end end --in fishing area if GetScancode() == 0 then pressed = 0 end end --main --------------- function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end