target = 0
charge = 0
fireball = 0
lastpos = vector3(0,0,0)
fired = false

	function onInit( )
		_SWEPSetSound( MyIndex, "single_shot", "NPC_Sniper.FireBullet" )
	end

	function onThink( )
		if(not _PlayerInfo(Owner, "alive")) then return; end
		if(not _PlayerIsKeyDown(Owner, IN_ATTACK)) then charge = 0; end
		if(not fired and _PlayerIsKeyDown(Owner, IN_ATTACK)) then
			_TraceLine(_PlayerGetShootPos(Owner), _PlayerGetShootAng(Owner), 4064, Owner)
			if(_TraceHitNonWorld()) then
				if(target==_TraceGetEnt()) then
					charge = charge+1
				else
					charge = 0
					target = _TraceGetEnt()
				end
				_GModText_Start( "ImpactMassive" )
		    	_GModText_SetPos( -1.0, -1.0 )
				 _GModText_SetColor( 255, 50, 200, 200 )
				 _GModText_SetTime( 3, 0, 0 )
				if(charge <= 10) then
				_GModText_SetText("<    >")
				elseif(charge <= 20) then
			 	_GModText_SetText("<   >")
				elseif(charge <= 30) then
				_GModText_SetText("<  >")
				elseif(charge <= 45) then
				_GModText_SetText("<>")				 
				elseif(charge >= 60) then
				_GModText_SetText("<<<!>>>")
				end
				_GModText_Send( Owner, 8111 )
				if(charge >= 60) then
					fired = true
					target = _TraceGetEnt()
					fireball = _EntCreate("physics_prop")
					_EntPrecacheModel( "models/props/cs_italy/orange.mdl" );			
					if(fireball > 0) then
						_EntSetPos(fireball, vecAdd( _PlayerGetShootPos(Owner), vecMul( _PlayerGetShootAng(Owner), vector3(80,80,80))))
						_EntSetModel(fireball, "models/props/cs_italy/orange.mdl")
						_PhysSetMass(fireball, "100")
						_EntSetModel(fireball, "models/props/cs_italy/orange.mdl")
						_EntSetKeyValue(fireball, "ExplodeDamage", "150")
						_EntSetKeyValue(fireball, "ExplodeRadius", "320")
						_EntSpawn(fireball)
						local fireforce = vecMul(_PlayerGetShootAng(userid), vector3(90000, 90000, 90000))
            			_PhysApplyForce(fireball, fireforce)
						_phys.EnableGravity(fireball, false)
						_EntFire(fireball, "Alpha", "0", 0)
						_EntFire(fireball, "sethealth", "1", 0)
						_EntFire(fireball, "break", "", 20)
					end
				end
			else
				target = 0
				charge = 0
				fired = false
			end
		elseif(fired) then
			if(_EntGetType(fireball) == "n/a" or _EntGetType(target) == "n/a") then
				fired = false
				charge = 0
				target = 0
				local exp = _EntCreate("env_ar2explosion")
				if(exp > 0) then
					_EntSetPos(exp, lastpos)
					_EntSpawn(exp)
					_EntFire(exp, "explode", "", 0.1)
					_EntEmitSound(exp, "weapons/physcannon/energy_disintegrate5.wav")
					_EntEmitSound(exp, "weapons/mortar/mortar_explode1.wav")
				end
				fireball = 0
				return
			end
			local entvec = vecNormalize(vecSub(_EntGetPos(target),_EntGetPos(fireball)))
            local forcevec = vecMul(entvec,vector3(80,80,40))
            _PhysApplyForce(fireball,forcevec)
            lastpos = _EntGetPos(fireball)
            local targs = _EntitiesFindInSphere(lastpos, 15)
		if(table.getn(targs) == 0) then return; end
		for i=1, table.getn(targs) do
			if(targs[i] == target) then
				_EntFire(fireball, "sethealth", "0", 0)
				_EntFire(fireball, "kill", "", 0)
			end
		end
		return
		end
	end
	
	function onPrimaryAttack( )
	end
		
	function onSecondaryAttack( )
		if(_EntGetType(fireball) ~= "n/a") then
			_EntFire(fireball, "break", "", 0)
			_EntFire(fireball, "kill", "", 0)
		end
	end

	function onReload( )
	end

	function getWeaponSwapHands()
		return true
	end
	
	function getWeaponFOV()
		return 75
	end
	
	function getWeaponSlot()
		return 2;	
	end
	
	function getWeaponSlotPos()
		return 5;	
	end
	
	function getFiresUnderwater()
		return true
	end
	
	function getReloadsSingly()
		return false
	end
	
	function getDamage()
		return 500
	end
	
	function getPrimaryShotDelay()
		return 0.08
	end
	
	function getSecondaryShotDelay()
		return 0.1
	end
	
	function getPrimaryIsAutomatic()
		return true
	end
	
	function getSecondaryIsAutomatic()
		return false
	end
	
	function getSecondaryIsAutomatic()
		return false
	end
	
	function getBulletSpread()
		return vector3( 0.001, 0.001, 0.001 );
	end
	
	function getViewKick()
		return vector3( 0.0, 0.0, 0.0);
	end
	
	function getViewKickRandom()
		return vector3( 0.4, 0.4, 0.4 );
	end

	function getViewModel( )
		return "models/weapons/v_snip_awp.mdl";
	end
	
	function getWorldModel( )
		return "models/weapons/w_snip_awp.mdl";
	end
	
	function getClassName()
		return "weapon_flameshot";
	end

	function getPrimaryAmmoType()
		return "pistol";
	end
		
	function getSecondaryAmmoType()
		return "pistol";
	end
	
	-- return -1 if it doesn't use clips
	function getMaxClipPrimary()
		return 1;
	end
	
	function getMaxClipSecondary()
		return -1;
	end
	
	-- ammo in gun by default
	function getDefClipPrimary()
		return 450;
	end
	
	function getDefClipSecondary()
		return -1;
	end

	-- pistol, smg, ar2, shotgun, rpg, phys, crossbow, melee, slam, grenade
	function getAnimPrefix()
		return "smg";
	end

	function getPrintName()
		return "Flame Shot"
	end

	function getPrimaryScriptOverride()
		return 3
	end

	function getSecondaryScriptOverride()
		return 3
	end
