Jump to content

Adding a script to the player


Recommended Posts

I want to attach a script to the player so that i can listen for the oneffectstart/finish events from ActiveMagicEffects, however I can't get it to compile as I'm not sure what event to register for.

Scriptname CustomHUDWidget extends Quest

String Property CustomHUD_Widget = "CustomHUD.swf" AutoReadOnly

; HUDFramework
HUDFramework hud

int timer_num = 0

Group WidgetCommands
    int Property Command_UpdateCount = 100 AutoReadOnly
EndGroup

Event OnQuestInit()
    hud = HUDFramework.GetInstance()
    
    If (hud)
        ; Register the widget, setting its position to 10, 70 on the screen.
        ; Load the widget automatically after registration, and auto-load it whenever the game loads.
        hud.RegisterWidget(Self, CustomHUD_Widget, 10, 70, abLoadNow = True, abAutoLoad = True)
    Else
        Debug.MessageBox("HUDFramework is not installed!")
    EndIf
EndEvent

; This function is called by HUDFramework when the widget is loaded.
Function HUD_WidgetLoaded(string asWidget)
    If (asWidget == CustomHUD_Widget)
        hud.SendMessage(CustomHUD_Widget, Command_UpdateCount, timer_num)
		RegisterForRemoteEvent(??????, "OnEffectStart") ; <-------------------- this line
    EndIf
EndFunction

Event ActiveMagicEffect.OnEffectStart(Actor akTarget, Actor akCaster)
	Debug.MessageBox("Start")
EndEvent

I've also tried adding a second script that extends from ActiveMagicEffects, but I don't know how to get it to run. Only the quest script runs when I start the game. I tried by creating a magic effect in CreationKit and then attaching that script to it. I also tried adding the second script to the quest in CreationKit as well, neither will make the script run.

Scriptname CustomMagicEffects extends ActiveMagicEffect

String Property CustomHUD_Widget = "CustomHUD.swf" AutoReadOnly

CustomHUDWidget Property Controller Auto Const Mandatory

Event OnInit()
	StartTimer(2)
	Controller.SendIt(30)
	Debug.MessageBox("CustomMagicEffects")
EndEvent

Event OnEffectStart(Actor akTarget, Actor akCaster)
	Controller.SendIt(100)
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	Controller.SendIt(50)
EndEvent
Link to comment
Share on other sites

There's two well known methods of getting a script on the player:

 

A script via Player as an Alias(ReferenceAlias script)

A script on the player through an effect, like yours, via an ability, or something akin to Skyrims' lesser powers.

 

Remote events like the one you attempted, I don't know how to do myself, so I stick to attaching scripts to the player via ReferenceAlias script. It's easiest for me, since I don't have to worry about things like spells, abilities, etc. Setting up magic effects can be tedious.

Link to comment
Share on other sites

There's two well known methods of getting a script on the player:

 

A script via Player as an Alias(ReferenceAlias script)

A script on the player through an effect, like yours, via an ability, or something akin to Skyrims' lesser powers.

 

Remote events like the one you attempted, I don't know how to do myself, so I stick to attaching scripts to the player via ReferenceAlias script. It's easiest for me, since I don't have to worry about things like spells, abilities, etc. Setting up magic effects can be tedious.

 

Yes an alias is what I need, I think, however I'm not sure how to actually apply it properly. I tried adding it to my quest in CK but I'm most likely doing something wrong since it doesn't seem to do anything, as I'd expect the OnInit() to show the message.

 

This is how I've set it up in CK:

 

http://i.imgur.com/o7sSMlC.png

http://i.imgur.com/bkSW6yI.pnghttp://i.imgur.com/a98lk5s.png

Link to comment
Share on other sites

How do you want that magic effect to be used? It won't fire just itself, it needs to be added on spell or on enchantment.

 

The idea is that I want to be able to listen to the events of when the player consumes an item that gives them a buff. I can then create a timer on screen to show how long that buff will last (sorta like the chem icon, but with a timer for each active buff). I figured I could do that by having a script running on the player that checks using OnEffectStart to get the buff. Perhaps there's another better way to do it?

Link to comment
Share on other sites

No, it's doesn't work that way, you can register by one for single specific magiceffect script to listen for one specific oneffect start of it.

 

You should use onMagicEffectApply event.

Register for it with RegisterForMagicEffectApply and pass game.getplayer().

Then onMagicEffectApply will fire when any effect applies on player

Link to comment
Share on other sites

No, it's doesn't work that way, you can register by one for single specific magiceffect script to listen for one specific oneffect start of it.

 

You should use onMagicEffectApply event.

Register for it with RegisterForMagicEffectApply and pass game.getplayer().

Then onMagicEffectApply will fire when any effect applies on player

 

Alright so it seems OnMagicEffectApply() fires when I use an item like I wanted to! Unfortunately I don't seem to be able to get the name and duration of the effect, as I want to be able to display a timer on screen.

 

As far as I can tell the wiki says that MagicEffect only has the GetAssociatedSkill() function.

https://www.creationkit.com/fallout4/index.php?title=MagicEffect_Script

Link to comment
Share on other sites

  • Recently Browsing   0 members

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