Jump to content

[LE] Making a modded spell that costs items per use


Smegmeister

Recommended Posts

I'm very new to modding Skyrim and I'm planning on making a set of modded spells that require an item to cast. For example, a powerful fire spell that requires fire salt before it can be cast, and after casting removes the fire salt from the player inventory. I can't seem to figure out how to do this, and I can't find any tutorials that touch this subject. Could this be done without custom scripts? Or should I look into custom scripting to resolve this?
Link to comment
Share on other sites

Yes. Definitely doable.

 

In the magic effect of the spell you could use a condition.

 

I think 'GetItemCount', 'FireSalts', >=, 1.0 should work, run on 'Player', selected from the drop-down box.

 

Then the spell cannot be cast unless the player has at least 1 FireSalts item.

 

Next you'd need a script.

 

Put it in the papyrus fragment of the magic effect.

 

 

Scriptname MySuperSpellScript extends ActiveMagicEffect
{Every time this spell is cast it removes an item from the player.}

 

Spell Property MySuperSpell Auto; this property will need to be entered manually, unless the spell ID is 'MySuperSpell'

Ingredient Property FireSalts Auto; this property will auto-fill

Actor Property PlayerRef Auto; this property will auto-fill

 

Event OnSpellCast(Form akSpell); the event that needs to happen for us to use the script

Spell spellCast = akSpell as Spell
If SpellCast && SpellCast == MySuperSpell; has a spell been cast and is it the spell we're concerned with?
PlayerRef.RemoveItem(FireSalts); removes the item from the player inventory
Endif

EndEvent

 

 

Now just create the spell and spell tome following regular tutorials

 

You don't need to restrict yourself to Fire Salts. The item could be anything, as long as you set the property correctly. things like soul gems are 'MiscObject' properties. Likewise, call the properties whatever you like. Calling the property 'Firesalts' helps in this case, because you can click on the 'Auto Fill' button in the properties box and it will put it in for you. Same with your spell. If the ID of the spell is something other than 'MySuperSpell', you'd have to search for your spell when assigning the property to the script.

 

It's best to keep the properties something generic like 'MySpell' and 'MyItemToBeTaken' so that the script looks reasonable if you want to use it for 3 different spells and 3 different miscellaneous items.

 

you don't need my remarks (the semi-colons and text after it.)

Link to comment
Share on other sites

cumbrianlad

Your script has one mistake, is not "MiscObject" but "Ingredient Property".


The use of "Game.GetPlayer()" is ok when it comes for a single use, but when it comes to call for the "Actor = Player" multiple times in one script session or in the case of a spell that will be use multiple times by the player, it's better to defind the "Actor = Player" in the scripts Property " Actor Property PlayerREF Auto".


The reason behind this is that the "PlayerREF" is a 1000 faster, and the continuous use of the "Game.GetPlayer()" will slow down / lag your game noticeably.

* Sometimes can even cause other scripts that might run at the same time while you are calling "Game.GetPlayer()" repeatedly to not fire due to the game lag.

Edited by maxarturo
Link to comment
Share on other sites

After a few hours of trials, tribulations, and misreading instructions, I am at a loss of what to do. I've tried the script provided, modifying it, and even other scripts I could find online; but not having the item needed in the inventory doesn't stop the spell from casting, and casting the spell doesn't remove the item from the inventory when it is present. The spell won't deal damage when the needed item isn't present, so that's a plus, but it still isn't what I want from the spell.

This is my current script I compiled after finding a similar topic:
Scriptname RailgunSpellScript extends activemagiceffect Conditional
'Casting this spell removes a gold coin from the player'
{Scriptname RailgunSpellScript extends ActiveMagicEffect
MiscObject property Gold001 Auto
Int GoldCount = akCaster.GetItemCount(Gold001)
'if player has 0 gold, spell can't be cast'
if GoldCount == 0
akCasster.InterruptCast()
else
'if spell is cast, remove a gold coin from player inventory'
Game.getPlayer().RemoveItem(Gold001, 1)
endif
EndEvent}
Link to comment
Share on other sites

Hey Smegmeister,

 

You would need to put the condition on the spell template, not in a script.

 

The script you have there does not even look like it would compile.

 

You have no event.

 

Put this script on the magiceffect of your spell and compile it.

 

Then:

Cast your spell at the wall ( not an NPC ) and tell us what message appears on the screen.

Cast your spell at an NPC and tell us what message appears on the screen.

Scriptname AMEtestscript extends activemagiceffect  

Event OnEffectStart(Actor akTarget, Actor akCaster)

Debug.Notification("Effect Started")

EndEvent

Event OnSpellCast(Form akSpell)

Debug.Notification("Spell Cast")

endEvent
Edited by SurfsideNaturals
Link to comment
Share on other sites

When I cast the spell on the wall I didn't receive any message and when I hit an NPC I received a message saying they resisted the spell (which happened previously, but I forgot to mention it), but no "Spell Cast" message.

It may sound stupid and naive of me, but I went into this fairly blind and didn't consider starting off of a fresh reinstall, so I'll do that and come back with the results.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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