Jump to content

Help with scripting


Sargrifal

Recommended Posts

Hello everyone, I trying to start writing scripts, and still newbie, so have trouble with it)
Tried to make script which make NPC or Player playing animations when they are equipe Item until then it was unequipped, but I failed at compile, can someone help with right looking script?

Scriptname FluidAnims extends ObjectReference
ObjectReference Property fluid Auto
Actor Property PlayerRef Auto
Event OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)
If akBaseObject == EFfluid
SendAnimationEvent(PlayerRef, "EFFstop")
EndIf
Utility.Wait(20)
PlayerRef.PlayIdle(IdleStop_Loose)
EndEvent
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
If akBaseObject == EFfluid
SendAnimationEvent(PlayerRef, "EFF")
EndIf
Utility.Wait(20)
PlayerRef.PlayIdle(IdleStop_Loose)
EndEvent

And compile failed because:
Starting 1 compile threads for 1 files...
Compiling "FluidAnims"...
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(8,0): SendAnimationEvent is not a function or does not exist
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(11,19): variable IdleStop_Loose is undefined
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(16,0): SendAnimationEvent is not a function or does not exist
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(19,19): variable IdleStop_Loose is undefined
No output generated for FluidAnims, compilation failed.
Edited by colourtemp3000
Link to comment
Share on other sites

Unless a script that contains a desired function is imported in the empty state, it needs to have the host script called so that papyrus knows where to look for the desired function

 

You can use one of the following:

Import Debug ;goes in the empty state where properties are defined

or

Debug.SendAnimationEvent(SomeObjectRef,"SomeAnimation") ;goes inside a function or event
Link to comment
Share on other sites

T

 

 

Hello everyone, I trying to start writing scripts, and still newbie, so have trouble with it)
Tried to make script which make NPC or Player playing animations when they are equipe Item until then it was unequipped, but I failed at compile, can someone help with right looking script?

Scriptname FluidAnims extends ObjectReference
ObjectReference Property fluid Auto
Actor Property PlayerRef Auto
Event OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)
If akBaseObject == EFfluid
SendAnimationEvent(PlayerRef, "EFFstop")
EndIf
Utility.Wait(20)
PlayerRef.PlayIdle(IdleStop_Loose)
EndEvent
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
If akBaseObject == EFfluid
SendAnimationEvent(PlayerRef, "EFF")
EndIf
Utility.Wait(20)
PlayerRef.PlayIdle(IdleStop_Loose)
EndEvent

And compile failed because:
Starting 1 compile threads for 1 files...
Compiling "FluidAnims"...
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(8,0): SendAnimationEvent is not a function or does not exist
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(11,19): variable IdleStop_Loose is undefined
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(16,0): SendAnimationEvent is not a function or does not exist
D:\Skyrim SE\Data\Source\Scripts\temp\FluidAnims.psc(19,19): variable IdleStop_Loose is undefined
No output generated for FluidAnims, compilation failed.

Thank you, but "variable IdleStop_Loose is undefined" still here and script wont work, can you tell me why it can happened?

Link to comment
Share on other sites

From the Creation Kit wiki notes on SendAnimationEvent:

 

 

  • SendAnimationEvent uses "Anim Events" under the Idle Manager, not the IDs. For example, to make an actor play the animation of attacking left, you must use "AttackStartLeftHand", not "LeftHandAttack" (its ID).

 

What this means is that you need to access the Idle Manager in the Creation Kit and find the correct animation. The editor ID of IdleStop_Loose will not work.

Link to comment
Share on other sites

You should accept some papyrus rules.

 

(1) your property name

ObjectReference Property fluid Auto

does not match with next condition code

If akBaseObject == EFfluid

(2) using of next property

Actor Property PlayerRef Auto

does not really make sense with your event codes, for example

 

Event OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)

If akBaseObject == EFfluid
    SendAnimationEvent(PlayerRef, "EFFstop")
EndIf

    Utility.Wait(20) 
    PlayerRef.PlayIdle(IdleStop_Loose) 
EndEvent

 

 

You forget the actor check. By running your script code the player makes the animation always (regardeless which actor is wearing the special item) .

 

(3) a long wait (here 20 seconds ingame time) within an OnObjectUnEquipped() or/and OnObjectEquipped() event is really bad

Utility.Wait(20)

Please avoid such waitings!

 

(4) you cannot compare an OjectReference property with a BaseObject, it does not work!

If akBaseObject == EFfluid

(5) I changed your posted code sample as follow. Keep in mind: "Use a better unique scriptname to avoid any trouble with scripts from other mods!"

colo_FluidAnimationScript

 

;Scriptname colo_FluidAnimationScript extends ObjectReference
Scriptname colo_FluidAnimationScript extends Actor        ; (7) added 2022-01-31
; https://forums.nexusmods.com/index.php?/topic/10877768-help-with-scripting/
 
  ObjectReference PROPERTY EFfluidRef auto        ; the object we are looking for
  Idle            PROPERTY IdleStop_Loose auto            ; (6) added 2022-01-31, missing in older post


; -- EVENTs --

;EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) ; (7) this event does not work for actor type
;    IF (akNewContainer == Game.GetPlayer() as ObjectReference)
;        gotoState("Waiting")        ; ### STATE ###  player got the item, observe equip now
;    ELSE
;        UnRegisterForUpdate()  ; just in case
;        gotoState("")               ; ### STATE ###
;    ENDIF
;ENDEVENT


EVENT OnUpdate()
    Game.GetPlayer().PlayIdle(IdleStop_Loose)             ; after 20 sec the item is wearing play vanilla stop animation
    Utility.Wait(0.1)
ENDEVENT

EVENT OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
    IF (akBaseObject == EFfluidRef.GetBaseObject())
        gotoState("WearItem")    ; ### STATE ###
        myF_Action(1)
        RegisterForSingleUpdate(20.0)                 ; wait for 20 sec
    ENDIF
ENDEVENT


;===================================
State WearItem
;=============
    EVENT OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)
        IF (akBaseObject == EFfluidRef.GetBaseObject())
            UnRegisterForUpdate()
            gotoState("")        ; ### STATE ###
            myF_Action(0)
        ENDIF
    ENDEVENT
;=======
endState


; -- FUNCTION --

;-------------------------
FUNCTION myF_Action(Int i)
;-------------------------
    IF ( i )    ; i == 1
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFF")        ; if item equipped play special animation
    ELSE        ; i == 0
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFFstop")    ; if item will be un-equipped play special stop animation
    ENDIF
ENDFUNCTION

 


(6) Idle property was missing as well

Idle PROPERTY IdleStop_Loose auto ; added 2022-01-31, missing in older post

(7) scriptname was wrong type extending

Scriptname colo_FluidAnimationScript extends Actor  ; changed 2022-01-31
Edited by ReDragon2013
Link to comment
Share on other sites

  • 3 weeks later...

You should accept some papyrus rules.

 

(1) your property name

ObjectReference Property fluid Auto

does not match with next condition code

If akBaseObject == EFfluid

(2) using of next property

Actor Property PlayerRef Auto

does not really make sense with your event codes, for example

 

Event OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)

If akBaseObject == EFfluid
    SendAnimationEvent(PlayerRef, "EFFstop")
EndIf

    Utility.Wait(20) 
    PlayerRef.PlayIdle(IdleStop_Loose) 
EndEvent

 

 

You forget the actor check. By running your script code the player makes the animation always (regardeless which actor is wearing the special item) .

 

(3) a long wait (here 20 seconds ingame time) within an OnObjectUnEquipped() or/and OnObjectEquipped() event is really bad

Utility.Wait(20)

Please avoid such waitings!

 

(4) you cannot compare an OjectReference property with a BaseObject, it does not work!

If akBaseObject == EFfluid

(5) I changed your posted code sample as follow. Keep in mind: "Use a better unique scriptname to avoid any trouble with scripts from other mods!"

colo_FluidAnimationScript

 

Scriptname colo_FluidAnimationScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/10877768-help-with-scripting/
 
  ObjectReference PROPERTY EFfluidRef auto        ; the object we are looking for


; -- EVENTs --

EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
    IF (akNewContainer == Game.GetPlayer() as ObjectReference)
        gotoState("Waiting")        ; ### STATE ###  player got the item, observe equip now
    ELSE
        UnRegisterForUpdate()  ; just in case
        gotoState("")               ; ### STATE ###
    ENDIF
ENDEVENT


EVENT OnUpdate()
    Game.GetPlayer().PlayIdle(IdleStop_Loose)             ; after 20 sec the item is wearing play vanilla stop animation
    Utility.Wait(0.1)
ENDEVENT


;===================================
State Waiting
;============
    EVENT OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
        IF (akBaseObject == EFfluidRef.GetBaseObject())
            gotoState("WearItem")    ; ### STATE ###
            myF_Action(1)
            RegisterForSingleUpdate(20.0)                 ; wait for 20 sec
        ENDIF
    ENDEVENT
;=======
endState


;===================================
State WearItem
;=============
    EVENT OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)
        IF (akBaseObject == EFfluidRef.GetBaseObject())
            UnRegisterForUpdate()
            gotoState("Waiting")    ; ### STATE ###
            myF_Action(0)
        ENDIF
    ENDEVENT
;=======
endState


; -- FUNCTION --

;-------------------------
FUNCTION myF_Action(Int i)
;-------------------------
    IF ( i )    ; i == 1
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFF")        ; if item equipped play special animation
    ELSE        ; i == 0
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFFstop")    ; if item will be un-equipped play special stop animation
    ENDIF
ENDFUNCTION

 

 

 

Thank you very much, Ill try it soon, just backed from another country

Link to comment
Share on other sites

  • 2 weeks later...

 

You should accept some papyrus rules.

 

(1) your property name

ObjectReference Property fluid Auto

does not match with next condition code

If akBaseObject == EFfluid

(2) using of next property

Actor Property PlayerRef Auto

does not really make sense with your event codes, for example

 

Event OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)

If akBaseObject == EFfluid
    SendAnimationEvent(PlayerRef, "EFFstop")
EndIf

    Utility.Wait(20) 
    PlayerRef.PlayIdle(IdleStop_Loose) 
EndEvent

 

 

You forget the actor check. By running your script code the player makes the animation always (regardeless which actor is wearing the special item) .

 

(3) a long wait (here 20 seconds ingame time) within an OnObjectUnEquipped() or/and OnObjectEquipped() event is really bad

Utility.Wait(20)

Please avoid such waitings!

 

(4) you cannot compare an OjectReference property with a BaseObject, it does not work!

If akBaseObject == EFfluid

(5) I changed your posted code sample as follow. Keep in mind: "Use a better unique scriptname to avoid any trouble with scripts from other mods!"

colo_FluidAnimationScript

 

Scriptname colo_FluidAnimationScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/10877768-help-with-scripting/
 
  ObjectReference PROPERTY EFfluidRef auto        ; the object we are looking for
  Idle            PROPERTY IdleStop_Loose auto    ; added 2022-01-31, missing in older post


; -- EVENTs --

EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
    IF (akNewContainer == Game.GetPlayer() as ObjectReference)
        gotoState("Waiting")        ; ### STATE ###  player got the item, observe equip now
    ELSE
        UnRegisterForUpdate()  ; just in case
        gotoState("")               ; ### STATE ###
    ENDIF
ENDEVENT


EVENT OnUpdate()
    Game.GetPlayer().PlayIdle(IdleStop_Loose)             ; after 20 sec the item is wearing play vanilla stop animation
    Utility.Wait(0.1)
ENDEVENT


;===================================
State Waiting
;============
    EVENT OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
        IF (akBaseObject == EFfluidRef.GetBaseObject())
            gotoState("WearItem")    ; ### STATE ###
            myF_Action(1)
            RegisterForSingleUpdate(20.0)                 ; wait for 20 sec
        ENDIF
    ENDEVENT
;=======
endState


;===================================
State WearItem
;=============
    EVENT OnObjectUnEquipped(Form akBaseObject, ObjectReference akReference)
        IF (akBaseObject == EFfluidRef.GetBaseObject())
            UnRegisterForUpdate()
            gotoState("Waiting")    ; ### STATE ###
            myF_Action(0)
        ENDIF
    ENDEVENT
;=======
endState


; -- FUNCTION --

;-------------------------
FUNCTION myF_Action(Int i)
;-------------------------
    IF ( i )    ; i == 1
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFF")        ; if item equipped play special animation
    ELSE        ; i == 0
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFFstop")    ; if item will be un-equipped play special stop animation
    ENDIF
ENDFUNCTION

 

 

(6) Idle property was missing as well

Idle PROPERTY IdleStop_Loose auto ; added 2022-01-31, missing in older post

@ReDragon2013 Thank your for PM answer, I already fixed "variable IdleStop_Loose is undefined", just before I send PM to you, I cant understand that

D:\Skyrim SE\Data\Source\Scripts\temp\scriptname.psc(28,4): function onobjectequipped cannot be defined in state waiting without also being defined in the empty state

D:\Skyrim SE\Data\Source\Scripts\temp\scriptname.psc(42,4): function onobjectunequipped cannot be defined in state wearitem without also being defined in the empty state

May be it is unnecessary to fix that, I dont know

(and about script name I use "scriptname.psc" just like example, not exist name)

Edited by colourtemp3000
Link to comment
Share on other sites

Hmm.. to get them work you have to change the script from extending objectReference into actor (I edited my previous posting)!

But that is out of "good coding practice" for the player or any other unique vanilla actor.

https://www.creationkit.com/index.php?title=OnObjectEquipped_-_Actor

So we have to change the whole script as follow.

https://www.creationkit.com/index.php?title=OnEquipped_-_ObjectReference

 

colo_FluidAnimationScript v2

 

Scriptname colo_FluidAnimationScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/10877768-help-with-scripting/
; version 2

  Idle PROPERTY IdleStop_Loose auto    ; added 2022-01-31, missing in older post


; -- EVENTs -- 2 + "Waiting" + "WearItem"

EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
    IF (akNewContainer == Game.GetPlayer() as ObjectReference)
        gotoState("Waiting")        ; ### STATE ###  player got the item, observe equip now
    ELSE
        UnRegisterForUpdate()  ; just in case
        gotoState("")               ; ### STATE ###
    ENDIF
ENDEVENT


EVENT OnUpdate()
    Game.GetPlayer().PlayIdle(IdleStop_Loose)         ; after 20 sec the item is wearing, play vanilla stop animation
    Utility.Wait(0.1)
ENDEVENT


;===================================
State Waiting
;============
    EVENT OnEquipped(Actor akActor)
        gotoState("WearItem")    ; ### STATE ###
        myF_Action(1)
        RegisterForSingleUpdate(20.0)                 ; wait for 20 sec
    ENDEVENT
;=======
endState


;===================================
State WearItem
;=============
    EVENT OnUnEquipped(Actor akActor)
        UnRegisterForUpdate()
        gotoState("Waiting")    ; ### STATE ###
        myF_Action(0)
    ENDEVENT
;=======
endState


; -- FUNCTION --

;-------------------------
FUNCTION myF_Action(Int i)
;-------------------------
    IF ( i )    ; i == 1
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFF")        ; if item equipped play special animation
    ELSE        ; i == 0
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFFstop")    ; if item will be un-equipped play special stop animation
    ENDIF
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

Hmm.. to get them work you have to change the script from extending objectReference into actor (I edited my previous posting)!

But that is out of "good coding practice" for the player or any other unique vanilla actor.

https://www.creationkit.com/index.php?title=OnObjectEquipped_-_Actor

 

So we have to change the whole script as follow.

https://www.creationkit.com/index.php?title=OnEquipped_-_ObjectReference

 

colo_FluidAnimationScript v2

 

Scriptname colo_FluidAnimationScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/10877768-help-with-scripting/
; version 2

  Idle PROPERTY IdleStop_Loose auto    ; added 2022-01-31, missing in older post


; -- EVENTs -- 2 + "Waiting" + "WearItem"

EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
    IF (akNewContainer == Game.GetPlayer() as ObjectReference)
        gotoState("Waiting")        ; ### STATE ###  player got the item, observe equip now
    ELSE
        UnRegisterForUpdate()  ; just in case
        gotoState("")               ; ### STATE ###
    ENDIF
ENDEVENT


EVENT OnUpdate()
    Game.GetPlayer().PlayIdle(IdleStop_Loose)         ; after 20 sec the item is wearing, play vanilla stop animation
    Utility.Wait(0.1)
ENDEVENT


;===================================
State Waiting
;============
    EVENT OnEquipped(Actor akActor)
        gotoState("WearItem")    ; ### STATE ###
        myF_Action(1)
        RegisterForSingleUpdate(20.0)                 ; wait for 20 sec
    ENDEVENT
;=======
endState


;===================================
State WearItem
;=============
    EVENT OnUnEquipped(Actor akActor)
        UnRegisterForUpdate()
        gotoState("Waiting")    ; ### STATE ###
        myF_Action(0)
    ENDEVENT
;=======
endState


; -- FUNCTION --

;-------------------------
FUNCTION myF_Action(Int i)
;-------------------------
    IF ( i )    ; i == 1
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFF")        ; if item equipped play special animation
    ELSE        ; i == 0
        Debug.SendAnimationEvent(Game.GetPlayer(), "EFFstop")    ; if item will be un-equipped play special stop animation
    ENDIF
ENDFUNCTION

 

 

So, now script is compiled, thank you, BUT, it doesn't work)

I made the test circlet and attach script to it, then equipped it on follower and PC, wait some time and nothing happens, mb I ,must not use vanilla animations like "idleWounded03", or mb I done smth wrong at another step, like error ar attaching script?

Here is script which I used

 

Scriptname CTP_objectAnims extends ObjectReference

 

Idle PROPERTY IdleStop_Loose auto

 

 

; -- EVENTs -- 2 + "Waiting" + "WearItem"

 

EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

IF (akNewContainer == Game.GetPlayer() as ObjectReference)

gotoState("Waiting") ; ### STATE ### player got the item, observe equip now

ELSE

UnRegisterForUpdate() ; just in case

gotoState("") ; ### STATE ###

ENDIF

ENDEVENT

 

 

EVENT OnUpdate()

Game.GetPlayer().PlayIdle(IdleStop_Loose) ; after 20 sec the item is wearing, play vanilla stop animation

Utility.Wait(0.1)

ENDEVENT

 

 

;===================================

State Waiting

;============

EVENT OnEquipped(Actor akActor)

gotoState("WearItem") ; ### STATE ###

myF_Action(1)

RegisterForSingleUpdate(1.0) ; wait for 1 sec

ENDEVENT

;=======

endState

 

 

;===================================

State WearItem

;=============

EVENT OnUnEquipped(Actor akActor)

UnRegisterForUpdate()

gotoState("Waiting") ; ### STATE ###

myF_Action(0)

ENDEVENT

;=======

endState

 

 

; -- FUNCTION --

 

;-------------------------

FUNCTION myF_Action(Int i)

;-------------------------

IF ( i ) ; i == 1

Debug.SendAnimationEvent(Game.GetPlayer(), "IdleWounded03enterinstant") ; if item equipped play special animation

ELSE ; i == 0

Debug.SendAnimationEvent(Game.GetPlayer(), "IdleWounded03Exit") ; if item will be un-equipped play special stop animation

ENDIF

ENDFUNCTION

 

Edited by colourtemp3000
Link to comment
Share on other sites

  • Recently Browsing   0 members

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