;'Death script'
CreateEffect(50,2000,0,#DIR_UP,GetUserMap(#USERID),GetUserX(#USERID),GetUserY(#USERID),0,#USERID,0)

;If-pyramid, a temporary solution until dracflamloc adds a IsN00b() function.
If GetUserStrength(#USERID) < 8
	If GetUserWisdom(#USERID) < 8
		If GetUserEndurance(#USERID) < 8
			If GetUserAgility(#USERID) < 8
				GoTo WARP
			EndIf
		EndIf
	EndIf
EndIf

;Drop random inventory item on death
;Check if Inv is empty
i=0
InvCount=0
While i<40
If GetUserInvItem(#USERID,i)>0
	If SubString(GetItemName(GetUserInvItem(#USERID,i)),1,1)<>"*"
		If SubString(GetItemName(GetUserInvItem(#USERID,i)),1,1)<>"~"
			InvCount=InvCount+1
		Endif
	Endif
Endif
i=i+1
Wend

;Select random Inv item
Label DropRandomItem
If InvCount>0
If GetUserAccess(#USERID)<1
InvItem=Random(0,39)

If GetUserInvItem(#USERID,InvItem)>0
	If SubString(GetItemName(GetUserInvItem(#USERID,InvItem)),1,1)<>"*"
		If SubString(GetItemName(GetUserInvItem(#USERID,InvItem)),1,1)<>"~"
			SendCombatMessage(#USERID,"You dropped your "+GetItemName(GetUserInvItem(#USERID,InvItem))+" on death!")
			SpawnItem(#MAPID,GetUserInvItem(#USERID,InvItem),#XPOS,#YPOS)
			TakeItem(#USERID,GetUserInvItem(#USERID,InvItem))
			;DropItem(#USERID,GetUserInvItem(#USERID,InvItem))
			Goto WARP
		Endif
	Endif
Endif
Goto DropRandomItem
Endif
Endif

Label WARP

;If player has a 'Resurrection Crystal' in his inventory
If HasItem(#USERID, 514) = 1
	TakeItem(#USERID, 514)
	WarpUser(#USERID,#MAPID,#XPOS,#YPOS)
	SendMessageToMap(#MAPID,GetUserName(#USERID)+" returns to life!",#MSG_EMOTE)
;If has a 'Orb of Guidence' turned on
ElseIf HasItem(#USERID, 197) = 1
	WarpUser(#USERID,9,10,10)
	SendMessageToUser(#USERID,"You are brought to the graveyard by your Orb of Guidence",#MSG_SERVER)
EndIf

;Mystix's custom cape. Shouldn't be dropable, since he's a mod, and it's a unique item.
If GetUserID("Mystix")=#USERID
	TakeItem(#USERID,756)
	GiveItem(#USERID,756)
	RemoveItem(#MAPID,756)
EndIf

;Player-usable chill touch
If GetUserTempFlag(#USERID, 6) = 1
	If GetMapType(#MAPID) = #MAPTYPE_PK
		Timer(811, 1, #USERID, 0, 0)
	EndIf
EndIf

Label End

Continue = 1