;'Locked Chests' NPC-object script

LastChest = GetUserFlag(#USERID,45)

SmallKey = 7
LargeKey = 8

KeyType=SmallKey 
ItemName=""
ItemReward = 0
Item2Name=""
Item2Reward = 0
Item3Name=""
Item3Reward = 0
SilverReward = 0

ChestID = 0

;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

If #MAPID = 601
	ChestID = 1 
	KeyType=LargeKey
	SilverReward=5000
Else
	GoTo END
EndIf

;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

MSG=GetUserMessage(#USERID)

Open = 0

If MSG="Open"
	Open = 1
ElseIf MSG="open"
	Open = 1
ElseIf MSG="yes"
	Open = 1
ElseIf MSG="Yes"
	Open = 1
ElseIf MSG="unlock"
	Open = 1
ElseIf MSG="No"
	Open = 0
ElseIf MSG="no"
	Open = 0
ElseIf MSG="close"
	Open = 0
ElseIf MSG="lock"
	Open = -1
ElseIf MSG="Lock"
	Open = -1
ElseIf MSG="look"
	Open = -1
ElseIf MSG="Look"
	Open = -1
Else
	SendMessageToUser(#USERID,"This chest is locked. Do you wish to open it?",#MSG_EMOTE)
	GoTo END
EndIf

If Open = 0
	SendMessageToUser(#USERID,"You decide not to open it after all...",#MSG_EMOTE)
	GoTo END
ElseIf Open = -1
	If KeyType="Small"
		SendMessageToUser(#USERID,"You inspect the lock and see that it requires a small key.",#MSG_EMOTE)
	Else
		SendMessageToUser(#USERID,"You look and see that this chest needs a large key to be unlocked.",#MSG_EMOTE)
	EndIf
	GoTo END
Else
	If LastChest = ChestID
		SendMessageToUser(#USERID,"This chest is empty!",#MSG_EMOTE)
		GoTo END
	EndIf
EndIf

If KeyType=SmallKey
	If HasItem(#USERID,SmallKey) = 0
		SendMessageToUser(#USERID,"You don't have a small key.",#MSG_CRITICAL)
		GoTo END
	Else
		TakeItem(#USERID,SmallKey)
	EndIf
Else
	If HasItem(#USERID,LargeKey) = 0
		SendMessageToUser(#USERID,"You don't have a large key.",#MSG_CRITICAL)
		GoTo END
	Else
		TakeItem(#USERID,LargeKey)
	EndIf
EndIf

SendMessageToUser(#USERID,"You unlocked the chest and peer inside...",#MSG_EMOTE)

;Item 1
If ItemReward <> 0
	If InvFull(#USERID) = 1
		SendMessageToUser(#USERID,"Your inventory is full!",#MSG_CRITICAL)
	Else
		GiveItem(#USERID,ItemReward)
		SendMessageToUser(#USERID,"You found a "+ItemName+"!",#MSG_TELL)
	EndIf
EndIf

;Item 2
If Item2Reward <> 0
	If InvFull(#USERID) = 1
		SendMessageToUser(#USERID,"Your inventory is full!",#MSG_CRITICAL)
	Else
		GiveItem(#USERID,Item2Reward)
		SendMessageToUser(#USERID,"You found a "+ItemName+"!",#MSG_TELL)
	EndIf
EndIf

;Item 3
If Item3Reward <> 0
	If InvFull(#USERID) = 1
		SendMessageToUser(#USERID,"Your inventory is full!",#MSG_CRITICAL)
	Else
		GiveItem(#USERID,Item3Reward)
		SendMessageToUser(#USERID,"You found a "+ItemName+"!",#MSG_TELL)
	EndIf
EndIf

;Silver
If SilverReward <> 0
	SetUserSilver(#USERID,GetUserSilver(#USERID)+SilverReward)
	SendMessageToUser(#USERID,"You found "+SilverReward+" silver!",#MSG_TELL)
EndIf

SetUserFlag(#USERID, 45, ChestID)

Label END

Continue = 1