Jump to content

Enable and disable an NPC?


Recommended Posts

My scripting skills are rudimentary, but I've been able to work things out and make them work up until now. I'm humbly beseeching help on what seems to be a very simple thing.

 

I am adding a quest to a mod, in which a main mod character sends the player to talk to an NPC that has been bribed to provide information. I want the information-bearing NPC to exist in the game only for the stages of the quest that require her. So the result I want is for her to start disabled (checked the box), become enabled when the quest hits a certain stage and the player enters the Wawnet Inn, hang around to provide reminder information until another stage is reached, then disappear (disable).

 

I tried including my script in the main quest script, and it didn't work. So I attached the following short script to the NPC object (persistent reference,) ref ID 'DorritaaMSB'. Still no luck. I have no idea what I'm doing wrong - I have had no problems enabling or disabling objects with other scripts.

 

SCN DorritScript

Short DorritOn
Short DorritOff

Begin Gamemode
If [GetStage aaMSB == 30]
If DorritOn == 0
If (Player.GetInCell WawnetInnTavern)
"DorritaaMSB".Enable
Set DorritOn to 1
EndIf
EndIf
EndIf
End

Begin Gamemode
If DorritOn == 1
If DorritOff == 0
If [GetStage aaMSB == 50]
"DorritaaMSB".Disable
Set DorritOff to 1
EndIf
EndIf
EndIf
End

 

I would sincerely appreciate any and all advice on making this work.

 

Thanks,

 

Trippy

Link to comment
Share on other sites

Why are there quotation marks around the reference's ID?

 

Also you should have only one GameMode block, containing both if statements. Never use more than one of any block type unless it's something like MenuMode "[different menu code]".

 

You're much better doing this in the quest script or in quest stages because GameMode scripts attached to world objects run every frame, which is bad for performance.

Edited by PushTheWinButton
Link to comment
Share on other sites

hello Trippy

I have suggestion for improvement

SCN DorritScript

Begin GameMode
	if GetDisabled ;no need to store enable disable in variable, you can use function GetDisabled
		if GetStage aaMSB == 30
			Enable
		endif
	else
		if GetStage aaMSB == 50
			Disable
		endif
	endif
End

PushTheWinButton said that GameMode is bad for performance, I agree

but I think you can rest assured,

because object script attached to npc will only run if player is in the same cellspace with that npc (or object)

the script only contain small code enable disable function, that is very light performance. even though the gamemode in attached script run per 0.001 sec / 1 millisecond

if you have Maskar Oblivion Overhaul mod

you can see that MOO have many object script attached in npcs or objects

but the game still considered stable and lightweight

so ... I believe attaching script object is pretty lightweight if we use it only for small use

Link to comment
Share on other sites

Thanks to you both for these helpful suggestions. I'll try it out and report the results.

 

The quotation marks were something I picked up from a tutorial, some time ago, and since they worked, I kept using them. Probably unnecessary, and just a cargo cult thing. I'll omit them and see if it makes a difference.

 

Regards,

 

T.

 

Edit: the elegant script you proposed worked like a charm. Thanks!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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