Jump to content

Help with scripts


nokou

Recommended Posts

Posted

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.

Posted

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.

Posted

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
	 
	

 

Posted
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

Posted

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}

Posted

You put all the code between { and }.

So you transformed it to just a comment.

 

Posted

ahh... so, yes... i think i know what you mean.. i'll try it again.

Thanks

Posted

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

Posted

 

Try to replace "(Self as Actor)" with "(Self as ReferenceAlias).getActorReference()"

 

It is there twice in the code.

 

 

Posted

it let me save and compile but did nothing when the outfit was worn so i went back to ck and added it to the outfit (pics shown)

sadly that didn't work either...

01.jpg

02.jpg

Posted

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
	

 

Posted

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.

Posted

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.

Posted

I did because it didn't work the first time, it's removed now and still wont work.

 

 

quest.jpg

reference.jpg

Posted

OK, try to compile the script now, try to run it , and let's check the traces in the papyrus log.

Posted

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.

 

Posted

Probably there are problems on the quest. Later or tomorrow i will try to give you more help.

Posted
3 hours ago, CPU said:

Probably there are problems on the quest. Later or tomorrow i will try to give you more help.

Thank you very much so far.. i do appreciate it

Archived

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

  • Recently Browsing   0 members

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