Think = 0
charge = 0
nextshot = 0.0

function onInit()
	_SWEPSetSound( MyIndex, "single_shot", "" )
end

function Holster()
	charge = 0
	DrawCharge()
	Think = _CurTime()
end

function onThink()
	if _CurTime() >= Think+0.13 then
		if _PlayerIsKeyDown(Owner, IN_ATTACK) and _CurTime() > nextshot then
			if charge < 100 then
				charge = charge+5
			else
				_RunString("CreateArrow("..Owner..", 3)")
				nextshot = _CurTime()+2
				charge = 0
				return
			end
		elseif charge > 0 then
			if charge <= 25 then
				_RunString("CreateArrow("..Owner..", 1)")
				nextshot = _CurTime()+0.6
			elseif charge <= 50 then
				_RunString("CreateArrow("..Owner..", 4)")
				_EntEmitSound(Owner, "weapons/tripwire/hook.wav")
				nextshot = _CurTime()+1
			elseif charge <= 75 then
				_RunString("CreateArrow("..Owner..", 2)")
				nextshot = _CurTime()+1.5
			elseif charge <= 100 then
				_RunString("CreateArrow("..Owner..", 3)")
				nextshot = _CurTime()+2
			end
			charge = 0
		end
		DrawCharge()
		Think = _CurTime()
	end
end

function DrawCharge()
if Owner <= 0 then return end
_GModRect_Start("gmod/white")
 _GModRect_SetPos(0.4, 0.95, 0.2, 0.1)
 _GModRect_SetColor(0, 0, 0, 200)
 _GModRect_SetTime(10, 0, 0)
_GModRect_Send(Owner, 1800)

_GModRect_Start("gmod/white")
 _GModRect_SetPos(0.41, 0.96, charge*0.0018, 0.05)
 if charge <= 25 then
 _GModRect_SetColor( 255, 255, 255, 255 )
 elseif charge <= 50 then
  _GModRect_SetColor( 0, 255, 0, 255 )
 elseif charge <= 75 then
  _GModRect_SetColor( 255, 0, 0, 255 )
 else
 _GModRect_SetColor( 0, 0, 255, 255 )
 end
 _GModRect_SetTime(10, 0, 0)
_GModRect_Send(Owner, 1801)
end

function onPrimaryAttack()
end

function onSecondaryAttack()
end

function onReload()
	return true
end

function getWeaponSwapHands()
	return false
end

function getWeaponFOV()
	return 75
end

function getWeaponSlot()
	return 5
end

function getWeaponSlotPos()
	return 3
end

function getFiresUnderwater()
	return true
end

function getReloadsSingly()
	return true
end

function getDamage()
	return 100
end

function getPrimaryShotDelay()
	return 1.25
end

function getSecondaryShotDelay()
	return 0.1
end

function getPrimaryIsAutomatic()
	return false
end

function getSecondaryIsAutomatic()
	return false
end

function getPrimaryAmmoType()
	return "none"
end

function getSecondaryAmmoType()
	return "none"
end

function getMaxClipPrimary()
	return 1
end

function getMaxClipSecondary()
	return -1
end

function getDefClipPrimary()
	return 1
end

function getDefClipSecondary()
	return -1
end

function getPrimaryScriptOverride()
	return 3
end

function getSecondaryScriptOverride()
	return 3
end

function getBulletSpread()
	return vector3( 0.0, 0.0, 0.0 )
end

function getViewKick()
	return vector3( 0, 0.0, 0.0)
end

function getViewKickRandom()
	return vector3( 0.0, 0.0, 0.0 )
end

function getViewModel( )
	return "models/weapons/v_crossbow.mdl"
end

function getWorldModel( )
	return "models/weapons/w_crossbow.mdl"
end

function getClassName()
	return "archer_bow"
end

function getAnimPrefix()
	return "crossbow"
end

function getPrintName()
	return "Archer Crossbow"
end

function getDeathIcon( )
	return "d_crossbow"
end
