Tasheni Posted December 6, 2017 Share Posted December 6, 2017 Hello to all, hope you can help me to improve this script I've written. It works but perhaps there's a better way to do this.Script is attached to the player alias of a quest. It teleports horses to followers and mount them if player mounts and follower are not waiting and if player dismount they do the same. Scriptname _TasheniMonitorPlayerMounting extends ReferenceAlias Actor Player Event OnInit() Player = Game.GetPlayer() RegisterForAnimationEvent(Game.GetPlayer(), "tailHorseMount") RegisterForAnimationEvent (Game.GetPlayer(), "tailHorseDismount") Debug.Notification ("Events registered") EndEvent Event OnAnimationEvent (ObjectReference akSource, string asEventName) If akSource == Player Else Return EndIf If Ruby.IsInFaction(CurrentFollowerFaction) ==1 If Ruby.GetActorValue("WaitingForPlayer") == 0 If asEventName == "tailHorseMount" Debug.Notification ("Player mounted") Assan.MoveTo(Ruby as objectreference, 50.0000 * math.sin(Ruby.GetAngleZ() + 90.0000), 50.0000 * math.cos(Ruby.GetAngleZ() + 90.0000), 0.000000, true) Ruby.OnAnimationEvent(none, "tailHorseMount") Ruby.EvaluatePackage() EndIf If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Ruby.Dismount() Ruby.EvaluatePackage() EndIf Else Return EndIf EndIf If Chiomara.IsInFaction(CurrentFollowerFaction) ==1 If Chiomara.GetActorValue("WaitingForPlayer") == 0 If asEventName == "tailHorseMount" Debug.Notification ("Player mounted") Dubha.MoveTo(Chiomara as objectreference, 50.0000 * math.sin(Chiomara.GetAngleZ() + 90.0000), 50.0000 * math.cos(Chiomara.GetAngleZ() + 90.0000), 0.000000, true) Chiomara.OnAnimationEvent(none, "tailHorseMount") Chiomara.EvaluatePackage() EndIf If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Chiomara.Dismount() Chiomara.EvaluatePackage() EndIf Else Return EndIf EndIf If Eldrid.IsInFaction(CurrentFollowerFaction) == 1 If Eldrid.GetActorValue("WaitingForPlayer") == 0 If asEventName == "tailHorseMount" Debug.Notification ("Player mounted") Rasha.MoveTo(Eldrid as objectreference, 50.0000 * math.sin(Eldrid.GetAngleZ() + 90.0000), 50.0000 * math.cos(Eldrid.GetAngleZ() + 90.0000), 0.000000, true) Eldrid.OnAnimationEvent(none, "tailHorseMount") Eldrid.EvaluatePackage() EndIf If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Eldrid.Dismount() Eldrid.EvaluatePackage() EndIf Else Return EndIf EndIf If Sherda.IsInFaction(CurrentFollowerFaction) == 1 If Sherda.GetActorValue("WaitingForPlayer") == 0 If asEventName == "tailHorseMount" Debug.Notification ("Player mounted") Qailash.MoveTo(Sherda as objectreference, 50.0000 * math.sin(Sherda.GetAngleZ() + 90.0000), 50.0000 * math.cos(Sherda.GetAngleZ() + 90.0000), 0.000000, true) Sherda.OnAnimationEvent(none, "tailHorseMount") Sherda.EvaluatePackage() EndIf If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Sherda.Dismount() Sherda.EvaluatePackage() EndIf Else Return EndIf EndIf If Ramgar.IsInFaction(CurrentFollowerFaction) == 1 If Ramgar.GetActorValue("WaitingForPlayer") == 0 If asEventName == "tailHorseMount" Debug.Notification ("Player mounted") Fahgravel.MoveTo(Ramgar as objectreference, 50.0000 * math.sin(Fahgravel.GetAngleZ() + 90.0000), 50.0000 * math.cos(Fahgravel.GetAngleZ() + 90.0000), 0.000000, true) Ramgar.OnAnimationEvent(none, "tailHorseMount") Ramgar.EvaluatePackage() EndIf If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Ramgar.Dismount() Ramgar.EvaluatePackage() EndIf Else Return EndIf EndIf If Tom.IsInFaction(CurrentFollowerFaction) == 1 If Tom.GetActorValue("WaitingForPlayer") == 0 If asEventName == "tailHorseMount" Debug.Notification ("Player mounted") Sugar.MoveTo(Tom as objectreference, 50.0000 * math.sin(Tom.GetAngleZ() + 90.0000), 50.0000 * math.cos(Tom.GetAngleZ() + 90.0000), 0.000000, true) Tom.OnAnimationEvent(none, "tailHorseMount") Tom.EvaluatePackage() EndIf If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Tom.Dismount() Tom.EvaluatePackage() EndIf Else Return EndIf EndIf EndEvent Faction Property CurrentFollowerFaction Auto Actor Property Ruby Auto Actor Property Assan Auto Actor Property Chiomara Auto Actor Property Dubha Auto Actor Property Eldrid Auto Actor Property Rasha Auto Actor Property Ramgar Auto Actor Property Fahgravel Auto Actor Property Sherda Auto Actor Property Qailash Auto Actor Property Tom Auto Actor Property Sugar Auto Script checks if player is mounting, if the specific npc is in current follower faction and if npc is not waiting. If I have all six followers with me, it happens sometimes that not all are mounting as fast as the player, but mostly it works. Please tell me your suggestions about it. Thank you. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted December 6, 2017 Share Posted December 6, 2017 May not resolve any delays that you are experiencing... I did notice that you have a lot of repeating code with minor differences. The following is a reworking of your script to make it shorter. Should perform the same at the very least and makes for adding new follower/horse pairs easier. Scriptname _TasheniMonitorPlayerMounting extends ReferenceAlias Actor Player Event OnInit() Player = Game.GetPlayer() RegisterForAnimationEvent(Player, "tailHorseMount") RegisterForAnimationEvent (Player, "tailHorseDismount") Debug.Notification ("Events registered") EndEvent Event OnAnimationEvent (ObjectReference akSource, string asEventName) If akSource == Player FollowerMount(Ruby,Assan) FollowerMount(Chiomara,Dubha) FollowerMount(Eldrid,Rasha) FollowerMount(Sherda,Qailash) FollowerMount(Ramgar,Fahgravel) FollowerMount(Tom,Sugar) Else Return EndIf EndEvent Function FollowerMount(Actor myFollower, Actor myHorse) If myFollower.IsInFaction(CurrentFollowerFaction) ==1 If myFollower.GetActorValue("WaitingForPlayer") == 0 If asEventName == "tailHorseMount" Debug.Notification ("Player mounted") myHorse.MoveTo(myFollower as objectreference, 50.0000 * math.sin(myFollower.GetAngleZ() + 90.0000), 50.0000 * math.cos(myFollower.GetAngleZ() + 90.0000), 0.000000, true) myFollower.OnAnimationEvent(none, "tailHorseMount") myFollower.EvaluatePackage() EndIf If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Ruby.Dismount() Ruby.EvaluatePackage() EndIf Else Return EndIf EndIf EndFunction Faction Property CurrentFollowerFaction Auto Actor Property Ruby Auto Actor Property Assan Auto Actor Property Chiomara Auto Actor Property Dubha Auto Actor Property Eldrid Auto Actor Property Rasha Auto Actor Property Ramgar Auto Actor Property Fahgravel Auto Actor Property Sherda Auto Actor Property Qailash Auto Actor Property Tom Auto Actor Property Sugar Auto Link to comment Share on other sites More sharing options...
Tasheni Posted December 7, 2017 Author Share Posted December 7, 2017 (edited) Hi Ishara, thank you for the script, that's very appreciated. But I have errors when compiling: Starting 1 compile threads for 1 files...Compiling "_TasheniMonitorPlayerMounting"...C:\Program Files (x86)\Steam\Steamapps\common\Skyrim\Data\Scripts\Source\temp\_TasheniMonitorPlayerMounting.psc(28,27): variable asEventName is undefinedC:\Program Files (x86)\Steam\Steamapps\common\Skyrim\Data\Scripts\Source\temp\_TasheniMonitorPlayerMounting.psc(28,39): cannot compare a none to a string (cast missing or types unrelated)C:\Program Files (x86)\Steam\Steamapps\common\Skyrim\Data\Scripts\Source\temp\_TasheniMonitorPlayerMounting.psc(35,27): variable asEventName is undefinedC:\Program Files (x86)\Steam\Steamapps\common\Skyrim\Data\Scripts\Source\temp\_TasheniMonitorPlayerMounting.psc(35,39): cannot compare a none to a string (cast missing or types unrelated)No output generated for _TasheniMonitorPlayerMounting, compilation failed. I'm not enough a scripter to know what Papyrus wants from me. Can you take a look at this again? So after trying to grasp what this script does I'm a little bit confused. What I see is that you have put the followers and horses in an array (FollowerMount) But FollowerMount is nowhere called. And there is a function declared but the function is not called in the OnAnimationEvent. I tried to find a sample where asEventName is used in a function but found only the use in events. :huh: Scripting is so incomprehensible ... Edited December 7, 2017 by Tasheni Link to comment Share on other sites More sharing options...
IsharaMeradin Posted December 7, 2017 Share Posted December 7, 2017 Sorry, I missed that. Just change the function declaration to the following: Function FollowerMount(Actor myFollower, Actor myHorse, String asEventName) And call it as follows FollowerMount(Ruby,Assan,asEventName) FollowerMount(Chiomara,Dubha,asEventName) FollowerMount(Eldrid,Rasha,asEventName) FollowerMount(Sherda,Qailash,asEventName) FollowerMount(Ramgar,Fahgravel,asEventName) FollowerMount(Tom,Sugar,asEventName) There are no arrays. All I did was create a local function that performed the repeating tasks with variables to be passed in so that the function knows what to work with. The function is called within the OnAnimationEvent. It is called when akSource is the player. It is the same thing that you were doing. Only it doesn't require forcing any non-player instances out with the use of Return. It is still there cause it doesn't hurt, but it isn't required. Link to comment Share on other sites More sharing options...
Tasheni Posted December 7, 2017 Author Share Posted December 7, 2017 I must apologize, it was too late in the night and I was working too much on other improvements.I overlooked the name of the function, of course it's called in the event. :wallbash:I added the corrections and finished the dismount part and it works like a charm. And it's pretty fast. Thank you very much. Link to comment Share on other sites More sharing options...
JonathanOstrus Posted December 7, 2017 Share Posted December 7, 2017 (edited) One minor glitch still remains. In the modified refactor the dismount check have it forcing Ruby instead of MyFollower:If asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") Ruby.Dismount() Ruby.EvaluatePackage() EndIf It should be changed toIf asEventName == "tailHorseDismount" Debug.Notification ("Player dismounted") myFollower.Dismount() myFollower.EvaluatePackage() EndIf I'm not sure if that's what you meant about finishing the dismount part or not but thought I'd point it out in case. Edited December 7, 2017 by BigAndFlabby Link to comment Share on other sites More sharing options...
IsharaMeradin Posted December 7, 2017 Share Posted December 7, 2017 Apparently, I was out of it the other day... At least Tasheni got it working. Link to comment Share on other sites More sharing options...
Tasheni Posted December 8, 2017 Author Share Posted December 8, 2017 I'm not sure if that's what you meant about finishing the dismount part or not but thought I'd point it out in case.Yes, this is right. I have tested it today again over hours and I'm pretty happy with it. Followermounting and dismounting is now so much faster, that's a real good feature. Thank you, Ishara, greeting from Germany Link to comment Share on other sites More sharing options...
soupdragon1234 Posted December 8, 2017 Share Posted December 8, 2017 Part of the problem of them not mounting fast enough is that its a single threaded script it has to run through and check each and every single follower one by one, daisy chain fashion until it reaches the end. I got around the problem on my mod by making it multi-threaded each follower alias has copy of the same script that will fire upon player mount/dismount. The script itself is short and the event fires for each follower simulaneously making it much more efficient. Link to comment Share on other sites More sharing options...
JonathanOstrus Posted December 9, 2017 Share Posted December 9, 2017 Part of the problem of them not mounting fast enough is that its a single threaded script it has to run through and check each and every single follower one by one, daisy chain fashion until it reaches the end. I got around the problem on my mod by making it multi-threaded each follower alias has copy of the same script that will fire upon player mount/dismount. The script itself is short and the event fires for each follower simulaneously making it much more efficient. That's a decent method. Also reduces the necessary count of properties. In fact at quick thought I think you could remove all except 2, the faction and an alias to the horse. Link to comment Share on other sites More sharing options...
Recommended Posts