Search the Community
Showing results for tags 'movable ship'.
Found 1 result
I need advice and help with a script
Tasheni posted a topic in Mod Support and DiscussionsDear fellows, I have implemented a big ship into my isles mod I want to use as a player's home and to transport followers. I used the same script I have already attached to my trading boat, but I can't get it to work the way I want. I used the script from the mod Sailable Ships and changed it to my needings and it works fine for my boats. But this solution maybe not the best for what I want to do now: Sail a big ship, move followers onboard, use two doors for getting into interior, a ladder as activator at the outer shipwall to being teleported from water onto the ship. What I have so far: Ship is sailable and the wheel activator and the doors move to the right place, when player toggles the anchor. Two ship interior cells I can enter, but not exit anymore. 1: I can toggle sails and anchor and start sailing. Sometimes when I exit sailing with the e key, player gets stuck and nothing but quit the game helps - it worked fine, but suddenly stops working. 2:There are problems with SetVehicle. I placed an XMarker in front of the shipswheel, but player is always attached outside the ship. When I start to sail. player is moved to the middle of the ship. When I exit sailing and activate the shipswheel again, player is positioned right. How can I get the player fixed? I don't really understand how SetVehicle works, because the XMarker is not moving with the ship? 3: I can enter my ship interior, but there is no activator to leave the cell. I guess this is due to the system the whole thing is setup. If you have any ideas, please read on. I explain now the setup and will post the used script: Setup: A dummy cell that includes the static ship with furled sails, an XMarker as movement point, two invisible actors and two load doors. On water: the movable ship with unfurled sails, an XMarker to attach the player to the ship with SetVehicle, and invisible activator at the shipswheel. If player activates the wheel, a messagebox pops up: Toggle sail and anchor or start/stop sailing. If player toggles the anchor, the static ship spawns from the dummy cell at the exact place of the movable ship, the doors are moved to the right place at the ship, the movable ship moves to dummy cell marker. Sails are furled and player can now go inside. If player starts sailing, the doors and the wheel activator are moved to the dummy cell. Player gets attached to the movable ship. When pressing e key, sailing stops, the activator moves from dummy cell back to the wheel. If there is a better solution to achieve my goals, please tell me. And if you want to help me scripting, this is much appreciated. Here comes the script: Scriptname _Tash_ShipRedguardActivatorScript extends ObjectReference ;-- Properties -------------------------------------- static property StaticShip auto ; static ship in dummy cell ObjectReference property MyBoat auto ;actually used ship idle property SitAnim auto actor property BackActor auto ;swimming invisible actor in dummy cell - they are used to detect if ship crashes on land or against an obstacle sound property WaterChurn auto ;ship's noise sound property CollisionSound auto ;if ship crashes on land or obstacle ObjectReference property SpawnedStaticShip auto ;static ship spawned from reference ship in dummy cell sound property BoatSound auto ;ship's second noise message property LongBoatMenu auto ;activation menu for sailing or toggling anchor and sails actor property FrontActor auto ;swimming invisible actor in dummy cell ObjectReference property SeatVehicle auto ;XMarker to attach player to the ship for translation actor property PlayerRef auto ObjectReference property StaticShipMarker auto ;XMarker in dummy cell where the ships are moved ObjectReference property ShipDoorCabin Auto ;Load door for cabin interior ObjectReference property ShipDoorBase Auto Load door for basement interior ;-- Variables --------------------------------------- Int DefLef = 30 ;left Float MaxReverseSpeed Float ZBoatPosition Int DefBac = 31 ;back Bool ToggleAnchor Float CurrentSpeed Int DefRig = 32 ;right Float FrontOffset Bool Activated Float YBoatPosition Float DefaultTiltAngle Int n Float BoatAngleSpeed Float BoatTiltAngle Float MenDepthOffset ;depth of swimming actors Float dir ;movement direction Float BoatAngle Float FrontBackMenOffset ;swimming actors distance from boat Float DefaultAngleSpeed Bool ToggleDrive Float XBoatPosition Int WaterChurnInstanceID Int BoatCreakSoundID Int DefFor = 17 ;forward Float MaxSpeed ;-- Functions --------------------------------------- function OnUpdate() ;get ship position, movement direction and speed. Invisible swimming actors simulate the collision with land ;I need to adjust the values to get it right for this big ship XBoatPosition = MyBoat.GetPositionX() YBoatPosition = MyBoat.GetPositionY() ZBoatPosition = MyBoat.GetPositionZ() BoatAngleSpeed = DefaultAngleSpeed if input.IsKeyPressed(DefFor) || input.IsKeyPressed(DefBac) if input.IsKeyPressed(DefFor) && FrontActor.IsSwimming() if CurrentSpeed > 0 as Float && dir == -1 as Float CurrentSpeed -= 10 as Float dir = -1 as Float elseIf CurrentSpeed < MaxSpeed CurrentSpeed += 10 as Float dir = 1 as Float endIf elseIf input.IsKeyPressed(DefBac) && BackActor.IsSwimming() if CurrentSpeed > 0 as Float && dir == 1 as Float CurrentSpeed -= 10 as Float dir = 1 as Float elseIf CurrentSpeed < MaxReverseSpeed CurrentSpeed += 10 as Float dir = -1 as Float endIf elseIf !FrontActor.IsSwimming() || !BackActor.IsSwimming() CollisionSound.play(PlayerRef as ObjectReference) CurrentSpeed = 0 as Float endIf elseIf CurrentSpeed > 0 as Float CurrentSpeed -= 5 as Float else MyBoat.StopTranslation() game.GetPlayer().StopTranslation() if !ToggleDrive self.UnregisterForUpdate() endIf endIf if CurrentSpeed > 0 as Float if input.IsKeyPressed(DefLef) BoatAngle += -BoatAngleSpeed if BoatAngle <= -360 as Float BoatAngle = 0 as Float endIf BoatTiltAngle = 2 as Float endIf if input.IsKeyPressed(DefRig) BoatAngle += BoatAngleSpeed if BoatAngle >= 360 as Float BoatAngle = 0 as Float endIf BoatTiltAngle = -2 as Float endIf endIf sound.SetInstanceVolume(WaterChurnInstanceID, CurrentSpeed / MaxSpeed) YBoatPosition += dir * -CurrentSpeed * math.Sin(BoatAngle) XBoatPosition += dir * CurrentSpeed * math.Cos(BoatAngle) Float YPlayerPos = YBoatPosition - (-400*math.sin(BoatAngle)) ;400 being the players displacement from the centre of the boat Float XPlayerPos = XBoatPosition - (400* math.cos(BoatAngle)) ;y direction is negative MyBoat.TranslateTo(XBoatPosition, YBoatPosition, ZBoatPosition, BoatTiltAngle, 0 as Float, BoatAngle + FrontOffset, CurrentSpeed, 0 as Float) game.GetPlayer().TranslateTo(XPlayerPos, YPlayerPos, ZBoatPosition + 580 as Float, 0 as Float, 0 as Float, BoatAngle, CurrentSpeed, 0 as Float) FrontActor.MoveTo(MyBoat, FrontBackMenOffset * math.Sin(MyBoat.GetAngleZ()), FrontBackMenOffset * math.Cos(MyBoat.GetAngleZ()), -MenDepthOffset, true) BackActor.MoveTo(MyBoat, -FrontBackMenOffset * math.Sin(MyBoat.GetAngleZ()), -FrontBackMenOffset * math.Cos(MyBoat.GetAngleZ()), -MenDepthOffset, true) if ToggleDrive self.RegisterForSingleUpdate(0 as Float) endIf endFunction function RebindKeys(Int KeySel, Int Code) ;unused if KeySel == 0 DefFor = Code debug.Notification("Forward key has been rebound") elseIf KeySel == 1 DefBac = Code debug.Notification("Back key has been rebound") elseIf KeySel == 2 DefRig = Code debug.Notification("Right key has been rebound") elseIf KeySel == 3 debug.Notification("Left key has been rebound") DefLef = Code else debug.Notification("Keys reset to default arrow keys") DefFor = 17 DefBac = 31 DefLef = 30 DefRig = 32 endIf endFunction function MenuActivated() ;player can unfurl the sails and lift the anchor for sailing or drop the anchor and furl the sails for docking Int MenuValue = LongBoatMenu.Show(0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000) if MenuValue == 0 ToggleDrive = !ToggleDrive if ToggleDrive as Bool && !ToggleAnchor ;if anchor is lifted and sailing is activated ShipDoorCabin.Disable() ShipDoorBase.Disable() game.ForceFirstPerson() game.DisablePlayerControls(true, false, true, false, false, false, true, false, 0) PlayerRef.SetVehicle(SeatVehicle) ;xmarker (SeatVehicle) on ship not working? player is never fixed there PlayerRef.SetGhost(True) WaterChurnInstanceID = WaterChurn.play(PlayerRef as ObjectReference) BoatCreakSoundID = BoatSound.play(PlayerRef as ObjectReference) sound.SetInstanceVolume(BoatCreakSoundID, 1.00000) self.MoveTo(StaticShipMarker, 0.000000, 0.000000, 0.000000, true) ; activator is moved to dummy cell PlayerRef.PlayIdle(SitAnim) ;not working self.UnregisterForUpdate() self.RegisterForKey(DefFor) self.RegisterForKey(DefLef) self.RegisterForKey(DefRig) self.RegisterForKey(DefBac) self.RegisterForKey(18) self.RegisterForSingleUpdate(0 as Float) elseIf !ToggleDrive && !ToggleAnchor ;player did exit sailing with e key ShipDoorCabin.Enable() ShipDoorBase.Enable() game.EnablePlayerControls(true, true, true, true, true, true, true, true, 0) self.UnregisterForAllKeys() self.UnregisterForUpdate() PlayerRef.StopTranslation() PlayerRef.SetVehicle(none) PlayerRef.SetGhost(False) sound.StopInstance(WaterChurnInstanceID) sound.StopInstance(BoatCreakSoundID) CurrentSpeed = 0 as Float ;player has toggled the anchor: move activator and doors to static ship self.MoveTo(MyBoat, 700 as Float * math.Sin(MyBoat.GetAngleZ()), 700 as Float * math.Cos(MyBoat.GetAngleZ()), 580 as Float, true) ShipDoorCabin.MoveTo(SpawnedStaticShip, 640 as Float * math.Sin(SpawnedStaticShip.GetAngleZ()), 640 as Float * math.Cos(SpawnedStaticShip.GetAngleZ()), 340 as Float, true) ShipDoorBase.MoveTo(SpawnedStaticShip, 0 as Float * math.Sin(SpawnedStaticShip.GetAngleZ()), 0 as Float * math.Cos(SpawnedStaticShip.GetAngleZ()), 340 as Float, true) else debug.MessageBox("You must raise the anchor before sailing") ToggleDrive = !ToggleDrive endIf elseIf MenuValue == 1 if !ToggleDrive self.DropAnchor() else debug.MessageBox("You must stop sailing before dropping anchor") endIf endIf endFunction function OnKeyUp(Int keyCode, Float holdTime) ;does nothing? if keyCode == 18 Debug.Trace("Key released after " + holdTime + " seconds") self.MenuActivated() endIf endFunction function DropAnchor() ToggleAnchor = !ToggleAnchor ;if anchor is down and sails furled, spawns a static ship at the exact position of the movable ship. Moves movable ship to dummy cell ;moves activator from dummy cell to static shipswheel, moves doors from dummy cell at their position on static ship if ToggleAnchor SpawnedStaticShip = MyBoat.PlaceAtMe(StaticShip as form, 1, false, false) MyBoat.MoveTo(StaticShipMarker, 0.000000, 0.000000, 0.000000, true) self.MoveTo(SpawnedStaticShip, 700 as Float * math.Sin(SpawnedStaticShip.GetAngleZ()), 700 as Float * math.Cos(SpawnedStaticShip.GetAngleZ()), 580 as Float, true) ShipDoorCabin.MoveTo(SpawnedStaticShip, 640 as Float * math.Sin(SpawnedStaticShip.GetAngleZ()), 640 as Float * math.Cos(SpawnedStaticShip.GetAngleZ()), 340 as Float, true) ShipDoorBase.MoveTo(SpawnedStaticShip, 0 as Float * math.Sin(SpawnedStaticShip.GetAngleZ()), 0 as Float * math.Cos(SpawnedStaticShip.GetAngleZ()), 340 as Float, true) debug.MessageBox("You have dropped the anchor.") else ;moves movable ship from dummy cell to static ship and disables the static ship MyBoat.MoveTo(SpawnedStaticShip, 0.000000, 0.000000, 0.000000, true) SpawnedStaticShip.DisableNoWait(false) SpawnedStaticShip.Delete() debug.MessageBox("You have lifted the anchor.") endIf endFunction function OnActivate(ObjectReference akActionRef) ;choice menu: sailing, anchor and sail toggling or exit self.MenuActivated() endFunction function OnInit() ;set ship speed and movement direction. Set distance from ship for invisible actors. Set movement keys to WSAD MaxSpeed = 400 as Float MaxReverseSpeed = 400 as Float DefaultAngleSpeed = 2 as Float DefaultTiltAngle = 2 as Float FrontOffset = 90 as Float FrontBackMenOffset = 780 as Float dir = 1 as Float MenDepthOffset = 30 as Float DefFor = 17 DefBac = 31 DefLef = 30 DefRig = 32 endFunction I do not understand everything the script does. It's all trial and error for me. The values for the translation and distance of the invisible actors i.e. I simply tried different values until it worked. What do you say? Screenshots here: https://www.afkmods.com/index.php?/gallery/album/149-tashenis-the-isles-of-teia/