Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Gyropod V3 by Starkkz
- #Basic inputs
- @inputs EyePod:wirelink Core:entity Active Unfreeze Level RollLock Boost
- #Movement inputs
- @inputs Forward Back MoveLeft MoveRight MoveUp MoveDown
- #Angle inputs
- @inputs PitchUp PitchDown PitchAbs YawLeft YawRight YawAbs RollLeft RollRight RollAbs
- #Multiplier inputs
- @inputs PitchMult YawMult RollMult SpeedMult
- #Aiming inputs
- @inputs AimMode AimX AimY AimZ AimVec:vector
- #Gyropod outputs
- @outputs Angle:angle Velocity:vector AngularVelocity:angle
- @outputs Mass
- #Global variables
- @persist Initialized LastEnv:string
- @persist Control ControlIndex
- @persist CurrentMass
- @persist Parent:entity Parts:array
- if (dupefinished()){reset()}
- function setName2(Text:string){
- setName("Gyropod V3 by Starkkz\n"+Text)
- }
- function normal pitchMult(){
- if (PitchMult){
- return PitchMult
- }
- return 1
- }
- function normal yawMult(){
- if (YawMult){
- return YawMult
- }
- return 1
- }
- function normal rollMult(){
- if (RollMult){
- return RollMult
- }
- return 1
- }
- function normal speedMult(){
- if (SpeedMult){
- return SpeedMult
- }
- return 1
- }
- function updateParent(){
- Parent = entity():parent()
- if (!Parent){Parent = entity():isConstrainedTo()}
- if (!Parent){Parent = entity()}
- Parts = Parent:getConstraints()
- Parts[Parts:count() + 1, entity] = Parent
- LastEnv = Parent:lsName()
- }
- function controlParts(){
- if (Control > 0){
- while (ControlIndex <= Parts:count()){
- if (minquota() <= 100){
- timer("controlParts", 1)
- exit()
- }
- local Part = Parts[ControlIndex, entity]
- if (Control == 1){
- #Check constraints
- if (Part != Parent & !Part:isVehicle()){
- if (Part:isWeldedTo() == Parent){
- if (Part:parent() == noentity()){
- Part:propFreeze(1)
- }
- Part:unConstrain()
- if (Core){Part:weld(Core)}
- Part:noCollide(Parent)
- }elseif (Part:isWeldedTo() != Core){
- Part:unWeld()
- Part:weld(Core)
- }
- }
- }elseif (Control == 2){
- #Calculate mass
- CurrentMass = CurrentMass + Part:mass()
- }elseif (Control == 3){
- #Freeze
- Part:propFreeze(1)
- }elseif (Control == 4){
- #Unfreeze
- Part:propFreeze(0)
- }elseif (Control == 5){
- #Disable gravity
- Part:propGravity(0)
- }elseif (Control == 6){
- #Enable gravity
- Part:propGravity(1)
- }
- ControlIndex = ControlIndex + 1
- }
- }
- if (ControlIndex > Parts:count()){
- if (Control == 1){
- timer("checkConstraints", 20000)
- if (Parent == entity()){
- setName2("Using E2 as parent")
- }else{
- setName2("Found parent\nCached "+Parts:count()+" entities")
- }
- Initialized = 1
- }elseif (Control == 2){
- Mass = CurrentMass
- CurrentMass = 0
- timer("calculateMass", 10000)
- }
- ControlIndex = 0
- Control = 0
- }
- }
- function update(){
- if (Active){
- local Pitch = PitchUp - PitchDown + PitchAbs
- local Yaw = YawLeft - YawRight + YawAbs
- local Roll = RollLeft - RollRight + RollAbs
- local AngleVel = ang(Pitch, Yaw, Roll) * 15
- if (EyePod){
- AngleVel = AngleVel - ang(EyePod["Y", normal], EyePod["X", normal], 0):setRoll(0) * 10
- }
- if (Level){
- AngleVel = -Parent:angles():setYaw(-AngleVel:yaw()) * 4
- }elseif (RollLock){
- AngleVel = -Parent:angles():setYaw(-AngleVel:yaw()):setPitch(-AngleVel:pitch()) * 4
- }elseif (AimMode){
- local Vec = vec(AimX, AimY, AimZ)
- if (AimVec){Vec = AimVec}
- AngleVel = -Parent:heading(AimVec) * 5
- }
- AngleVel = ang(AngleVel:pitch() * pitchMult(), AngleVel:yaw() * yawMult(), AngleVel:roll() * rollMult())
- local MoveX = Forward - Back
- local MoveY = MoveRight - MoveLeft
- local MoveZ = MoveUp - MoveDown
- local VelMult = 800
- if (Boost){VelMult = 5000}
- local Vel = (Parent:forward() * MoveX + Parent:right() * MoveY + Parent:up() * MoveZ) * speedMult() * VelMult
- Parent:setVel(Vel)
- Parent:setAngVel(shiftR(AngleVel))
- }
- }
- if (first()){
- #Initialize
- runOnLast(1)
- updateParent()
- timer("checkConstraints", 1)
- timer("calculateMass", 1000)
- timer("update", 1000)
- }elseif (last()){
- #End
- }
- if (Parent & Parent:lsName() != LastEnv){
- LastEnv = Parent:lsName()
- if (Active){timer("Activate", 1)}
- }
- if (~Active){
- if (Active){
- timer("Activate", 1)
- }else{
- timer("Deactivate", 1)
- }
- EyePod["Enable", normal] = Active
- }elseif (~Unfreeze){
- if (Unfreeze){
- timer("Unfreeze", 1)
- }else{
- timer("Freeze", 1)
- }
- }elseif (clk("controlParts")){
- controlParts()
- }elseif (clk("update")){
- if (Initialized){
- update()
- }
- timer("update", 200)
- }elseif (clk("Activate")){
- if (Control == 0){
- Control = 5
- controlParts()
- }else{
- timer("Activate", 100)
- }
- }elseif (clk("Deactivate")){
- if (Control == 0){
- Control = 6
- controlParts()
- }else{
- timer("Dectivate", 100)
- }
- }elseif (clk("Freeze")){
- if (Control == 0){
- Control = 3
- controlParts()
- }else{
- timer("Freeze", 100)
- }
- }elseif (clk("Unfreeze")){
- if (Control == 0){
- Control = 4
- controlParts()
- }else{
- timer("Unfreeze", 100)
- }
- }elseif (clk("checkConstraints")){
- if (Control == 0){
- Control = 1
- updateParent()
- controlParts()
- }else{
- timer("checkConstraints", 100)
- }
- }elseif (clk("calculateMass")){
- if (Control == 0){
- Control = 2
- controlParts()
- }else{
- timer("calculateMass", 100)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement