Scripting:Duranium Extractor
From STNE Wiki
STNE is a Strategy and Role Play Game. You can play here.
Contents | STNE | Colonies | Buildings | Goods | Items | NPC | Ships | Stellar Cartography | Research | Trade | Combat | Settler | Alliances | Index |
---|
Main | Syntax | Operators | Interfaces | FAQ | Contents | API Reference | Index |
---|
Duranium Extractor
On entering this portal, the hosting ship will attempt to tractor all debris fields in the sector and extract Duranium from them. Script created by Glest Durnham
Code
#UseInterface Web, ShipPortal; If(GuestUser.UserID = MyShip.UserID) { Var curShip As CShip; Var dockedTo As Integer = - 1; Var oldQuantity As Integer = 0; Var oldTotalQuantity As Integer = MyShip.StockRoom.Amount(EGoodsType.Duranium); Var collected As Integer = 0; // Loop all ships in the sector For (Each curShip In MyShip.SRS) { // Make sure it's a debris field. If (isDebris(curShip)) { // Activate SRS If ( NOT MyShip.SRSIsActive) { MyShip.Action.ActivateSRS(True); log(MyShip.Name & " (NCC " & MyShip.ShipID & ") activated SRS."); } // Undock If (MyShip.Docked) { dockedTo = MyShip.DockedToShipID; MyShip.Action.Undock(); If ( NOT MyShip.Docked) { log(MyShip.Name & " (NCC " & MyShip.ShipID & ") undocked."); } Else { log(MyShip.Name & " (NCC " & MyShip.ShipID & ") failed to undock."); } } oldQuantity = MyShip.StockRoom.Amount(EGoodsType.Duranium); // Perform the action MyShip.Action.DeactivateTractorBeam() MyShip.Action.ActivateTractorBeam(curShip.ShipID) MyShip.Action.ExtractFromWreck(1000); // Calculate the result collected = MyShip.StockRoom.Amount(EGoodsType.Duranium) - oldQuantity; // Output result log("Collected " & collected & " Duranium from " & curShip.Name & " (NCC " & curShip.ShipID & ") ."); } } // Calculate the result collected = MyShip.StockRoom.Amount(EGoodsType.Duranium) - oldTotalQuantity; log("Total: collected " & collected & " Duranium."); // Re-dock If (dockedTo > - 1) { MyShip.Action.DockTo(dockedTo); If (MyShip.Docked AND MyShip.DockedToShipID = dockedTo) { log(MyShip.Name & " (NCC " & MyShip.ShipID & ") docked to " & MyShip.DockedTo.Name & " (NCC " & MyShip.DockedToShipID & ")."); } Else { log(MyShip.Name & " (NCC " & MyShip.ShipID & ") failed to redock."); } } } Function isDebris(ship As CShip) As Boolean { Return ship.Name.EndsWith(" (destroyed)") OR ship.Name.EndsWith(" (self destroyed)"); } Function log(msg As String) { Response.Add(msg); Response.Add(New CHtmlBreak()); }