-- LUA Script - precede every function and global member with lowercase name of script + '_main'
--DESCRIPTION: smallg's fishing rod script - to work with fishing.lua
--DESCRIPTION: [RODIMAGE=2]
--DESCRIPTION: [CASTSPEED=200]
--DESCRIPTION: [REELSPEED=100]
--DESCRIPTION: [PICKUPRANGE=100]
--DESCRIPTION: [PICKUPANGLE=20]
--DESCRIPTION: [RODCOLLECTED!=0]
--DESCRIPTION: Sounds: slot 1 = pick up, 2 = cast line

U = U or require "scriptbank\\utillib"
g_fishing_rod = {}

function fishing_rod_properties(e, rodimage, castspeed, reelspeed, pickuprange, pickupangle, rodcollected)
	local r = g_fishing_rod[e]
	r.rodimage = rodimage
	r.castspeed = castspeed
	r.reelspeed = reelspeed
	r.pickuprange = pickuprange
	r.pickupangle = pickupangle
	r.rodcollected = rodcollected
end 

function fishing_rod_init(e)
	g_fishing_rod[e] = {}
	local r = g_fishing_rod[e]
	local rname = string.lower(GetEntityName(e))
	if string.find(rname,"beginner") ~= nil then 
		r.rodimage = 1 
		r.castspeed = 150
		r.reelspeed = 75
	elseif string.find(rname,"basic") ~= nil then 
		r.rodimage = 2
		r.castspeed = 200
		r.reelspeed = 100
	elseif string.find(rname,"expert") ~= nil then 
		r.rodimage = 3
		r.castspeed = 250
		r.reelspeed = 150
	elseif string.find(rname,"master") ~= nil then 
		r.rodimage = 4
		r.castspeed = 300
		r.reelspeed = 200
	end 
	r.pickuprange = 100
	r.pickupangle = 20
	r.rodcollected = 0
end 

function fishing_rod_main(e)
	local r = g_fishing_rod[e]
	if r.rodcollected == 0 then 
		if U.PlayerLookingNear(e, r.pickuprange, r.pickupangle) == true then 
			PromptLocal(e, "Collect the "..GetEntityName(e).."? (E)")
			if g_KeyPressE == 1 then 
				if presse == 0 then 
					presse = 1 
					PlaySound(e,1)
					r.rodcollected = 1 
				end 
			else 
				presse = 0
			end 
		end 
	elseif r.rodcollected == 1 then 
		CollisionOff(e)
		Hide(e)
		r.rodcollected = 2 
	end 
end 