Assigning scripts to NPC’s with SetScript...

Post » Sat Dec 04, 2010 1:59 pm

I was instantly intrigued when I discovered this function for OBSE. In theory, the ability to write an arbitrary object script you could then assign on-the-fly to a reference in-game...

Quite promising indeed, if I could get it to work correctly. As it is I am wondering if it actually means what I think it means…

Essentially what I am trying to do is have a spell that when cast at an NPC will put a script on them. I then want that script to start immediately and do its thing until they either die or whatever other script I mess around with removes it (but most likely when they die.)

So, I made this simple spell script to attempt to do just that:


scn phitestscript

ref ttarget ; the NPC
ref scriptid ; the script I'm putting on them

begin ScriptEffectStart
set ttarget to GetSelf
set scriptid to MyNPCScript ; set my script ID to a variable (?)
ttarget.SetScript scriptid
ttarget.RunScriptLine "%q%i%q" 1 ; this is supposed to start the script (?)
end


The reason I set the script name to a variable like that is because according to the wiki page for this command, there is no variable type for scripts, so you have to pass the ID to the SetScript function that way. I don't know if I'm exactly doing it right however. I tried using the actual ID but it complained.

http://cs.elderscrolls.com/constwiki/index.php/SetScript

Anyway, it seems like the script either never gets added or never starts. I don't know if that RunScriptLine thing is right or the best way to force the script to start, but I put a basic "kill me if I'm alive" code in the script I added so I'd know immediately if it worked (because the NPC would keel over.)

Any ideas would be very much appreciated.
User avatar
Ells
 
Posts: 3430
Joined: Thu Aug 10, 2006 9:03 pm

Post » Sat Dec 04, 2010 8:21 pm

There seems to be a bit more of an explanation of this function in the http://obse.silverlock.org/obse_command_doc.html. Did you see that? I'm interpreting the comment in the OBSE docs as this being something you can't attach to an NPC, but I could be wrong - I really don't know. If the description in the docs doesn't help, I'd post your question in the OBSE thread in the mods forum.
User avatar
Blackdrak
 
Posts: 3451
Joined: Thu May 17, 2007 11:40 pm

Post » Sat Dec 04, 2010 5:29 pm

Thanks for the link. I have a feeling I’ve a bit of homework to do on this one.

I am researching this as a possible avenue into a redesign of my summoning mod, to make it where you can essentially “tame” any creature from any mod. Of course there would be a whole level-offset mini-game involved in whether you would ultimately be successful in such endeavors.

I have all the details of happiness rating and time to perma-pet and feeding system and hot-keyed favorites or “stable” systems all worked out. So, really all I need is to be able to reliable apply a rudimentary script to a target, so that they have the basic functions of my control system even before they are completely tamed and made “permanent.”

At that point, they are replaced with a custom version or that respective creature that works like my existing summoning mod, more or less.

For this temporary functionality I mod the creature’s disposition to the player so they are friendly, and add a script package to have them follow me no matter what, while engaging in defensive combat.

This works more or less as intended. (I may add a rally type effect as well, to force them to engage in less “defensive” combat, based on their happiness rating.)

I am however concerned about changes to a reference creature carrying over to the base object. The last thing I want is for something I do to change every single version of that creature spawned of that base object anywhere in the game.

That is what I am most concerned about this SetScript function. It is unclear to me whether this replaces existing scripts for the current reference only of for every single spawn of that base object…

I am also looking into some of the new array stuff, as the concept is uber-sixy indeed.

However, as I said, still much to study.
User avatar
Len swann
 
Posts: 3466
Joined: Mon Jun 18, 2007 5:02 pm

Post » Sat Dec 04, 2010 3:14 pm

Don't think you can use the command that way. From all I can see it affects the base object. And it replaces existing scripts, which means it wouldn't work for a lot of actors (especially popular overhauls like Fran's and MMM/OOO add scripts to most actors, even those that didn't have any scripts in vanilla) or cause bugs. I think it's mainly meant to be used in a controlled environment, but not for adding scripts to random actors or objects.

Why can't you simply use a token? You can do everything you could do with a script directly attached to the actor with a token.
User avatar
Soku Nyorah
 
Posts: 3413
Joined: Tue Oct 17, 2006 1:25 pm

Post » Sat Dec 04, 2010 3:17 pm

I gave the token thing a try, and while it does indeed get added it doesn't seem to work with OnActivate.

It may be that some pre-existing script on the creature I tested had an onActivate block as well that said specifically to do nothing, and took precedent over my token script, which I am testing now.
User avatar
Daddy Cool!
 
Posts: 3381
Joined: Tue Aug 21, 2007 5:34 pm

Post » Sat Dec 04, 2010 10:37 am

OnActivate will not work directly on a token (since it will only run if you activate the token, but not when you activate the container the token is in), you need to use Event Handler functions like described on the http://obse.silverlock.org/obse_command_doc.html page. You could probably also use other workarounds (like getcrosshairref that checks for actors with active tokens and then checks for activate key being pressed).
User avatar
Chloe Mayo
 
Posts: 3404
Joined: Wed Jun 21, 2006 11:59 pm


Return to IV - Oblivion