Jump to content

Script issue need help please


Ninjaluxray7685

Recommended Posts

so i have been letting chatgpt teach me how to script because i couldn't find a video to teach me how to create a 1-20 chance roll system for a object to simulate rolling a d20 but for what ever reason its failing the save with a error 

here is my script and screenshot of my work can some one please help me im getting annoyed trying to make this work error i get is "ApplySpell is not a function or does not exist" or when i change applyspell > cast i get "Cast is not a function or does not exist"

Spoiler

Scriptname SaintCastTreasureScript extends ObjectReference

MiscObject Property SaintCastTreasure Auto ; Reference to the Saint Cast Treasure item
Weapon Property BladeOfDestiny Auto ; Reference to the Blade of Destiny
Spell Property StunEffect Auto ; Reference to the Stun spell/effect
Spell Property FearEffect Auto ; Reference to the Fear spell/effect
Spell Property CritFailEffect Auto ; Reference to the Crit Fail effect (e.g., summon a Dremora)
Spell Property BoostEffect Auto ; Reference to the temporary stat boost effect
Spell Property InstantKillEffect Auto ; Reference to the Instant Kill effect
Message Property MsgCritFail Auto ; Reference to the Crit Fail message box
Message Property MsgStun Auto ; Reference to the Stun message box
Message Property MsgFear Auto ; Reference to the Fear message box
Message Property MsgBoost Auto ; Reference to the Boost message box
Message Property MsgInstantKill Auto ; Reference to the Instant Kill message box
Message Property MsgDrainMagickaStamina Auto ; Reference to the Drain Magicka and Stamina message box
Form Property Gold001 Auto ; Reference to the gold item
Form Property DragonBone Auto ; Reference to the Dragon Bone item
Form Property DaedraHeart Auto ; Reference to the Daedra Heart item
Form Property DragonScales Auto ; Reference to the Dragon Scales item

Event OnEquipped(Actor akActor)
    ; Only run the script if the player interacts with the Saint Cast Treasure
    if akActor == Game.GetPlayer()
        int rollResult = Utility.RandomInt(1, 20)
        
        ; Handle the different roll outcomes
        if rollResult == 1
            MsgCritFail.Show()
            akActor.Cast(CritFailEffect, akActor) ; Apply Crit Fail Effect (e.g., summon a Dremora)
        elseif rollResult >= 2 && rollResult <= 6
            MsgDrainMagickaStamina.Show()
            akActor.DamageActorValue("Magicka", 50)
            akActor.DamageActorValue("Stamina", 50)
        elseif rollResult >= 7 && rollResult <= 11
            MsgStun.Show()
            akActor.Cast(StunEffect, akActor) ; Apply Stun Effect directly to the actor
        elseif rollResult >= 12 && rollResult <= 17
            MsgFear.Show()
            akActor.Cast(FearEffect, akActor) ; Apply Fear Effect directly to the actor
        elseif rollResult >= 18 && rollResult <= 19
            MsgBoost.Show()
            akActor.Cast(BoostEffect, akActor) ; Apply Boost Effect directly to the actor
        elseif rollResult == 20
            MsgInstantKill.Show()
            akActor.Cast(InstantKillEffect, akActor) ; Apply Instant Kill Effect directly to the actor
            ; Add rewards to the player
            Game.GetPlayer().AddItem(Gold001, 250)
            Game.GetPlayer().AddItem(DragonBone, 1)
            Game.GetPlayer().AddItem(DaedraHeart, 1)
            Game.GetPlayer().AddItem(DragonScales, 3)
        endif
    endif
EndEvent
 

Screenshot2024-09-02060244.thumb.png.09bd31747f0f061223b2f93c8572f656.png

Edited by redlink32
Link to comment
Share on other sites

The correct syntax for Cast is:

mySpell.Cast(mySource,myTarget)

The reason it is creating an error is that Cast is a function on the Spell script rather than the Actor script.  Thus having the actor call Cast results in the error you are seeing.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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