-- LUA Script - precede every function and global member with lowercase name of script + '_main'
--DESCRIPTION: smallg's fishing bait script - to work with fishing.lua
--DESCRIPTION: [BAITIMAGE=2]
--DESCRIPTION: [CATCHCHANCE=1]
--DESCRIPTION: [BAITQUANTITY=10] --amount to pick up when collecting
--DESCRIPTION: [PICKUPRANGE=100]
--DESCRIPTION: [PICKUPANGLE=20]
--DESCRIPTION: [BAITCOLLECTED!=0]
--DESCRIPTION: Sounds: slot 1 = pick up

U = U or require "scriptbank\\utillib"
g_fishing_bait = {}
baittotal = {}
function fishing_bait_properties(e, baitimage, catchchange, baitquantity, pickuprange, pickupangle, baitcollected, baittotal)
	local b = g_fishing_bait[e]
	b.baitimage = baitimage
	b.catchchange = catchchange
	b.baitquantity = baitquantity
	b.pickuprange = pickuprange
	b.pickupangle = pickupangle
	b.baitcollected = baitcollected
end 


function fishing_bait_init(e)
	g_fishing_bait[e] = {}
	local b = g_fishing_bait[e]
	local bname = string.lower(GetEntityName(e))
	if string.find(bname,"basic") ~= nil then 
		b.baitimage = 1
		b.catchchance = 1
	elseif string.find(bname,"expert") ~= nil then 
		b.baitimage = 2
		b.catchchance = 10
	elseif string.find(bname,"master") ~= nil then 
		b.baitimage = 3
		b.catchchance = 40
	else 
		b.baitimage = 1
		b.catchchance = 1
	end 
	baittotal[b.baitimage] = baittotal[b.baitimage] or 0
	b.baitquantity = g_Entity[e]['health']
	b.pickuprange = 100
	b.pickupangle = 20
	b.baitcollected = 0
	b.baittotal = 0
	
end 

function fishing_bait_main(e)
	local b = g_fishing_bait[e]
	if b.baitcollected == 0 then 
		if U.PlayerLookingNear(e, b.pickuprange, b.pickupangle) == true then 
			PromptLocal(e,"Collected the "..GetEntityName(e).."? (E)")
			if g_KeyPressE == 1 then 
				if presse == 0 then 
					presse = 1
					PlaySound(e,1)
					b.baitcollected = 1
				end 
			else 
				presse = 0
			end 
		end 
	elseif b.baitcollected == 1 then 
		baittotal[b.baitimage] = baittotal[b.baitimage] + b.baitquantity
		CollisionOff(e)
		Hide(e)
		b.baitcollected = 2 
	end 				
end 

