Jump to content

Actor.MoveTo() Won't move a horse


Recommended Posts

I am trying to create a set of spells that will allow me to mark a primary horse, store it in a world space I created, and then recall it from that world space later.

 

Here is the code I have:

 

This is the horse manager script, which stores a reference to the horse marked as primary, and handles moving it to the storage world.

Scriptname _HC_HorseManager   extends ObjectReference

Actor property HCPrimaryHorse auto  ;Reference to the primary horse.  This is set by the player in game.

ObjectReference property HCStableMarker1 auto  ;Reference to XMarkerHeader in the storage world I'm moving the horse to.

bool Function isPrimaryHorse(Actor check)
	return check == HCPRimaryHorse
endfunction

Function SetHorseAsPrimary(Actor target)
	HCPrimaryHorse = target
	StoreHorse(target)
EndFunction

Function StoreHorse(Actor target)
	target.MoveTo(HCStableMarker1)
endfunction

Here is the Spell script. This is a projectile spell, Delivery is Target Actor.

Scriptname _HC_HorseStoreMarkSpellEffect extends activemagiceffect  

Race Property HorseRace  Auto              
Faction Property PlayerHorseFaction Auto

Message property _HC_MSG_HorseStoreMark auto

ObjectReference property hmObj auto  ;Reference to the object that holds the _HC_HorseManager script


Event OnEffectStart(Actor akTarget, Actor akCaster)

	_HC_HorseManager manager = hmObj as _HC_HorseManager

	if(akTarget.GetActorBase().GetRace() == HorseRace)     ;Make sure the spell hit a horse
		if(akTarget.IsInFaction(PlayerHorseFaction))   ;Make sure the horse is owned by the player
			if(manager.isPrimaryHorse(akTarget))   ;Check if horse is already primary
				manager.StoreHorse(akTarget)   ;If so, move it to the storage world
			else                                   ;If not, ask to set as primary or not
				int selection = _HC_MSG_HorseStoreMark.show()

				if(selection == 0)
					manager.StoreHorse(akTarget)
				elseif(selection == 1)
					manager.SetHorseAsPrimary(akTarget)
				endif
			endif
		else
			Debug.Notification("You cannot store a horse you don't own.")
		endif
	else
		Debug.Notification(akTarget.GetActorBase().GetRace()) ;debug output
	endif

EndEvent

I've run this with debug notifications, every function is being called in its proper order, and HCPrimaryHorse is being assigned to correctly. The issue is simply that when I cast it, the horse doesn't go anywhere. I am casting this on a horse I purchased from the Whiterun Stables.

 

Thanks for any guidance you can offer.

Edited by PowderedSugar
Link to comment
Share on other sites

Why have you made two scripts for such task? You can do everything from one magic effect script. Like check if target is needed horse (you can add custom keyword to actor horse and check it with haskeyword()) then check if it is in player horse faction and then move it to your xmarker in your worldspace.
Link to comment
Share on other sites

I went with two scripts because the store and summon spells need to be separate (different delivery types), so I thought I needed an intermediary to store the reference.

 

I did try to place the MoveTo code to the Spell Script, and the horse teleported away, but then reappeared a couple seconds later. That's one step closer at least. I guess I'll move the storage and reference portion to the spell like you suggested, and see if that fixes the issue. Thanks!

Edited by PowderedSugar
Link to comment
Share on other sites

Look at

    Actor Horse = Game.GetPlayersLastRiddenHorse()
    if (horse) ; does the player have a horse?
        if(!horse.IsDead()) ; you don't want a dead horse, lol
            horse.MoveToMyEditorLocation() ; go to whiterun stable or other editor location like a Mod Storage Cell
            Game.SetPlayersLastRiddenHorse(none)  ; Set or Clear it so it stops following on fast travel
           endif
    endif

No X Marker, Factions, or anything required, I just copied Beth Original Games Codes.

 

Note you must own the horse, stolen doesn't count as last ridden.

 

I don't do it much now, but I spent hours read the codes, my first rule is keep it simple. I left debug stuff for you.

Link to comment
Share on other sites

Look at

    Actor Horse = Game.GetPlayersLastRiddenHorse()
    if (horse) ; does the player have a horse?
        if(!horse.IsDead()) ; you don't want a dead horse, lol
            horse.MoveToMyEditorLocation() ; go to whiterun stable or other editor location like a Mod Storage Cell
            Game.SetPlayersLastRiddenHorse(none)  ; Set or Clear it so it stops following on fast travel
           endif
    endif

No X Marker, Factions, or anything required, I just copied Beth Original Games Codes.

 

Note you must own the horse, stolen doesn't count as last ridden.

 

I don't do it much now, but I spent hours read the codes, my first rule is keep it simple. I left debug stuff for you.

 

Thanks for the example, but the horse being stored or recalled won't necessarily be the last horse the player rode on.

 

They're also not just being moved to the player, they're being moved a small world space I created. MoveToMyEditorLocation won't work in this instance because player-purchased horses are never placed in the editor.

Edited by PowderedSugar
Link to comment
Share on other sites

 

I just copied Beth Original Games Codes.

 

 

Would you mind if I asked where you found that? I am going to be looking into the horses in the near future.

 

To follow up, by moving everything to a single script the teleportation effect started working. When I was standing near the stables it would immediately teleport the horse back to me, but when I moved away from it it started working.

 

What you are doing should be done via quest. The horse the player chooses should be forced to an Alias and that is just for starters.

 

You really need to get a much better grasp of what you are doing. Look at how the game deals with Horses. You may even want to have a look at the dialogue follower quest.

 

Watch the videos bellow, they will give you a wide range of information.

 

https://www.youtube.com/user/doughamil/videos

Link to comment
Share on other sites

 

 

I just copied Beth Original Games Codes.

 

 

Would you mind if I asked where you found that? I am going to be looking into the horses in the near future.

 

To follow up, by moving everything to a single script the teleportation effect started working. When I was standing near the stables it would immediately teleport the horse back to me, but when I moved away from it it started working.

 

What you are doing should be done via quest. The horse the player chooses should be forced to an Alias and that is just for starters.

 

You really need to get a much better grasp of what you are doing. Look at how the game deals with Horses. You may even want to have a look at the dialogue follower quest.

 

Watch the videos bellow, they will give you a wide range of information.

 

https://www.youtube.com/user/doughamil/videos

 

 

Thanks for the link to the tutorial series. I'll watch those before continuing.

Link to comment
Share on other sites

I happen to have some slight interest in this also and am unable to do any testing with horses at this time.

 

If you are still working on this project place this script on the player or a player alias and see if these two events work.

Event OnCellAttach()
  RegisterForAnimationEvent(Game.GetPlayer(), "HorseEnter") 
  RegisterForAnimationEvent(Game.GetPlayer(), "HorseExit") 
  Debug.Notification("Events have been registered.")
endEvent

Event OnAnimationEvent(ObjectReference akSource, string asEventName)

  If (akSource == Game.GetPlayer()) 
  Else 
    Return
  EndIf
  
  If (asEventName == "HorseEnter")
    Debug.Notification("Player got on Horse.")
    Return
  EndIf

  If (asEventName == "HorseExit")
    Debug.Notification("Player got off Horse.")
    Return
  EndIf

EndEvent
Edited by Masterofnet
Link to comment
Share on other sites

  • Recently Browsing   0 members

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