;Bloodlink - Set
;Skill #4

;Amount of blood needed to cast this spell
BloodCost = 5

;The map number to set the warp to
MapNum = #MAPID

;User's mana at time of using skill
Blood = GetUserMana(#USERID)

If Blood < BloodCost
	SendMessageToUser(#USERID,"You need more blood to link to this location.",#MSG_CRITICAL)
	Goto END
EndIf

If MapNum = 159
	WarpPoint = 0
Elseif MapNum = 128
	WarpPoint = 1
Elseif MapNum = 177
	WarpPoint = 2
Elseif MapNum = 398
	WarpPoint = 3
Elseif MapNum = 375
	WarpPoint = 4
Elseif MapNum = 305
	WarpPoint = 5
Elseif MapNum = 738
	WarpPoint = 6
Elseif MapNum = 1135
	WarpPoint = 7
Elseif MapNum = 628
	WarpPoint = 8
Elseif MapNum = 602
	WarpPoint = 9
Elseif MapNum = 30
	WarpPoint = 10
Else
	SendMessageToUser(#USERID,"You cannot link your blood to this area.",#MSG_CRITICAL)
	Goto END
Endif

;NEW CODE
PointA = GetUserFlag(#USERID, 49) % 100000
PointB = GetUserFlag(#USERID, 49) / 100000

If WarpPoint = PointA
	;Swap the two points
	PointA = PointB
	PointB = WarpPoint
	
	;Compile and store the two values again
	WarpPoint = PointB * 100000
	WarpPoint = WarpPoint + PointA
	SetUserFlag(#USERID, 49, WarpPoint)
	SendMessageToUser(#USERID,"Your blood already flows in this spot. Your two marked links will be swapped.",#MSG_CRITICAL)
	Goto END
ElseIf WarpPoint = PointB
	;Swap the two points
	PointB = PointA
	PointA = WarpPoint
	
	;Compile and store the two values again
	WarpPoint = PointB * 100000
	WarpPoint = WarpPoint + PointA
	SetUserFlag(#USERID, 49, WarpPoint)
	SendMessageToUser(#USERID,"Your blood already flows in this spot. Your two marked links will be swapped.",#MSG_CRITICAL)
	Goto END
Else
	Blood = Blood - BloodCost
	SetUserMana(#USERID, Blood)
	
	PointB = PointA
	PointA = WarpPoint
	
	;Compile and store the two values again
	WarpPoint = PointB * 100000
	WarpPoint = WarpPoint + PointA
	SetUserFlag(#USERID, 49, WarpPoint)
	SendMessageToUser(#USERID, "Your blood is now linked to this spot.", #MSG_CRITICAL)
Endif

;END OF NEW CODE

;If WarpPoint = GetUserFlag(#USERID, 49)
;	SendMessageToUser(#USERID,"Your blood already flows in this spot.",#MSG_CRITICAL)
;	Goto END
;Endif 

Label END

Continue = 1