
isArrowE = {}
local hitE = {}
--make sure you have bowAmmoIndex set (set in bowarrow.lua if you have set bowGunID)
local cancollect = true 
local pickuprange = 120
local pickupangle = 35

--sound 0 = pick up sound
function arrow_init(e)
	isArrowE[e] = e 
	SetActivated(e,0)
end 

function arrow_main(e)
	local ent = g_Entity[e]
	if ent.activated == 0 then 
		CollisionOff(e)
		Hide(e)
		SetActivated(e,1)
	elseif ent.activated == 1 then 
		
	elseif ent.activated == 2 then 
		if hitE[e] ~= nil and g_Entity[hitE[e]]['health'] < 1 then 
			RemoveArrow(e)
			return 
		end 
		if cancollect == true then 
			if U.PlayerLookingNear(e,pickuprange,pickupangle) == true then 
				PromptLocal(e,"Collect arrow? (e)")
				if g_KeyPressE == 1 then 
					if not ePressed then
						SetWeaponPoolAmmo(bowAmmoIndex, GetWeaponPoolAmmo(bowAmmoIndex)+1)
						PlaySound(e,0)
						RemoveArrow(e)
					end 
					ePressed = true 
				else 
					ePressed = false 
				end 				
			end 
		end
	end 

end 

function PlaceArrow(e, x,y,z, ax,ay,az, arrowtype, entity)
	SetPosition(e,x,y,z)
	SetRotation(e,ax,ay,az)	
	hitE[e] = entity 
	if arrowtype == "fire" then 
		if entity ~= nil then 
			if walltorch ~= nil then 
				if walltorch[entity] ~= nil then 
					LightTorch(entity)
				end 
			end 
		end 
	elseif arrowtype == "water" then 
		if entity ~= nil then 
			if walltorch ~= nil then 
				if walltorch[entity] ~= nil then 
					ExtinguishTorch(entity)
				end 
			end 
		end 
	end
	Show(e)
	SetActivated(e,2)		
end 

function RemoveArrow(e)
	hitE[e] = nil
	SetActivated(e,0)
end
