View difference between Paste ID: 1019iQMQ and 1WzeApKt
SHOW: | | - or go back to the newest paste.
1
@name Gyropod V3 by Starkkz
2
3
#Basic inputs
4
@inputs EyePod:wirelink Core:entity Active Unfreeze Level RollLock Boost
5
6
#Movement inputs
7
@inputs Forward Back MoveLeft MoveRight MoveUp MoveDown
8
9
#Angle inputs
10
@inputs PitchUp PitchDown PitchAbs YawLeft YawRight YawAbs RollLeft RollRight RollAbs
11
12
#Multiplier inputs
13
@inputs PitchMult YawMult RollMult SpeedMult
14
15
#Aiming inputs
16
@inputs AimMode AimX AimY AimZ AimVec:vector
17
18
#Gyropod outputs
19
@outputs Angle:angle Velocity:vector AngularVelocity:angle
20
@outputs Mass
21
22
#Global variables
23
@persist Initialized LastEnv:string
24
@persist Control ControlIndex
25
@persist CurrentMass
26
@persist Parent:entity Parts:array
27
if (dupefinished()){reset()}
28
29
function setName2(Text:string){
30
    setName("Gyropod V3 by Starkkz\n"+Text)
31
}
32
33
function normal pitchMult(){
34
    if (PitchMult){
35
        return PitchMult
36
    }
37
    return 1
38
}
39
40
function normal yawMult(){
41
    if (YawMult){
42
        return YawMult
43
    }
44
    return 1
45
}
46
47
function normal rollMult(){
48
    if (RollMult){
49
        return RollMult
50
    }
51
    return 1
52
}
53
54
function normal speedMult(){
55
    if (SpeedMult){
56
        return SpeedMult
57
    }
58
    return 1
59
}
60
61
function updateParent(){
62
    Parent = entity():parent()
63
    if (!Parent){Parent = entity():isConstrainedTo()}
64
    if (!Parent){Parent = entity()}
65
    Parts = Parent:getConstraints()
66
    Parts[Parts:count() + 1, entity] = Parent
67
    LastEnv = Parent:lsName()
68
}
69
70
function controlParts(){
71
    if (Control > 0){
72
        while (ControlIndex <= Parts:count()){
73
            if (minquota() <= 100){
74
                timer("controlParts", 1)
75
                exit()
76
            }
77
            local Part = Parts[ControlIndex, entity]
78
            
79
            if (Control == 1){
80
                #Check constraints
81-
                        Part:deparent()
81+
82
                    if (Part:isWeldedTo() == Parent){
83
                        if (Part:parent() == noentity()){
84-
                        Part:parentTo(Parent)
84+
                            Part:propFreeze(1)
85
                        }
86
                        Part:unConstrain()
87
                        if (Core){Part:weld(Core)}
88
                        Part:noCollide(Parent)
89
                    }elseif (Part:isWeldedTo() != Core){
90
                        Part:unWeld()
91
                        Part:weld(Core)
92
                    }
93
                }
94
            }elseif (Control == 2){
95
                #Calculate mass
96
                CurrentMass = CurrentMass + Part:mass()
97
            }elseif (Control == 3){
98
                #Freeze
99
                Part:propFreeze(1)
100
            }elseif (Control == 4){
101
                #Unfreeze
102
                Part:propFreeze(0)
103
            }elseif (Control == 5){
104
                #Disable gravity
105
                Part:propGravity(0)
106
            }elseif (Control == 6){
107
                #Enable gravity
108
                Part:propGravity(1)
109
            }
110
            ControlIndex = ControlIndex + 1
111
        }
112
    }
113
        
114
    if (ControlIndex > Parts:count()){
115
        if (Control == 1){
116
            timer("checkConstraints", 20000)
117
            if (Parent == entity()){
118
                setName2("Using E2 as parent")
119
            }else{
120
                setName2("Found parent\nCached "+Parts:count()+" entities")
121
            }
122
            Initialized = 1
123
        }elseif (Control == 2){
124
            Mass = CurrentMass
125
            CurrentMass = 0
126
            timer("calculateMass", 10000)
127
        }
128
        
129
        ControlIndex = 0
130
        Control = 0
131
    }
132
}
133
134
function update(){
135
    if (Active){
136
        local Pitch = PitchUp - PitchDown + PitchAbs
137
        local Yaw = YawLeft - YawRight + YawAbs
138
        local Roll = RollLeft - RollRight + RollAbs
139
        
140
        local AngleVel = ang(Pitch, Yaw, Roll) * 15
141-
            AngleVel = -Parent:angles():setYaw(0) * 3
141+
142
            AngleVel = AngleVel - ang(EyePod["Y", normal], EyePod["X", normal], 0):setRoll(0) * 10
143-
            AngleVel = -Parent:angles():setYaw(0):setPitch(0) * 3
143+
144
        if (Level){
145
            AngleVel = -Parent:angles():setYaw(-AngleVel:yaw()) * 4
146
        }elseif (RollLock){
147
            AngleVel = -Parent:angles():setYaw(-AngleVel:yaw()):setPitch(-AngleVel:pitch()) * 4
148
        }elseif (AimMode){
149
            local Vec = vec(AimX, AimY, AimZ)
150-
        local VelMult = 600
150+
            if (AimVec){Vec = AimVec}
151
            AngleVel = -Parent:heading(AimVec) * 5
152
        }
153
        AngleVel = ang(AngleVel:pitch() * pitchMult(), AngleVel:yaw() * yawMult(), AngleVel:roll() * rollMult())
154
        
155
        local MoveX = Forward - Back
156
        local MoveY = MoveRight - MoveLeft
157
        local MoveZ = MoveUp - MoveDown
158
        local VelMult = 800
159
        if (Boost){VelMult = 5000}
160
        local Vel = (Parent:forward() * MoveX + Parent:right() * MoveY + Parent:up() * MoveZ) * speedMult() * VelMult
161
        
162
        Parent:setVel(Vel)
163
        Parent:setAngVel(shiftR(AngleVel))
164
    }
165
}
166
167
if (first()){
168
    #Initialize
169
    runOnLast(1)
170
    
171
    updateParent()
172
    timer("checkConstraints", 1)
173
    timer("calculateMass", 1000)
174
    timer("update", 1000)
175
}elseif (last()){
176
    #End
177
}
178
179
if (Parent & Parent:lsName() != LastEnv){
180
    LastEnv = Parent:lsName()
181
    if (Active){timer("Activate", 1)}
182
}
183
184
if (~Active){
185
    if (Active){
186
        timer("Activate", 1)
187
    }else{
188
        timer("Deactivate", 1)
189
    }
190
    EyePod["Enable", normal] = Active
191
}elseif (~Unfreeze){
192
    if (Unfreeze){
193
        timer("Unfreeze", 1)
194
    }else{
195
        timer("Freeze", 1)
196
    }
197
}elseif (clk("controlParts")){
198
    controlParts()
199
}elseif (clk("update")){
200
    if (Initialized){
201
        update()
202
    }
203
    timer("update", 200)
204
}elseif (clk("Activate")){
205
    if (Control == 0){
206
        Control = 5
207
        controlParts()
208
    }else{
209
        timer("Activate", 100)
210
    }
211
}elseif (clk("Deactivate")){
212
    if (Control == 0){
213
        Control = 6
214
        controlParts()
215
    }else{
216
        timer("Dectivate", 100)
217
    }
218
}elseif (clk("Freeze")){
219
    if (Control == 0){
220
        Control = 3
221
        controlParts()
222
    }else{
223
        timer("Freeze", 100)
224
    }
225
}elseif (clk("Unfreeze")){
226
    if (Control == 0){
227
        Control = 4
228
        controlParts()
229
    }else{
230
        timer("Unfreeze", 100)
231
    }
232
}elseif (clk("checkConstraints")){
233
    if (Control == 0){
234
        Control = 1
235
        updateParent()
236
        controlParts()
237
    }else{
238
        timer("checkConstraints", 100)
239
    }
240
}elseif (clk("calculateMass")){
241
    if (Control == 0){
242
        Control = 2
243
        controlParts()
244
    }else{
245
        timer("calculateMass", 100)
246
    }
247
}