# Author: Steeveeo # Updated: Aug 6, 2010 @ 9:10 AM PST (-8 GMT) # Use and Purpose: # Place this chip on the main prop of your ship and say # '!parent' in chat. This will do all the work for you # to have a properly working and non-laggy parented ship. # Note that this does auto-weight props, so if your gyropod # is setup for a different weight, you may have to adjust. # # To share this chip, just say 'share mode' in chat before placing. # Fair Use and Legality: # This chip is provided as is and is designed to work only # as instructed. This is provided under Creative Commons and # may be modified and/or shared with anyone as long as proper # credit is given to the original author (Steeveeo). Failure to # give credit by plagiarising or removing this header is subject # to administrative punishment. @name E2 Tool - Autoparenter @inputs @outputs @persist Parts:array Parent:entity Step CommandStack:array #Options @persist Option_Constrain Option_Weight Option_GravPlate @trigger runOnChat(1) #Startup if(first()) { #Check if constrained if(!entity():isConstrained() & owner():lastSaid():lower() != "share mode") { print("Please place this on a contraption to begin") selfDestruct() } elseif(entity():isConstrained()) { print("Caching structure parts, say '!parent' to begin.") Parent = entity():isConstrainedTo() Parts = entity():getConstraints() } #Option Defaults Option_Constrain = 0 Option_Weight = 0 Option_GravPlate = 0 } #Begin parenting if(chatClk(owner()) & owner():lastSaid():lower() == "!parent") { #------------ # Derma Menu #------------ #Panel dPanel("Main_Control_Panel",vec2(scrW()*0.05,scrH()*0.15),vec2(300,200)) dText("Main_Control_Panel","E2 Autoparenter") #Instructions dLabel("Check each option to perform, then hit Start.","Main_Control_Panel",vec2(10,30)) #Contraint Checkbox dCheckBox("Optimize_Constraints","Main_Control_Panel",vec2(15,60)) dText("Optimize_Constraints","Optimize Constraints") dRunOnChange("Optimize_Constraints",1) #Weight Checkbox dCheckBox("Optimize_Weights","Main_Control_Panel",vec2(15,80)) dText("Optimize_Weights","Optimize Weights") dRunOnChange("Optimize_Weights",1) #Gravplating Checkbox dCheckBox("Apply_Gravplate","Main_Control_Panel",vec2(15,100)) dText("Apply_Gravplate","Apply GravPlate") dRunOnChange("Apply_Gravplate",1) #Apply Button dButton("Start","Main_Control_Panel",vec2(215,155),vec2(75,35)) #Capture Mouse enableMouse(1) #--End of Derma Menu-- } #--------------------- # Derma Functionality #--------------------- #Constraint Option if(dClk("Optimize_Constraints")) { Option_Constrain = dNval("Optimize_Constraints") } #Weighting Option if(dClk("Optimize_Weights")) { Option_Weight = dNval("Optimize_Weights") } #GravPlate Option if(dClk("Apply_Gravplate")) { Option_GravPlate = dNval("Apply_Gravplate") } #Start if(dClk("Start")) { print("Initializing AutoParent, DO NOT TOUCH YOUR SHIP UNTIL THIS IS COMPLETE!") #Close Derma enableMouse(0) dShow("Main_Control_Panel",0) #Compile Commands onto stack, then start (will always freeze first and parent last) CommandStack[1,string] = "Freeze" if(Option_Constrain) { CommandStack[CommandStack:count()+1,string] = "Unconstrain" } if(Option_Weight) { CommandStack[CommandStack:count()+1,string] = "Weights" } if(Option_GravPlate) { CommandStack[CommandStack:count()+1,string] = "GravPlate" } CommandStack[CommandStack:count()+1,string] = "Parent" #printTable(CommandStack) timer("CallStack",100) } #--End of Derma-- #-------------------------- # Command Stack Controller #-------------------------- if(clk("CallStack")) { if(CommandStack:count()) { Call = CommandStack:removeString(1) #print("Calling " + Call) Step = 0 timer(Call,100) } else { print("[PARENTER] - Error! Got to end of stack before parenting!") selfDestruct() } } #--End of Stack Control-- #--------------- # Functionality #--------------- #Freeze all props if(clk("Freeze")) { #From here on out, these are expensive processes, so we need to do this in chunks Index = 1+(10*Step) End = 0 while(Index <= 10+(10*Step)) { if(Index != Parts:count()+1) { Parts[Index,entity]:freeze() Index++ } else { #Back to the Stack timer("CallStack",100) print("Freezing finished.") End = 1 break } } #Check if we did not hit the end, start next step if(!End) { Step++ timer("Freeze",100) } } #Unconstrain everything if(clk("Unconstrain")) { Index = 1+(10*Step) End = 0 while(Index <= 10+(10*Step)) { if(Index != Parts:count()+1) { Parts[Index,entity]:unConstrain() Index++ } else { #Call the Rewelder Step = 0 timer("Reweld",100) print("Unconstrain finished, welding to parent.") End = 1 break } } #Check if we did not hit the end, start next step if(!End) { Step++ timer("Unconstrain",100) } } #ReWeld everything to Parent if(clk("Reweld")) { Index = 1+(10*Step) End = 0 while(Index <= 10+(10*Step)) { if(Index != Parts:count()+1) { if(Parts[Index,entity] != Parent) { Parts[Index,entity]:weld(Parent) } Index++ } else { #Back to the Stack timer("CallStack",100) print("Constraint Optimizations Complete.") End = 1 break } } #Check if we did not hit the end, start next step if(!End) { Step++ timer("Reweld",100) } } #Weight everything dynamically if(clk("Weights")) { Index = 1+(10*Step) End = 0 while(Index <= 10+(10*Step)) { if(Index != Parts:count()+1) { Part = Parts[Index,entity] if(Part == Parent) { Part:setMass(50000) } elseif(Part:type() == "prop_physics" | Part:type() == "prop_physics_multiplayer") { Part:setMass(200) } else { Type = Part:type():lower() if(Type:find("resource") | Type:find("storage") | Type:find("gen") | Type:find("regulator") | Type:find("gyropod")) { Part:setMass(50) } else { Part:setMass(1) } } Index++ } else { #Back to the Stack timer("CallStack",100) print("Weighting finished.") End = 1 break } } #Check if we did not hit the end, start next step if(!End) { Step++ timer("Weights",100) } } #GravPlate all props if(clk("GravPlate")) { Index = 1+(10*Step) End = 0 while(Index <= 10+(10*Step)) { if(Index != Parts:count()+1) { Parts[Index,entity]:setGravPlate(1) Index++ } else { #Back to the Stack timer("CallStack",100) print("GravPlating finished.") End = 1 break } } #Check if we did not hit the end, start next step if(!End) { Step++ timer("Freeze",100) } } #Parenting time if(clk("Parent")) { Index = 1+(10*Step) End = 0 while(Index <= 10+(10*Step)) { if(Index != Parts:count()+1) { if(Parts[Index,entity] != Parent & !Parts[Index,entity]:isVehicle()) { Parts[Index,entity]:parentTo(Parent) } Index++ } else { #End it print("Parenting complete, you may now fly this ship.") End = 1 break } } #Check if we did not hit the end, start next step if(!End) { Step++ timer("Parent",100) } else { selfDestruct() } } #--End of Functions--