Using GetScript to check if an NPC has a particular script

Post » Sat Feb 19, 2011 11:34 am

Can anyone tell me how to check if an NPC has a certain script attached, say "BeggarScript", using OBSE? I tried using the "GetScript" function which returns a ref variable and then using the "GetName" function to get the name of the script but no luck... it appears GetName does not work on scripts.

ref rActorref rScriptstring_var svScriptBegin GameMode	set rScript to rActor.GetScript	if ( rScript )		set svScript to GetName rScript		if  ( svScript == "BeggarScript" )			; Do something		endif	endifEnd


Keep in mind that "BeggarScript" is a Vanilla Oblivion script so I cannot modify it.
User avatar
priscillaaa
 
Posts: 3309
Joined: Sat Dec 30, 2006 8:22 pm

Post » Sat Feb 19, 2011 5:53 am

Scripts don't have a name component - That's why GetName doesn't work on them. The only way to do that would be to compare the script ref with that returned by GetFormFromMod, to which you pass the BeggarScript's formID.
User avatar
R.I.p MOmmy
 
Posts: 3463
Joined: Wed Sep 06, 2006 8:40 pm

Post » Sat Feb 19, 2011 12:02 pm

Works like a charm. Thanks ShadeMe!

Here's the code in case anyone's interested:

ref rActorref rScriptstring_var svScriptBegin GameMode	set rScript to GetFormFromMod "Oblivion.esm" 06E606	if ( rActor.GetScript == rScript )		; Do Something	endifEnd

User avatar
Annick Charron
 
Posts: 3367
Joined: Fri Dec 29, 2006 3:03 pm

Post » Sat Feb 19, 2011 10:43 am

For the record, if the script is defined in Oblivion.esm you don't need GetFormFromMod.
begin gamemode  if rActor.GetScript == BeggarScript    ; stuff  endifend

User avatar
Becky Cox
 
Posts: 3389
Joined: Thu Jun 22, 2006 8:38 am

Post » Sat Feb 19, 2011 7:41 am

:facepalm:

thanks scruggs. glad to see u around!
User avatar
Johnny
 
Posts: 3390
Joined: Fri Jul 06, 2007 11:32 am


Return to IV - Oblivion