ObjectActor script like the old GameMode?

Post » Mon Jun 18, 2012 7:28 pm

I would like to attach a script to a horse, so that when a global variable becomes a '1', the horse disables and deletes itself.

But I do not know what type of script would constantly run that is attached to the horse like the old 'GameMode' block. I need the script attached to the horse so it can disable and delete itself. Unless there is a way to store the reference of the horse in a global, which I did not see.

I use a spell to summon the horse, and a second cast of the spell will set the global variable to 1 so the script on the horse can delete itself and reset the global.

Here is the script I was thinking about, but its not 'extending' anything because I did not know what to use.

Any ideas on how I can accomplish what I want?

Scriptname LevelersHorseBaseScript   GlobalVariable Property LevelersSummonHorseDGBL  Auto float myValFunction SomeFunction()			      registerForUpdate(5)EndFunctionEvent OnUpdate()   myVal = LevelersSummonHorseDGBL.GetValue()   if myVal == 1      LevelersSummonHorseDGBL.SetValue(0)      Disable()      Delete()   endifEndEvent
User avatar
k a t e
 
Posts: 3378
Joined: Fri Jan 19, 2007 9:00 am

Post » Tue Jun 19, 2012 2:42 am

What you could do is create the script for the magic effect that does it all within the spell - have the spell check the global variable, see if it is 0 / 1, and act appropriately. You could create an Actor property to store the horse reference, I believe.
User avatar
priscillaaa
 
Posts: 3309
Joined: Sat Dec 30, 2006 8:22 pm

Post » Tue Jun 19, 2012 8:08 am

Hmm. Are you using a single Horse actor? If so, could you add the script directly to the actor? Dunno if that would work but... maybe it's a place to start? Sorry if this doesn't help :(
User avatar
kat no x
 
Posts: 3247
Joined: Mon Apr 16, 2007 5:39 pm

Post » Tue Jun 19, 2012 1:50 am

The problem with magic scripts is that they do not preserve the values stored after they run, into the next cast of the spell.
I don't want to use the same spell with a long duration. What happens when the duration runs out and your still riding it? Even if you checked for riding it, the spell has ended so how would you disable and delete the horse?

The original summon cast does a placeAtMe of the base horse as a new actor with a unique reference.

I would like to put the above script on the horse actor, but I dont know how to make it run constatntly...

Here is the magic spell script:
Scriptname LevelersHorseScript extends activemagiceffect{Summon Horse to/from self}ActorBase Property LevelersNightMareAB  AutoObjectReference LevelersHorseObjGlobalVariable Property LevelersSummonHorseGBL  AutoGlobalVariable Property LevelersSummonHorseDGBL  Autofloat myValEvent OnEffectStart(Actor akTarget, Actor akCaster)myVal = LevelersSummonHorseGBL.GetValue()if myVal == 0.00	LevelersSummonHorseGBL.SetValue(1)	LevelersHorseObj = Game.GetPlayer().PlaceAtMe(LevelersNightMareAB)else	LevelersSummonHorseGBL.SetValue(0)	LevelersSummonHorseDGBL.SetValue(1)  ;  LevelersHorseObj.Disable()  ;  LevelersHorseObj.Delete()endifEndEvent
User avatar
A Lo RIkIton'ton
 
Posts: 3404
Joined: Tue Aug 21, 2007 7:22 pm

Post » Mon Jun 18, 2012 6:49 pm

You could use an ability so it wouldn't need recasting.

The script you posted above only has one native event - OnUpdate. However, without another entry point it will never be registered for updates (that function is never called) so no code will actually run. I recommend adding an http://www.creationkit.com/OnInit event as well, to start things off.

Cipscis
User avatar
cosmo valerga
 
Posts: 3477
Joined: Sat Oct 13, 2007 10:21 am

Post » Tue Jun 19, 2012 5:28 am

What would I extend the scriptname as? I get plenty of errors with this:

 Scriptname LevelersHorseBaseScript  GlobalVariable Property LevelersSummonHorseDGBL  Auto float myValEvent OnInit() registerForUpdate(5) GotoState ("polling")EndEventState polling Event OnUpdate()  myVal = LevelersSummonHorseDGBL.GetValue()  if myVal == 1   LevelersSummonHorseDGBL.SetValue(0)   Disable()   Delete()  endif EndEventEndStateState active ;do nothingEndState
User avatar
Nims
 
Posts: 3352
Joined: Thu Jun 07, 2007 3:29 pm

Post » Mon Jun 18, 2012 10:31 pm

You would want to "extends Quest" I believe.
User avatar
Bethany Short
 
Posts: 3450
Joined: Fri Jul 14, 2006 11:47 am

Post » Tue Jun 19, 2012 6:07 am

Basically, as I understand it, whenever a script is attached to an object that object inherits the "type" defined by the script, so if I create a script called "MyNewType" and attached it to something, that thing would then have the type "MyNewType". Obviously, since multiple scripts can be attached to objects, they can have multiple types.

However, in order to attach a script to an object, that script must extend a script the defines a type that the object already has. This is where native scripts like "Quest" and "Actor" come in, as the game engine attaches them to the appropriate objects automatically. So, if you want to attach a script to a quest that doesn't have any scripts currently attached to it, you'll need that script to extend Quest.

I talk a little bit about inheritance here, for anyone not familiar with it - http://www.cipscis.com/skyrim/tutorials/externalaccess.aspx

Cipscis
User avatar
Amanda savory
 
Posts: 3332
Joined: Mon Nov 27, 2006 10:37 am

Post » Tue Jun 19, 2012 10:10 am

Ok, so basically, there is no way to simply attach a script to an object and that script is running all the time. Like you could in oblivion by attaching a GameMode script.

If I understand whats being suggested, I would neet to do something like this.

1. The spell simply checks a global variable. If its == 0, then make it = 1. If its == 1, then make it = 0. And thats all it does.

2. Make a quest script that runs every second, and check the value of the global, and its current local value. If the values are different, perform an action.
so, if global is 1 and local is 0, send the horse to the player. If the global is 0 and the local is 1, send the horse back home.
User avatar
Lisa
 
Posts: 3473
Joined: Thu Jul 13, 2006 3:57 am

Post » Tue Jun 19, 2012 8:10 am

If anyone is interested, this worked.

Script on the magic effect:

Scriptname LevelersHorseScript extends activemagiceffect {Summon Horse to/from self} GlobalVariable Property LevelersSummonHorseGBL  Auto float myValEvent OnEffectStart(Actor akTarget, Actor akCaster) myVal = LevelersSummonHorseGBL.GetValue() if myVal == 0.00   LevelersSummonHorseGBL.SetValue(1) else   LevelersSummonHorseGBL.SetValue(0) endifEndEvent

And I made a quest to 'start game enabled'

Scriptname LevelersHorseQuestScript extends Quest  ObjectReference Property LevelersHorseHomeREF  Auto ObjectReference Property LevelersNightMareREF  Auto GlobalVariable Property LevelersSummonHorseGBL  Auto float myValint myStateEvent OnInit() registerForUpdate(4)EndEventEvent OnUpdate() myVal = LevelersSummonHorseGBL.GetValue() if myVal == 1  if myState == 0   myState = 1   LevelersNightMareREF.MoveTo(Game.GetPlayer())  endif else  if myState == 1   myState = 0   LevelersNightMareREF.MoveTo(LevelersHorseHomeREF)  endif endifEndEvent
Now the spell controls the horse summons. I will later be putting fade effects on the horse for when it comes and goes.
Thanks everyone! :)
User avatar
Lloyd Muldowney
 
Posts: 3497
Joined: Wed May 23, 2007 2:08 pm

Post » Mon Jun 18, 2012 9:44 pm

I see you've used a "State" variable in your last script, so I feel like I should let you know about http://www.creationkit.com/States_(Papyrus), just in case they're something you haven't come across yet.

Adding states to your script might make it look like this, and just means that there'd be less stuff for Papyrus to handle each time the event is called:
Scriptname LevelersHorseQuestScript extends QuestObjectReference Property LevelersHorseHomeREF  AutoObjectReference Property LevelersNightMareREF  AutoGlobalVariable Property LevelersSummonHorseGBL  AutoEvent OnInit()	registerForUpdate(4)	GoToState("HorseAtHome")EndEventState HorseAtHome	Event OnUpdate()		if LevelersSummonHorseGBL.GetValue() == 1			GoToState("HorseAtPlayer")			LevelersNightMareREF.MoveTo(Game.GetPlayer())		endif	EndEventEndStateState HorseAtPlayer	Event OnUpdate()		if LevelersSummonHorseGBL.GetValue() == 0			GoToState("HorseAtHome")			LevelersNightMareREF.MoveTo(LevelersHoreHomeREF)		endif	EndEventEndState

Cipscis
User avatar
Cheryl Rice
 
Posts: 3412
Joined: Sat Aug 11, 2007 7:44 am


Return to V - Skyrim