Jump to content

[LE] Script for a spell (similar to transmute ore) isn't working and I don't know why


NoobzorTM

Recommended Posts

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).

 

 

 

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!

 

Thanks!

Edited by NoobzorTM
Link to comment
Share on other sites

Ingredient instead of MiscObject

 

nbzreagentEffectScript

 

Scriptname nbzreagentEffectScript extends ActiveMagicEffect  
{script for spell to require the use of an item to be cast}
; https://forums.nexusmods.com/index.php?/topic/9022688-script-for-a-spell-similar-to-transmute-ore-isnt-working-and-i-dont-know-why/
     
 ;MiscObject PROPERTY spellReagent auto        ; gold001 is of type miscobject
  Ingredient PROPERTY theReagent   auto        ; the Void salt is of type ingredient
 
  Spell      PROPERTY realSpell    auto        ; the muffle spell to cast to


; https://www.creationkit.com/index.php?title=Cast_-_Spell

; -- EVENT --

EVENT OnEffectStart(Actor akTarget, Actor akCaster)

IF (akCaster == Game.GetPlayer())

    IF (akCaster.GetItemCount(theReagent) > 0)
        akCaster.RemoveItem(theReagent, 1)
        realSpell.Cast(akCaster, akTarget)            ; cast muffle from player
    ELSE
        Debug.Notification("You don't have the items required to cast this spell.")
    ENDIF

ENDIF
ENDEVENT

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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