Jump to content

Need Help With a Script


Recommended Posts

For a mod that I'm making, I needed to create a script that would disable and delete the npc with the script, once the player had reached a certain distance from that particular npc. I went looking through Bethesda's scripts and found a script called 'cwkillselfwhenfarfromplayer' which contained the following:

 

import game


EVENT OnLoad()
;GetReference().RegisterForUpdate(2)
EndEVENT


;EVENT OnUpdate()

;	actor selfAsActor = GetActorReference()

;	if ((GetOwningQuest() as CWSiegeWhiterunAttackQstSCRIPT).StartSuicides == 1)
;		if selfAsActor.isDead() == FALSE
;			if selfAsActor.GetDistance(game.GetPlayer()) <= 3000
;				selfAsActor.Kill()
;			endif
;		endif
;	endif

;EndEVENT

 

 

So I decided to copy this script and then edit it to meet my own needs. This was the result I came up with:

 

 

import game


EVENT OnLoad()
;GetReference().RegisterForUpdate(2)
EndEVENT


;EVENT OnUpdate()

;	actor selfAsActor = GetActorReference()

;	if selfAsActor.isDead() == FALSE
;		if selfAsActor.GetDistance(game.GetPlayer()) <= 3000
;			selfAsActor.Disable()
;			selfAsActor.Delete()				
;		endif
;	endif

;EndEVENT

 

The problem? It doesn't work. Unfortunately my knowledge with scripting is fairly limited and I am unable to figure out what I've done wrong. If anyone could help me with this, I would be very grateful.

Link to comment
Share on other sites

Well for starters, the ";" in front of all the code makes it useless. ";" basically tells the program to disregard the code that comes after it, this is called "commenting" and usually you will do this to temporarily remove code, or write text to help yourself and other understand the code you are writing.

 

I would also add an event that would force the script to un-register itself upon death, since the OnUpdate would technically keep running.

 

Though I believe you could simply do this:

Event OnUnload()
      (self as Actor).Delete()  
endEvent

 

Why? Because if the object is unloaded, it's far enough away as is.

Link to comment
Share on other sites

Well for starters, the ";" in front of all the code makes it useless. ";" basically tells the program to disregard the code that comes after it, this is called "commenting" and usually you will do this to temporarily remove code, or write text to help yourself and other understand the code you are writing.

 

I would also add an event that would force the script to un-register itself upon death, since the OnUpdate would technically keep running.

 

Though I believe you could simply do this:

Event OnUnload()
      (self as Actor).Delete()  
endEvent

 

Why? Because if the object is unloaded, it's far enough away as is.

 

So that's why it didn't work. I guess Bethesda never used the script that I copied then. Thanks for the heads up.

 

But anyway I tried your suggested script and it worked perfectly. The only change I had to make was to remove the 'self as actor' part and just leave is as 'Delete()'. Thank you very much for the help though.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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