Jump to content

Unequip Spell if requirements not met


Rizalgar

Recommended Posts

Okay, so I'm making some custom skills with custom spells based on those skills. Basically, I need a level requirement for each spell, but, I'm not quite sure how to force unequip the spell if the requirements aren't met. I've tried several different methods to no avail. Any help on the topic would be appreciated.

 

Here's one of the methods I've tried -

Event OnSpellEquip(Spell akSpell)

	Int cMag = RS_GV_MagicLvl.GetValue() as Int

	If (PlayerRef.GetEquippedItemType(1) == 9)
		EquippedSpell = PlayerRef.GetEquippedSpell(1)
		
		If cMag < rMag
			PlayerRef.UnequipSpell(EquippedSpell, 1)
		EndIf
		
	EndIf

EndEvent

Another one I've tried

Event OnEquipped(Actor akActor)

	Int cMag = RS_GV_MagicLvl.GetValue() as Int

	Spell eSpell = PlayerRef.GetEquippedSpell(1)

	If akActor == PlayerRef
	
		If cMag < rMag
			PlayerRef.UnequipSpell(eSpell, 1)
		EndIf
	EndIf
	
EndEvent
Edited by Rizalgar
Link to comment
Share on other sites

I've gotten it to work with weapon equips using this script

 

 

 

Scriptname RS_FW_WeaponEquips extends ObjectReference  
{Handles requirements and stats}

;;hidden
GlobalVariable Property RS_Check_Statlock Auto Hidden

;;Stat Globals
GlobalVariable Property RS_GV_AttackLVL Auto
GlobalVariable Property RS_GV_StrengthLVL Auto
GlobalVariable Property RS_GV_RangedLVL Auto
GlobalVariable Property RS_GV_MagicLVL Auto
GlobalVariable Property RS_GV_PrayerLVL Auto

;;Weapon Bonuses
GlobalVariable Property RS_GV_AttackBonus Auto
GlobalVariable Property RS_GV_StrengthBonus Auto
GlobalVariable Property RS_GV_RangedBonus Auto
GlobalVariable Property RS_GV_MagicBonus Auto
GlobalVariable Property RS_GV_PrayerBonus Auto

;;Possible quest requirement
Quest Property ReqQ Auto

;;Possible level requirement
Int Property rAttackLvl Auto
Int Property rStrengthLVL Auto
Int Property rRangedLVL Auto
Int Property rMagicLVL Auto
Int Property rPrayerLVL Auto

;;Stat Bonuses
Int Property AttackBonus Auto
Int Property StrengthBonus Auto
Int Property RangedBonus Auto
Int Property MagicBonus Auto
Int Property PrayerBonus Auto

Int Property DamMin Auto
Int Property DamMax Auto

bool bCrashLock = False

Event OnEquipped(Actor akActor)

	If akActor == Game.GetPlayer()
		Weapon lefthand = akActor.GetEquippedWeapon(true)
		akActor.UnequipItem(lefthand, true, true)
		
		If RS_Check_Statlock.GetValue() != 0
			Weapon righthand = akActor.GetEquippedWeapon()
			akActor.UnequipItem(righthand, true, true)
			Debug.MessageBox("Item equip error! Unequipping")
		Else
			If ReqQ == none
				If RS_GV_AttackLVL.GetValue() < rAttackLvl
					bCrashLock == true
					Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
					akActor.UnequipItem(righthand, true, true)
					Debug.Notification("You lack the required Attack level to equip this!")
				ElseIf RS_GV_StrengthLVL.GetValue() < rStrengthLVL
					bCrashLock == true
					Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
					akActor.UnequipItem(righthand, true, true)
					Debug.Notification("You lack the required Strength level to equip this!")
				ElseIf RS_GV_RangedLVL.GetValue() < rRangedLVL
					bCrashLock == true
					Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
					akActor.UnequipItem(righthand, true, true)
					Debug.Notification("You lack the required Ranged level to equip this!")
				ElseIf RS_GV_MagicLVL.GetValue() < rMagicLVL
					bCrashLock == true
					Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
					akActor.UnequipItem(righthand, true, true)
					Debug.Notification("You lack the required Magic level to equip this!")
				ElseIf RS_GV_PrayerLVL.GetValue() < rPrayerLVL
					bCrashLock == true
					Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
					akActor.UnequipItem(righthand, true, true)
					Debug.Notification("You lack the required Prayer level to equip this!")
				Else 
					bCrashLock == false
					ApplyStats(true)
				EndIf
			Else
				If ReqQ.IsCompleted() == false
					Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
					akActor.UnequipItem(righthand, true, true)
					Debug.Notification("You need to complete the Quest '" + ReqQ.GetName() + "' before you can equip this.")
				Else
					If RS_GV_AttackLVL.GetValue() < rAttackLvl
						bCrashLock == true
						Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
						akActor.UnequipItem(righthand, true, true)
						Debug.Notification("You lack the required Attack level to equip this!")
					ElseIf RS_GV_StrengthLVL.GetValue() < rStrengthLVL
						bCrashLock == true
						Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
						akActor.UnequipItem(righthand, true, true)
						Debug.Notification("You lack the required Strength level to equip this!")
					ElseIf RS_GV_RangedLVL.GetValue() < rRangedLVL
						bCrashLock == true
						Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
						akActor.UnequipItem(righthand, true, true)
						Debug.Notification("You lack the required Ranged level to equip this!")
					ElseIf RS_GV_MagicLVL.GetValue() < rMagicLVL
						bCrashLock == true
						Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
						akActor.UnequipItem(righthand, true, true)
						Debug.Notification("You lack the required Magic level to equip this!")
					ElseIf RS_GV_PrayerLVL.GetValue() < rPrayerLVL
						bCrashLock == true
						Weapon righthand = Game.GetPlayer().GetEquippedWeapon()
						akActor.UnequipItem(righthand, true, true)
						Debug.Notification("You lack the required Prayer level to equip this!")
					Else 
						bCrashLock == false
						ApplyStats(true)
					EndIf
				EndIf
			EndIf
		EndIf
	EndIf
	
EndEvent

Event OnUnEquipped(actor akActor)
	if bCrashLock == true
		;do nothing
	else
		;debug.trace("Event OnUnEquipped fired!!")
		if RS_Check_StatLock.GetValue() != 0
			debug.messagebox("Equip error 002")
		else
			;Utility.Wait(2.0)
			ApplyStats(false)
		endif
	endif
EndEvent

Function ApplyStats(bool bApply)

	RS_Check_StatLock.SetValue(1)
		
	If bApply == true			
		RS_GV_AttackBonus.SetValue((RS_GV_AttackBonus.GetValue() + AttackBonus))
		RS_GV_StrengthBonus.SetValue((RS_GV_StrengthBonus.GetValue() + StrengthBonus))
		RS_GV_RangedBonus.SetValue((RS_GV_RangedBonus.GetValue() + RangedBonus))
		RS_GV_MagicBonus.SetValue((RS_GV_MagicBonus.GetValue() + MagicBonus))
		RS_GV_PrayerBonus.SetValue((RS_GV_PrayerBonus.GetValue() + PrayerBonus))
	ElseIf bApply == False		
		RS_GV_AttackBonus.SetValue(0)
		RS_GV_StrengthBonus.SetValue(0)
		RS_GV_MagicBonus.SetValue(0)
		RS_GV_RangedBonus.SetValue(0)
		RS_GV_PrayerBonus.SetValue(0)
	Else
		RS_GV_AttackBonus.SetValue((RS_GV_AttackBonus.GetValue() - AttackBonus))
		RS_GV_StrengthBonus.SetValue((RS_GV_StrengthBonus.GetValue() - StrengthBonus))
		RS_GV_RangedBonus.SetValue((RS_GV_RangedBonus.GetValue() - RangedBonus))
		RS_GV_MagicBonus.SetValue((RS_GV_MagicBonus.GetValue() - MagicBonus))
		RS_GV_PrayerBonus.SetValue((RS_GV_PrayerBonus.GetValue() - PrayerBonus))	
	EndIf
	
	RS_Check_StatLock.SetValue(0)

EndFunction 

 

 

 

I just can't get it to work with spell equips

Edited by Rizalgar
Link to comment
Share on other sites

Bump

 

I'm getting beyond frustrated. I can't get this to work. I can't even get it to detect when the player equips the spell. Anyone?

 

My latest attempt, attached to a start game enabled quest,

Event OnEquipped(Actor akActor)

	Spell WindStrike = RS_Spell_WindStrike
	Debug.Notification("Wind strike equipped")
	If akActor == PlayerRef
		If (PlayerRef.GetEquippedItemType(1) == 9)
			Spell eSpell = PlayerRef.GetEquippedSpell(1)
			If eSpell == WindStrike
				GSR("WindStrike", None, 10, 1, 0, 0, 0, 0, 0)
			EndIf
		Else
			Debug.MessageBox("Error determing equip")
		EndIf
	EndIf
	
EndEvent

Edit

 

For anyone who ever has the same idea in mind, note that after hours of trial and error I couldn't find a way to unequip a spell on equip if requirements weren't met. I found it 100x times easier and less stressful to take the easy cheap route of having a dummy spell do the checks and then unequip it if it doesn't pass, then cast the actual spell if it does. If someone does find a way though, be sure to hit me up.

Edited by Rizalgar
Link to comment
Share on other sites

I want to say I tried that, in many different forms, including

 

 

Script examplescript Extends Actor

Actor Property PlayerRef Auto
Spell Property RS_Spell_Example Auto

Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)

    If akBaseObject as Spell
        Spell eSpell = PlayerRef.GetEquippedSpell(1)
        Debug.Notification("Player has equipped " + eSpell")
    EndIf

EndEvent

 

 

as well as calling the event without the Spell eSpell, to no avail. Maybe I'm just not setting up the triggering for it properly?

 

I have also tried it as

 

 

 

Scriptname somescriptexample Extends Actor

Actor Property PlayerRef Auto

Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)

    If akBaseObject as Spell
        If (PlayerRef.GetEquippedItemType(1) == 7)
            Debug.Notification("Spell equipped in left hand")
        EndIf
    EndIf

EndEvent

 

 

Link to comment
Share on other sites

I'm gonna toss out more options for you to try.

 

-Condition Functions

GetEquippedItemType

You already know the script version

 

isWeaponMagicOut - checks if a weapon or spell is equipped

Script Version: https://www.creationkit.com/index.php?title=IsWeaponDrawn_-_Actor

 

You're probably better off using a condition and place it in an ability that is on the player, so that it checks every second for spells being equipped. Then you can use OnEffectStart event to check what kind of spell is equipped.

Link to comment
Share on other sites

Huzzah! Breakthrough. All works now! For any googlers coming across this, this is how you can force unequip a spell if you don't meet requirements.

 

Attach this to an ability given to the player, with the spell condition IsWeaponMagicOut == 1

 

 

 

Scriptname RS_FW_SpellEquips extends ActiveMagicEffect
{Handles spell requirements}

Actor Property PlayerRef Auto
RS_FW_Magic Property Controller Auto
GlobalVariable Property RS_GV_MagicLvl Auto
Spell Property RS_Spell_WindStrike Auto
Event OnEffectStart(Actor target, actor caster)

	RegisterForUpdate(1.0)
	
EndEvent
Event OnUpdate()

	GoToState("OOE")
	Debug.Notification("Going to state")
	
EndEvent

State OOE

Event OnBeginState()

	Int Current = RS_GV_MagicLvl.GetValue() as Int

	bool isOut = PlayerRef.IsWeaponDrawn()

	Spell eSpell = PlayerRef.GetEquippedSpell(1)
	Debug.Notification("Got the spell equip check")
		
	If eSpell == RS_Spell_WindStrike
		Controller.BSDC("WindStrike", None, Current, 10, 1, 0, 0, 0)
		Debug.Notification("WindStrike is equipped")
	Endif
	
EndEvent

EndState 

 

 

 

Then, attach this script to a start enabled, always running quest

 

 

 

Scriptname RS_FW_Magic extends Quest

Actor Property PlayerRef Auto

Spell Property RS_Spell_WindStrike Auto

Function BSDC(String sName, Quest rQuest, Int cLvl, Int rLvl, Int Air, Int Water, Int Earth, Int Fire)
	
	Spell WindStrike = RS_Spell_WindStrike as Spell
	
	If sName == "WindStrike"
		If rQuest == None
			Debug.Notification("Quest Check Pass")
			If cLvl < rLvl
				Debug.Notification("Level Check Pass, unequipping")
				PlayerRef.UnequipSpell(WindStrike, 1)
			ElseIf "Air" < 1
				Debug.Notification("Rune Check Pass, unequipping")
			EndIf
		EndIf
	EndIf
	
EndFunction

 

 

Edited by Rizalgar
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...