Tasheni Posted April 18, 2017 Share Posted April 18, 2017 (edited) Hi all, after trying a lot with my few abilities and your great help I decided to create a ring that sets my horse from a npc to a mount, when equipping and when unequipping back to a npc. This is the script, but it works not as I want it to do. To demonstrate what it does, I attach a video: Scriptname _PlayerOnHorseRingEquip extends ObjectReference Actor Property PlayerRef Auto ObjectReference Property ValaHorse Auto ObjectReference Property ValaNPC Auto Actor Property Vala Auto ;necessary because equipping items doesn't work on ObjectReference Armor Property Ring Auto Armor Property Saddle Auto Armor Property NPCSaddle Auto Actor Property ValaNPCActor Auto MiscObject Property MiscItemSaddle Auto Event OnEquipped(Actor akActor) ;if ring is equipped by player, turn Vala into a horse and saddle up. If PlayerRef.IsOnMount() ;avoid using the ring while mounted because game will crash Debug.Notification("You must dismount before using the ring") PlayerRef.UnequipItem(Ring, true, true) ;prevents player from equipping ring while mounted because game will crash. Else ValaNPC.disable () ValaHorse.enable () If PlayerRef.GetItemCount(MiscItemSaddle) == 1 ;player should have the saddle in his inventory PlayerRef.RemoveItem(MiscItemSaddle) ;remove saddle from player and let horse equip it EndIf Vala.EquipItem(Saddle) float az = PlayerRef.GetAngleZ() ;teleport horse near player - thank you cdcooley ValaHorse.MoveTo(PlayerRef, 80.0*Math.sin(az), 80.0*Math.cos(az), 10.0, 0) EndIf Vala.EvaluatePackage() EndEvent Event OnUnequipped(Actor akActor) ;turn Vala into NPC If PlayerRef.IsOnMount() Debug.Notification("You must dismount before removing the ring") ;prevents player from unequipping ring while mounted PlayerRef.EquipItem(Ring, false, true) Else ValaHorse.disable () ValaNPC.enable () ValaNPCActor.EquipItem(NPCSaddle) ;saddle should not be removed by the ring, only via player dialog float az = PlayerRef.GetAngleZ() ValaNPC.MoveTo(PlayerRef, 80.0*Math.sin(az), 80.0*Math.cos(az), 10.0, 0) EndIf ValaNPCActor.EvaluatePackage() EndEvent Sorry, I have not uncovered yet the secret of using the spoiler function. This works without crashes and does mostly what I want, but not all. So Horse will not show the NPCSaddle after unequipping the ring - only the first time I do it, it works, but then not anymore. I can only reach the saddlebags, if horse is an NPC and the saddle shows up. Take a look: https://www.youtube.com/watch?v=kHwC3mW3Fu8 I've tested it also without Convenient Horses - no conflicts showed up between these two mods. So first question, is there a way to force equipping the saddle on that NPCHorse? Second, this line does nothing: PlayerRef.UnequipItem(Ring, true, true) ;prevents player from equipping ring while mounted because game will crash. It only prevents to run the changing actor code but the ring will be equipped. Third, I don't understand the math code from cdcooley. Is there a way to turn the horse round, so that the player automatically stand on the left side of it? And which part handles the distance between horse and player? Sorry, I forgot, what cosinus and sinus do and I'm a completley math noob - that makes scripting an adventure :smile: Thank you for your time. Greetings, Tasheni Edited April 18, 2017 by Tasheni Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 18, 2017 Share Posted April 18, 2017 Secret of the spoiler function:Method #1 -- Third icon from the left on the top row just before the Font box in the post editor (it is a light bluish green and white box). When mouse hovered it should say Special BBCode. Simply click the icon and choose Spoiler in the drop down window. Works best when the text you want hidden is highlighted (thus the icon looks like a document with highlighted text).Method #2 -- Manually type it in. Works best when you want to hide multiple things such as several code boxes, images, videos, etc.Example: [spoiler-]content goes here[/spoiler-] (do not include the hyphens, they are needed to prevent the BBCode from functioning)Result: content goes here FYI - The code box can be done in a similar fashion. Its icon is the blue <> on the bottom row or typed manually (see spoiler code above and replace spoiler with code). Not sure I saw the problem in the video. Can you describe what is going wrong a bit more? Link to comment Share on other sites More sharing options...
Tasheni Posted April 18, 2017 Author Share Posted April 18, 2017 (edited) Hi Ishara, thanks for quick reply and for introduction of the spoiler :smile:. It works pretty nice. Quite easy - I'm completely blind.Problem is that equipping the saddle on the NPC works only the first time I unequip the ring. All further tryings switch the horse back to npc but the saddle won't show up again - I made a special npc version to it that works fine in the ck. But then I can't get to the saddlebags if saddle shows not up. Bad for inventory.Second is the code that should prevent player from equipping the ring while on mount. It's a minor bug, but a bit annoying.The ring is equipped despite the code, so nothing damages because the code for changing actor will not fire. But player has ring equipped when he should not. The consequence is that player has to unequip and equip it again, if he has changed the actor type to horse via dialog and not through the ring.This option is possible, because the player can chose if he wants to saddle the horse or not - using the ring will always saddle the horse. It's annoying because everytime he is equipping or unequipping the ring will let the horse vanish for short time, so it should not happen more often as needed.I hope my explanation is understandable. Please ask, if not. EDIT: Alright, after shutting down all programs and the computer the saddle shows up. I will try further to see, if it is a solid state. Edited April 18, 2017 by Tasheni Link to comment Share on other sites More sharing options...
Tasheni Posted April 18, 2017 Author Share Posted April 18, 2017 (edited) So when I wrote this script, I need hours for getting it to work. When I looked at it now I discovered that I used for the horse and the npc an ObjectReference.But I can't remember, why. I have a similar script written for the dialog and there I only used actor properties. And it works also.Can someone explain me what happens if using ObjectReference on actors? I think, I've done it for a reason but can't track back. Thank you very much. EDIT: After further testing it happens now that the player is kicked off the horse despite the IF-condition (PlayerRef.UnequipItem(Ring, true, true)) , but game crashes not. I think I'm too long on it today and will leave it, because I make more and more mistakes. Tomorrow with a well rested brain I'm perhaps luckier. But it's truly hard, how could one learn the right way if the behavior of the result is changing even one has not altered the code :( Edited April 18, 2017 by Tasheni Link to comment Share on other sites More sharing options...
ReDragon2013 Posted April 18, 2017 Share Posted April 18, 2017 I am still waiting for answers? https://forums.nexusmods.com/index.php?/topic/5464827-perk-entry-point-needs-a-script-but-what-to-put-in/page-3If you share enough infos, it makes sense for me to help. About "objectReference" and "actors" both are References which are tracked by the game engine. It's a matter of persistence!Do not use different scripts to hold the same References, that is very bad. Cheers Link to comment Share on other sites More sharing options...
Tasheni Posted April 18, 2017 Author Share Posted April 18, 2017 (edited) I am still waiting for answers? https://forums.nexusmods.com/index.php?/topic/5464827-perk-entry-point-needs-a-script-but-what-to-put-in/page-3If you share enough infos, it makes sense for me to help.Oh Schande über mich, das habe ich schlichtweg nicht gesehen. I'm sorry, really. Of course I will answer that - it's in my interest to get it to work and to learn. It's simply too much stuff to do with this mod, mostly getting the scenes and dialogs fired when they should fire, because I don't like it, when Tom talks about his falmer ear stew facing a dragon, or all six running a scene when I need them to get on the damn horses because time's running short. So messing around with conditions, packages and testing consumes 90 percent of development. It's my first mod I ever made. But I will win at the end - experience my fight with the damn ck! About "objectReference" and "actors" both are References which are tracked by the game engine. It's a matter of persistence!Do not use different scripts to hold the same References, that is very bad. Don't understand this. Both, actors and ObjectRefs are persistent, I think? There must be a difference between them, why are they otherwise different. I have different dialogs and these trigger scripts and in them I use of course the same refs, because I manipulate the same things, don't know how to do it other way. Also PlayerRef is many times used in different scripts of other mods, is that bad? (I learned that using PlayerRef is faster that Game.GetPlayer()) To get back to my problem in this post, I experience some strange behavior in game. I get different results, things that worked one day suddenly stop to do so, as it was with this script posted here. It happens frequently that I think, all is fine, but another day behavior of actors is suddenly different or broken and I go always one step forward and two back. And I always use a clean save and make my seq. It makes learning sometimes a frustrating trip to hell. I assure you, I will try until I get the best out of your help, it's very much appreciated and encourages me to go on. Greetings from damn icy cold germany, Tasheni Edited April 18, 2017 by Tasheni Link to comment Share on other sites More sharing options...
Tasheni Posted April 19, 2017 Author Share Posted April 19, 2017 So because I get questions ( and help again, yeah!) from ReDragon2013, I will lay open again what I'm doing and trying to achieve. What's done so far:- created actor ValaHorse (horse race) for riding - created actor ValaNPC (custom race) for talking - needed, because switching the race or assign an ActorTypeKeyword do not work to get the horse activator changed. - created a quest with dialog for the ValaNPC. If player meets the horse first time, he can talk to it and at the end of this short dialog is a script that adds a ring to player inventory. This ring is for changing Vala from horse to npc and back and also to teleport horse to player if it was forgotten somewhere or is waiting or else. First I had created a summon spell but I'm not satisfied with this, because casting takes too much time and I experienced, that I can't summon horse (or other npcs) if they are in waiting state. The ring is a very comfortable and elegant solution I feel. - created ValaOrderRing. Script I posted above is attached there and works mostly fine. Sometimes I need to equip the ring twice to get the horse saddled. I don't know, why. Sometimes the code part that should prevent the player to use the ring while on horse works not as intended and it catapults player of the horse because it's changing to npc. It is important that the player will be prevented to use the ring on horseback because game crashes if he does. This is meant for both actions, equip or unequip. - created dialog with a script attached at the end to saddle the horse, if player don't want to use the ring, because that's more realistic and for immersion. This script changes the actor to horse and put the saddle on the back of it, so player can ride. Works fine. - created dialog and attached script at the end to remove the saddle from horseback and - or - change the actor to npc without removing the saddle, so that player can give orders like wait, follow or go home or something (go home is not implemented yet, because I don't know yet how to do it). This action is the same the ring does, if unequipped. Why not only using the ring? The ring saddles the horse when changing the actor automatically and this is faster. But perhaps player want to ride without saddle. So with the dialog it can be done. - created dialog for Eldrid in her own quest to care for the horses (Vala and her horse), saddle or unsaddle them. At the end of the dialog is a script that starts a scene in the HorseDialogQuest. - created scenes for Eldrid, she goes to the horses and saddle or unsaddle them and is talking with them. At the end of the talking dialog script starts, that unsaddle the horses and set them to wait state but changes not the horse Vala into an npc. And the other way round script saddles the horses and set them back to follow state. Big problem here: If player goes through a load door and returns, the horses are always unsaddled! So I have different states for the horse: - unsaddled as npc - saddled as npc - unsaddled as horse - saddled as horse (hey, when I was a little girl, that was pretty nice to saddle or unsaddle a horse myself. I know, some of you may think that's wasted time, but are you not collecting wood for the fire in campfire and love it? Or craft your armor instead of buying it? I like realistic horses and I know that there's a limit to get them but I will try. And perhaps I will create an enchanted horse that talks to the player - who knows.) - created a saddle that works for the ValaNPC because NPCs can't wear saddles. So far it works but I'm not sure if my scripting will make problems, because I'm no coder. In my unmodded game and also with Convenient Horses installed it works without crashes or something. What I want to improve now: - If the saddle is removed from horse it should be added to player inventory. A saddle has a weight from perhaps 20 to 30 kilos, if it's a lightweight and not a western and this should be added to players weight. Player should be able to place the saddle somewhere, if it's not needed. - Player should not be able to place the saddle on horse if he hasn't it in his inventory. - Saddles should be available at vendors or perhaps through crafting. - When horse is teleportet to player it should appear with it's left side to player because mounting animation is always from the left - it's a minor wish that wood be pretty nice. - Player horse Vala should be available through a short quest. For now it's directly running to player from the beginning and following, because it's timesaving in this test phase. So that's it so far. This reflection helps me to get clear of the things and I hope for you, too. I'm proud that I've come so far - never realised before, that it's all so immense complicated. I have a thousand questions more, but I will leave it with that for now. Small steps are better than overwhelming undertakings. Any of your suggestions are welcome.Mod is growing, is fun to me and hopefully soon to others. Thank you all for your patience. Greetings from Tasheni Link to comment Share on other sites More sharing options...
IsharaMeradin Posted April 19, 2017 Share Posted April 19, 2017 If having the ring in the inventory while the player is mounted is having issues, why not transfer the ring to a hidden container when the player mounts and transfer back when they dismount? If using SKSE you could use OnPlayerCameraState event to initiate the transfer of the ring to and from the container. Something like Event OnPlayerCameraState(int oldState, int newState) If newState == 10 ; on horse - oldState value does not matter ;transfer ring from actor to container MyActor.RemoveItem(MyRing,1,true,MyContainer) ElseIf oldState == 10 ; not on horse - newState value does not matter ;transfer ring from container to actor MyContainer.RemoveItem(MyRing,1,true,MyActor) EndIf EndEvent ;MyActor = whatever actor will be riding the horse, most likely the player ;MyRing = the ring that switches horse actors ;MyContainer = the hidden container (use a custom interior cell and place a duplicated player house container inside) ;If necessary, you can check that the item is present in the container/inventory being moved from as a requirement before moving. Link to comment Share on other sites More sharing options...
Tasheni Posted April 19, 2017 Author Share Posted April 19, 2017 Thank you for your code, Ishara, but I have a question: If I remove the ring via script into a container, what happens then with the script attached to the ring? Because it runs when player unequip the ring and then change the horse. Is it not the same when I remove the ring - player must unequip it first - or doesn't it affect this event? I will try it out. I already have a dummycell and a chest is easy to implement there. It will take some days because of real life ;( Thank you so much for now, I report back. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted April 19, 2017 Share Posted April 19, 2017 (edited) Actor vs. ObjectReferenceyou wrote: "Don't understand this. Both, actors and ObjectRefs are persistent, I think? There must be a difference between them, why are they otherwise different."1) Every actor is also an objectReference in game, but an objectReference can be an actor or not! ScriptName Actor extends ObjectReference2) As you can see, actors are a subclass of objectReference. They have special member functions as follow: http://www.creationkit.com/index.php?title=Actor_Script3) Actors are "dynamic objects" like creatures, animals, citiziens .. Objects are almost "static" ObjectReferences like flowers, trees, weapons, armor ..Objects/actors receive next both events EVENT OnCellAttach() ; player is sharing the same cell with objectRefs/actors in this parent cell ; player goes into the cell ENDEVENT EVENT OnCellDetach() ; player is leaving the parent cell, objectRefs/actors keeps left outside of players parent cell ; player goes out of the cell ENDEVENTand now only actors should trigger the next events, because they move or get moving EVENT OnAttachedToCell() ; the actor enters and is sharing the parent cell with player ; actor goes into players parent cell ENDEVENT EVENT OnDetachedFromCell() ; the actor is leaving players parent cell ; actor goes out of attached cell ENDEVENT and only actor can do special things like bleeding, changing combat, .. EVENT OnCombatStateChanged(Actor akTarget, Int aeCombatState) ; actor is going to fight (1), is looking for enemy (2), is leaving the combat (0) ENDEVENT EVENT OnEnterBleedOut() ; actor triggers bleeding out ENDEVENT EVENT OnDying(Actor akKiller) ; actor is near of dead ENDEVENT EVENT OnDeath(Actor akKiller) ; actor is dead and bones, only resurrection brings him back to life ENDEVENT EVENT OnRaceSwitchComplete() ; actor has now a new race ENDEVENT EVENT OnSit(ObjectReference akFurniture) ; actor is sitting down to akFurniture ENDEVENTand two event for the player actor only EVENT OnPlayerLoadGame() ; every time a savegame is loaded, runs that on player alias scripts only ENDEVENT EVENT OnPlayerBowShot(Weapon akWeapon, Ammo akAmmo, Float afPower, Bool abSunGazing) ENDEVENT Edited April 19, 2017 by ReDragon2013 Link to comment Share on other sites More sharing options...
Recommended Posts