;GUN SCRIPT


;If #USERID = 254
;	SendMessageToUser(#USERID,"Hangover, because you abused the gun glitch even when I've told everyone not to, you can never again use a gun on this account. With love, Comrade",#MSG_CRITICAL)
;	GoTo END
;EndIf

;SendMessageToUser(#USERID,"Because of players abusing the gun glitch, it's disabled until I fix it - Comrade",#MSG_SERVER)
;GoTo END

BaseDamage=Floor(Floor(GetUserAgility(#USERID)+GetUserAgilityBonus(#USERID))*0.5)+GetItemFlag1(#TARGETID)
SetUserFlag(#USERID,24,BaseDamage+GetUserFlag(#USERID,27))

If GetUserFlag(#USERID,21)>GetItemFlag4(#TARGETID)
Goto End
Endif

If GetUserDirection(#USERID)=#DIR_UP
StartX=GetUserX(#USERID)
StartY=GetUserY(#USERID)-1
CurrX=GetUserX(#USERID)
CurrY=GetUserY(#USERID)-2
EffectID=GetItemFlag3(#TARGETID)
SetUserFlag(#USERID,19,1)
Elseif GetUserDirection(#USERID)=#DIR_DOWN
StartX=GetUserX(#USERID)
StartY=GetUserY(#USERID)+1
CurrX=GetUserX(#USERID)
CurrY=GetUserY(#USERID)+2
EffectID=GetItemFlag3(#TARGETID)
SetUserFlag(#USERID,19,2)
Elseif GetUserDirection(#USERID)=#DIR_RIGHT
StartX=GetUserX(#USERID)+1
StartY=GetUserY(#USERID)
CurrX=GetUserX(#USERID)+2
CurrY=GetUserY(#USERID)
EffectID=GetItemFlag2(#TARGETID)
SetUserFlag(#USERID,19,3)
Elseif GetUserDirection(#USERID)=#DIR_LEFT
StartX=GetUserX(#USERID)-1
StartY=GetUserY(#USERID)
CurrX=GetUserX(#USERID)-2
CurrY=GetUserY(#USERID)
EffectID=GetItemFlag2(#TARGETID)
SetUserFlag(#USERID,19,4)
Endif


If GetUserFlag(#USERID,22)=#TARGETID
Goto StartFire
Elseif GetUserFlag(#USERID,26)=#TARGETID
Goto StartFire
Else
Goto FailFire
Endif

Label StartFire
	If GetUserFlag(#USERID,23)=0
		SendCombatMessage(#USERID,"You are out of ammo for the "+GetItemName(#TARGETID)+" ")
	Else
		SendCombatMessage(#USERID,"You have "+Floor(GetUserFlag(#USERID,23)-1)+" rounds left ")
		SetUserFlag(#USERID,23,GetUserFlag(#USERID,23)-1)
		CreateEffect(18,100,0,GetUserDirection(#USERID),GetUserMap(#USERID),StartX,StartY,0,0,0)


		If GetUserAtXY(GetUserMap(#USERID),StartX,StartY)>0
			Goto FireGun
		Elseif GetMonsterAtXY(GetUserMap(#USERID),StartX,StartY)>-1
			Goto FireGun
		Elseif GetTileType(GetUserMap(#USERID),StartX,StartY)=#TILE_DOOR
			Goto End
		Elseif GetTileType(GetUserMap(#USERID),StartX,StartY)=#TILE_WALL
			Goto End
		Elseif GetTileType(GetUserMap(#USERID),StartX,StartY)=#TILE_WARP
			Goto End
		Elseif GetTileType(GetUserMap(#USERID),StartX,StartY)=#TILE_NPC
			Goto End
		Elseif GetTileType(GetUserMap(#USERID),StartX,StartY)=#TILE_GODONLY
			Goto End
		Else
			CreateEffect(EffectID,1000,50,GetUserDirection(#USERID),GetUserMap(#USERID),CurrX,CurrY,0,0,1)
			Goto FireGun
		Endif
	Endif

Goto End

Label FailFire
	If GetUserFlag(#USERID,22)>0
		SendCombatMessage(#USERID,"You have ammo for the "+GetItemName(GetUserFlag(#USERID,22))+" loaded ")
	Else
		SendCombatMessage(#USERID,"You are out of ammo for the "+GetItemName(#TARGETID)+" ")
	Endif
Goto End

Label FireGun
SetUserFlag(#USERID,21,GetUserFlag(#USERID,21)+1)
SetUserFlag(#USERID,20,GetUserMap(#USERID))
Timer(402,0,#USERID,StartX,StartY)
Timer(403,4000,#USERID,0,0)

Label End

Continue = 1
