Jump to content

Help with scripts


nokou

Recommended Posts

I've made a new outfit but I want to add a script that adds a spell to the player and removes the spell when unequipped.

The only problem is I've never done scripts before. any help would be appreciated.

Link to comment

Create a quest.

Create an alias inside the quest.

Set the alias forced to the player

Add a script with the following code.

 

Maybe you want to correctly name the script, and the two properties (myArmor and mySpell) with the actual names

Fill the properties after compiling the script and you should be good to go.

 

	Scriptname myOutfitSpell extends ReferenceAlias
	 
	Armor Property myArmor Auto
	Spell Property mySpell Auto
	 
	Evnet OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
	  if akBaseObject==myArmor
	    (Self as Actor).addSpell(mySpell, true)
	  endIf
	endEvent
	 
	Evnet OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
	  if akBaseObject==myArmor
	    (Self as Actor).removeSpell(mySpell)
	  endIf
	endEvent
	 
	

 

Link to comment
9 hours ago, Azazellz said:

You can look on vanilla dragonborn rings from Azidal quest (one of them add fire spell when equipped).

So you can just look how it work there and make same things for your item.

 

9 hours ago, CPU said:

Create a quest.

Create an alias inside the quest.

Set the alias forced to the player

Add a script with the following code.

 

Maybe you want to correctly name the script, and the two properties (myArmor and mySpell) with the actual names

Fill the properties after compiling the script and you should be good to go.

 

 

 

 

Awesome, Thank you guys.. i'll give it a go now

Link to comment

sorry it didnt work.. im still trying to figure it out as this is new to me...  just curious but here's what I done

 

{Scriptname myOutfitSpell extends ReferenceAlias
    
    Armor Property Cyber_AngelOutfit Auto
    Spell Property Cyber_ElectricDischarge Auto
    
    Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
      if akBaseObject==Cyber_AngelOutfit
        (Self as Actor).addSpell(Cyber_ElectricDischarge, true)
      endIf
    endEvent
    
    Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
      if akBaseObject==Cyber_AngelOutfit
        (Self as Actor).removeSpell(Cyber_ElectricDischarge)
      endIf
    endEvent}

Link to comment

ok, so I started over again but now Im getting "cannot cast Cyber_ElectroDischarge to actor, types are incompatable"

 

here's my script.. well the one you gave me

 

Scriptname ElectroDischarge extends ReferenceAlias  
{Electro Discharge}
    
Armor Property Cyber_AngelOutfit Auto
    Spell Property Cyber_ElectroDischarge Auto
    
    Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
      if akBaseObject==Cyber_AngelOutfit
        (Self as Actor).addSpell(Cyber_ElectroDischarge, true)
      endIf
    endEvent
    
    Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
      if akBaseObject==Cyber_AngelOutfit
        (Self as Actor).removeSpell(Cyber_ElectroDischarge)
      endIf
    endEvent

Link to comment

OK, let's put some debug traces in the code, and let's see what is going on.

 

	Scriptname ElectroDischarge extends ReferenceAlias  
{Electro Discharge}
 
	Armor Property Cyber_AngelOutfit Auto
Spell Property Cyber_ElectroDischarge Auto
    
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
      if akBaseObject==Cyber_AngelOutfit
	debug.trace("---> Angel Outfit equipped")
	debug.trace("---> Applying to: " + (Self as ReferenceAlias).getActorReference())
        (Self as ReferenceAlias).getActorReference().addSpell(Cyber_ElectroDischarge, true)
      endIf
endEvent
    
Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
      if akBaseObject==Cyber_AngelOutfit
debug.trace("---> Angel Outfit removed")
	debug.trace("---> Removing spell from to: " + (Self as ReferenceAlias).getActorReference().getDisplayName())
	        (Self as ReferenceAlias).getActorReference().removeSpell(Cyber_ElectroDischarge)
      endIf
endEvent
	

 

Link to comment

I dont know if this how to add debug traces but I enable papyrus logging and started a new game, I ran it for a while and i found this

 

"[03/17/2018 - 01:46:22AM] Error: Unable to bind script ElectricDischarge to Item 1 in container  (00000014) because their base types do not match"

 

That first script i did ElectroDischarge was deleted and redone to ElectricDischarge, this new one compiled and saved but the above problem is what im getting

 

i can send the Papyrus.0.log file if needed.

Link to comment

Wait, did you attach the script directly to the player?

 

You have to put it to a ReferenceAlias inside a quest, and the refalias has to point to the player.

Link to comment

ok, I added the extra commands, saved and compiled it.. checked the papyrus log, nothing.. then I tried adding

debug.trace("---> Cyber_AngelOutfit Outfit equipped") instead of debug.trace("---> Angel Outfit equipped") and still nothing.

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use