;Skillbook item script

;Item flag 1: Class only class (0 equals no class, add 1 to any class ID)
;Item flag 2: Type of stat (0 equals general level, 1 = strength, etc...)
;Item flag 3: Minimum stat level
;Item flag 4: Skill ID (The ID of the skill this book gives)

;For a generic non-tradable item drop script, use script #14

ITEMID = #TARGETID

ClassOnly = GetItemFlag1(ITEMID)
StatType = GetItemFlag2(ITEMID)
StatLevel = GetItemFlag3(ITEMID)
SkillID = GetItemFlag4(ITEMID)

;Make sure the user is the right class.
If ClassOnly > 0
	ClassOnly = ClassOnly - 1
	
	If ClassOnly <> GetUserClass(#USERID)
		SendMessageToUser(#USERID,"Your class cannot use this skill.",#MSG_SAY)
		GoTo END
	EndIf
EndIf

;Make sure the user has the right amount of stats.
If StatLevel > 0
	If StatType = 0
		GeneralLevel = 0
		GeneralLevel = GeneralLevel + GetUserStrength(#USERID)
		GeneralLevel = GeneralLevel + GetUserEndurance(#USERID)
		GeneralLevel = GeneralLevel + GetUserWisdom(#USERID)
		GeneralLevel = GeneralLevel + GetUserAgility(#USERID)
		GeneralLevel = GeneralLevel / 4
		
		If GeneralLevel < StatLevel
			SendMessageToUser(#USERID,"You need a general stat level of "+StatLevel+" to learn this skill.",#MSG_SAY)
			GoTo END
		EndIf
	Else
		PlayerStatLevel = 0
		STATMESSAGE=""
		
		If StatType = 1
			PlayerStatLevel = GetUserStrength(#USERID)
			STATMESSAGE="Strength"
		ElseIf StatType = 2
			PlayerStatLevel = GetUserEndurance(#USERID)
			STATMESSAGE="Endurance"
		ElseIf StatType = 3
			PlayerStatLevel = GetUserWisdom(#USERID)
			STATMESSAGE="Wisdom"
		ElseIf StatType = 4
			PlayerStatLevel = GetUserAgility(#USERID)
			STATMESSAGE="Agility"
		Else
			SendMessageToUser(#USERID,"This item, Item ID "+#TARGETID+", has ItemFlag2 set incorrectly. Please tell a moderater, or post it on the forums.",#MSG_CRITICAL)
			GoTo END
		EndIf
		
		If PlayerStatLevel < StatLevel
			SendMessageToUser(#USERID,"You need at least "+StatLevel+" "+STATMESSAGE+" to learn this skill.",#MSG_SAY)
			GoTo END
		EndIf
	EndIf
EndIf

;Make sure the user doesn't already have this skill.
If GetUserSkill(#USERID, SkillID) > 0
	SendMessageToUser(#USERID,"You already know the "+GetSkillName(SkillID)+" skill.",#MSG_SAY)
	GoTo END
EndIf

;Make sure the user actually has the item.
If HasItem(#USERID, ITEMID) <> 1
	GoTo END
EndIf

TakeItem(#USERID, ITEMID)

SetUserSkill(#USERID, SkillID, 1)
SendMessageToUser(#USERID,"You now know the "+GetSkillName(SkillID)+" skill!",#MSG_CRITICAL)

Label END

Continue = 1