I'm new to scripting and I've been trying to find a way to make spells have item requirements in order to be cast. For example, here I'm trying to make it so you can only cast Muffle if you have a Void Salt in your inventory.
For this, I've based my script on the Transmute Ore spell (if you have iron ore in your inventory, it will do stuff. if you don't, it will do nothing).
EVENT OnEffectStart(Actor akTarget, Actor akCaster)
objectReference caster = akCaster
if caster.getItemCount(Ore02) >= 1
; favor the more valuable ore first
caster.removeItem(Ore02, 1, TRUE)
caster.addItem(Ore03, 1, FALSE)
advanceSkill("alteration",skillAdvancement)
elseif caster.getItemCount(Ore01) >= 1
; if none of that, look for the base ore to upgrade
caster.removeItem(Ore01, 1, TRUE)
caster.addItem(Ore02, 1, FALSE)
advanceSkill("alteration",skillAdvancement)
else
; caster must have had no valid ore
FailureSFX.play(caster)
failureMSG.show()
endif
endEVENT
This is the transmute ore script taken from vanilla. In xEdit, Ore02 and Ore01 are linked to the FormIDs for iron and silver ore.
Now look at my script:
Scriptname reagentDeletion extends ActiveMagicEffect
{script for spell to require the use of an item to be cast}
import game
MiscObject Property spellReagent Auto
Spell Property realSpell Auto
EVENT OnEffectStart(Actor akTarget, Actor akCaster)
objectReference caster = akCaster
if (caster.getItemCount(spellReagent) >= 1)
caster.removeItem(spellReagent, 1)
realSpell.cast(akCaster, akTarget)
else
Debug.Notification("You don't have the items required to cast this spell.")
endif
endEVENT
It's incredibly similar and also simpler than the transmute ore script. Pretty much all I've done is remove unwanted lines. The script is supposed to check whether I have enough spellReagent (linked to the FormID for Void Salts in the creation kit, the same way transmute ore does it for the iron ore), and if I do, then it casts realSpell (set to Muffle). Here's a screenshot of the magic effect in xEdit, in which my script is called: https://i.imgur.com/3dYsLss.png
The issue is, that for some reason, no matter how many Void Salts I have in my inventory, the script never goes inside of the "IF" section, it always goes into the "ELSE", and I have no idea why it does that.
If someone is able to figure out where my mistake is, I would love if you could let me know!
[LE] Script for a spell (similar to transmute ore) isn't working and I don't know why
in Creation Kit and Modders
Posted · Edited by NoobzorTM
Hello,
I'm new to scripting and I've been trying to find a way to make spells have item requirements in order to be cast. For example, here I'm trying to make it so you can only cast Muffle if you have a Void Salt in your inventory.
For this, I've based my script on the Transmute Ore spell (if you have iron ore in your inventory, it will do stuff. if you don't, it will do nothing).
This is the transmute ore script taken from vanilla. In xEdit, Ore02 and Ore01 are linked to the FormIDs for iron and silver ore.
Now look at my script:
It's incredibly similar and also simpler than the transmute ore script. Pretty much all I've done is remove unwanted lines. The script is supposed to check whether I have enough spellReagent (linked to the FormID for Void Salts in the creation kit, the same way transmute ore does it for the iron ore), and if I do, then it casts realSpell (set to Muffle). Here's a screenshot of the magic effect in xEdit, in which my script is called: https://i.imgur.com/3dYsLss.png
The issue is, that for some reason, no matter how many Void Salts I have in my inventory, the script never goes inside of the "IF" section, it always goes into the "ELSE", and I have no idea why it does that.
If someone is able to figure out where my mistake is, I would love if you could let me know!
Thanks!