Jump to content

Please help me fix this Script I dont know what I did wrong


artemissrose

Recommended Posts

Hello
I really need some help with this script ive been trying to write for the past week. Im new to scripting and I cant find any solution to what im doing wrong. If someone could please help I would really appreciate it. Im just using this for personal use nothing more.
Im trying to create a script that will allow me to add and remove a spell from the player by clicking on a static spelltome.
This is what I have so far and it might just be completely wrong I dont know
Scriptname SpellTome_Script extends activemagiceffect
Spell Property YourSpell auto
Event OnActivate(Actor akTarget, Actor akCaster)
If akTarget.HasSpell(YourSpell) == false
Debug.Notification("You have learned YourSpell!")
Game.GetPlayer().AddSpell (YourSpell)
Else
akTarget.RemoveSpell(YourSpell)
Debug.Notification("YourSpell Removed.")
Game.GetPlayer().RemoveSpell(YourSpell)
EndIf
EndEvent
Link to comment
Share on other sites

Ok Update I can get this script to compile and when I enter game to test I can learn the spell on activation and get the message but then when I click on the activator again to remove the spell nothing happens... any suggestions? could really use the help
Scriptname SpellTome_Script extends ObjectReference
; Toggle spells on player
Spell Property YourSpell Auto
ObjectReference Property LinkedRef auto
int Property myStatus auto

Event OnActivate(ObjectReference akActionRef)

If Game.GetPlayer().HasSpell(YourSpell) == true
GoToState("SpellRemoved")
Else Game.GetPlayer().HasSpell(YourSpell) == false
GoToState("SpellAdded")
EndIf

EndEvent

State SpellAdded

Event OnActivate(ObjectReference akActionRef)
Game.GetPlayer().AddSpell(YourSpell) ;Adds Spell to the player
Debug.Trace("YourSpell was Learned")
GoToState("SpellAdded")
EndEvent

EndState

State SpellRemoved

Event OnActivate(ObjectReference akActionRef)
Game.GetPlayer().RemoveSpell(YourSpell) ;Removes Spell from the Player
Debug.Trace("YourSpell was Forgotten")
GoToState("SpellRemoved")
EndEvent

EndState
Link to comment
Share on other sites

I don't know why the compiler didn't complain about your first Event. The Else statement is syntactically incorrect. Other than that, it looks fine. Could be that you forgot to fill the spell property.

 

correct version:

  Event OnActivate(ObjectReference akActionRef)
 
 If Game.GetPlayer().HasSpell(YourSpell) == true
    GoToState("SpellRemoved")
 Elseif Game.GetPlayer().HasSpell(YourSpell) == false
    GoToState("SpellAdded")
 EndIf

I changed the order because that's how the creator of papyrus said to do it, so I do it out of habit. It doesn't really affect how the states run though.

Anyway, when wanting to run multiple conditional statements, you need an elseif. else is just when all else fail(lol).

if thisValue == 0
    ;stuff
elseif thisValue == 1
    ;stuff
else
    ;stuff
endif

You can shorten the checking though in your case, and skip the else if, as well as skipping the == operator and checking for true:

Event OnActivate(ObjectReference akActionRef)
 
if Game.GetPlayer().HasSpell(YourSpell)
    GoToState("SpellRemoved")
else
    GoToState("SpellAdded")
endif
EndEvent
Edited by Rasikko
Link to comment
Share on other sites

  • 4 months later...
  • Recently Browsing   0 members

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