Jump to content

[LE] Need help with a simple script for a forge


Recommended Posts

Hello everyone.

I'd like to make the forges in my dungeon to consume firewood for each use. I have duplicated the default script attached to the forge and tried to modify it and I was succesfull to an extent.

Activating the forge now removes 5 pieces of firewood but the forge still activates if you lack the necesarry firewoods.

 

Id be gratefull if somebody could modify the script below so it would prevent the use of the forge without the necessary items. Im sure its a simple script but im a total noob at moding.

Bonus points for making this requirement for the player only. :D

 

 

 

Scriptname DMBlacksmithsForge extends ObjectReference
import Debug
spell property FlameDamage Auto
MiscObject Property Firewood01 Auto
EVENT onActivate ( objectReference triggerRef )
if TriggerRef.GetItemCount(Firewood01) >= 5
playAnimation("activate")
TriggerRef.RemoveItem(Firewood01, 5)
endIf
endEvent
Event OnTriggerEnter ( objectReference triggerRef )
if (triggerRef == Game.GetPlayer())
FlameDamage.Cast(triggerRef, triggerRef)
endIf
endEvent
Link to comment
Share on other sites

I tried it but it doesnt work. The compiler threw out an error for PlayerRef being an undefined variable. I changed all the triggerRef to PlayerRef and it did compile however now when I activate the forge in game, the animation starts playing and it displays the "You expect the forge to burn forever?" message, but it doesnt remove the firewood from the inventory.

 

Heres the code now:

 

Scriptname DMBlacksmithsForge extends ObjectReference
import Debug

spell property FlameDamage Auto
MiscObject Property Firewood01 Auto

EVENT onActivate ( objectReference PlayerRef )
if PlayerRef.GetItemCount(Firewood01) >= 5
Debug.Trace("Player has more than or equal to 5 FireWood")
playAnimation("activate")
PlayerRef.RemoveItem(Firewood01, 5)
Else
Debug.Notification("You expect the forge to burn forever?")
EndIf
endEvent


Event OnTriggerEnter ( objectReference triggerRef )
if (triggerRef == Game.GetPlayer())
FlameDamage.Cast(triggerRef, triggerRef)
endIf
endEvent

 

Link to comment
Share on other sites

Make sure that you fill the Firewood01 property in the Creation Kit. If it is not filled, it will yield a null value which will be treated as 0 and thus pass on to your notification line. Also, just changing triggerRef to PlayerRef doesn't help you any. You want the script to check if the player and only the player has firewood. Thus you need to compare triggerRef to the player. PlayerRef is a variable that some authors use to represent the player but it still has to be assigned the player data.

 

Example:

 

 

Event OnActivate(ObjectReference triggerRef)
  Actor PlayerRef = Game.GetPlayer()
  If triggerRef == PlayerRef  ; the player activated
    If PlayerRef.GetItemCount(Firewood01) >= 5
      Debug.Notification("Player has 5 or more firewood")
      PlayerRef.RemoveItem(Firewood01,5)
      playAnimation("activate")
    Else
      Debug.Notification("Player does not have enough firewood")
    EndIf
  Else ; NPC activated
    playAnimation("activate")
  EndIf
EndEvent

 

 

 

However, I believe this won't prevent the player from using the forge even if they do not have enough firewood. If I am correct, they should still get access to the menu just not have the animation sequence play out. I'll let you test it out and see what happens.

 

 

Link to comment
Share on other sites

Yeah earlier I forgot to fill the properties. My bad.
Your script works to an extent. Although as you suspectet, it doesnt prevent access to the menu and even the animation still plays.

Still thank you for your help.

 

I just wanted to have a harder time surviving in skyrim, but instead I got a harder time in the creation kit. :sad:

Link to comment
Share on other sites

Interfering with the default activations of stuff in Skyrim can get tricky. However it can be done. I would suggest adding a BlockActivation call to an OnInit block, which will prevent the default activation. You should then be able to use the Activate function to force-activate the default processing if and only if your firewood condition is met.

 

 

Scriptname DMBlacksmithsForge extends ObjectReference  
import Debug
 
spell property FlameDamage Auto
MiscObject Property Firewood01 Auto

EVENT onInit ()
    BlockActivation()
endEVENT
 
EVENT onActivate ( objectReference triggerRef )
    if TriggerRef.GetItemCount(Firewood01) >= 5
        playAnimation("activate")
        TriggerRef.RemoveItem(Firewood01, 5)
        Activate(triggerRef, true)
    endIf
endEvent
 
Event OnTriggerEnter ( objectReference triggerRef )
    if (triggerRef == Game.GetPlayer())
        FlameDamage.Cast(triggerRef, triggerRef)
    endIf
endEvent
Link to comment
Share on other sites

Just keep in mind that if you use BlockActivation on an object and have no way to reverse it then when the player removes the mod those objects will not function properly.

 

Instead of the OnInit event, try toggling the status with OnCellAttach and OnCellDetach events

 

i.e.

 

 

Scriptname DMBlacksmithsForge extends ObjectReference  
import Debug
 
spell property FlameDamage Auto
MiscObject Property Firewood01 Auto

EVENT OnCellAttach()
    BlockActivation(True)
endEVENT

Event OnCellDetach()
	BlockActivation(False)
EndEvent
 
Event OnActivate(ObjectReference triggerRef)
  Actor PlayerRef = Game.GetPlayer()
  If triggerRef == PlayerRef  ; the player activated
    If PlayerRef.GetItemCount(Firewood01) >= 5
      Notification("Player has 5 or more firewood")
      PlayerRef.RemoveItem(Firewood01,5)
      playAnimation("activate")
    Else
      Notification("Player does not have enough firewood")
    EndIf
  Else ; NPC activated
    playAnimation("activate")
  EndIf
EndEvent 

Event OnTriggerEnter ( objectReference triggerRef )
    if (triggerRef == Game.GetPlayer())
        FlameDamage.Cast(triggerRef, triggerRef)
    endIf
endEvent 

 

 

At least this way you could tell users to leave the area and there will be a chance that the forge will still work after the mod is removed.

Link to comment
Share on other sites

This is amazing! BlockActivation works like a charm and it doesnt even prevent NPCs using the forge.
Removing the mod shouldnt cause any issues as I have duplicated the forges and only they have the script. Also there is only one instance of that forge in my dungeon so far.

For the rest of the forges in the world I plan to make them rentable from their owners or else the player gets a bounty,

but first I want to finish that one dungeon which I use for practicing moding before I move on changing things in all of tamriel.

 

Thank you guys/girls/sentient creatures for your help. My head would have exploded figuring this out on my own.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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