enterportal = vector3(0,0,0)
exitportal = vector3(0,0,0)
opentime = 0

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

function onThink()
	local temp = ""
	if enterportal.x ~= 0 and exitportal.x ~= 0 then
		local tab = _EntitiesFindInSphere(enterportal, 100)
		for i=1, table.getn(tab) do
			temp = _EntGetType(tab[i])
			if temp == "player" then
				if _PlayerInfo(Owner, "team") ~= _PlayerInfo(tab[i], "team") or tab[i] == Owner then
					local ent = _EntCreate("info_target")
					if ent > 0 then
						_EntSetPos(ent, enterportal)
						_EntSpawn(ent)
						_EntFire(ent, "kill", "", 0.75)
						local ran = math.random(2, 4)
						if ran < 3 then ran = 1 end
						_EntEmitSound(ent, "ambient/machines/teleport"..ran..".wav")
					end
					_EntSetPos(tab[i], exitportal)
				end
			elseif temp == "prop_physics" then
				if tab[i] ~= redflag and tab[i] ~= blueflag and _EntGetName(tab[i]) ~= "frozenprop" then
					local ent = _EntCreate("info_target")
					if ent > 0 then
						_EntSetPos(ent, enterportal)
						_EntSpawn(ent)
						_EntFire(ent, "kill", "", 0.75)
						local ran = math.random(2, 4)
						if ran < 3 then ran = 1 end
						_EntEmitSound(ent, "ambient/machines/teleport"..ran..".wav")
					end
					_EntSetPos(tab[i], exitportal)
				end
			end
		end
		opentime = opentime+1
		if opentime > 100 then
			enterportal = vector3(0,0,0)
			exitportal = vector3(0,0,0)
			opentime = 0
		end
	end	
end

--sprites/physbeam.spr

function onPrimaryAttack()
	_RunString("CreateWraithPortalEntry("..Owner..")")
end

function onSecondaryAttack()
	_RunString("CreateWraithPortalExit("..Owner..")")
end

function onReload()
end

function getWeaponSwapHands() end
function getWeaponFOV() return 60 end
function getWeaponSlot() return 1 end
function getWeaponSlotPos() return 5 end
function getFiresUnderwater() return true end
function getReloadsSingly() return false end
function getDamage() return 1 end
function getPrimaryShotDelay() return 0.1 end
function getSecondaryShotDelay() return 0.1 end
function getPrimaryIsAutomatic() return true end
function getSecondaryIsAutomatic() return true 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_physcannon.mdl" end
function getWorldModel() return "models/weapons/shell.mdl" end
function getClassName()	return "wraith_weapon" end
function getAnimPrefix() return "slam" end
function getPrintName() return "Wraith" end
function getDeathIcon() return "d_wraith" end
