Advertisement
Guest User

Tank Chip ACF GMod

a guest
Sep 28th, 2012
4,648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.74 KB | None | 0 0
  1. @name Tank Chip Simple V5
  2. @inputs [Pod Gun TurretBase]:entity GunLock ADV:wirelink Ready
  3. @outputs DDDD XHVec:vector Debug GunLatch Torque PrimaryAmmo SecondaryAmmo
  4. @persist Dran:ranger XH:ranger User:entity A HoloOpacity
  5. @persist Exclude
  6. @persist [Trig Sam Sac Fac Trig3 ET ET2]:vector
  7. @persist TrigTX TrigTY TrigTZ TrigY TrigX TrigZ TrigT XHVec:vector Vel:vector [ETG ETG2]:vector TurretPitchAch TurretPitch RPMPitch RPM
  8. @persist TurningRate ElevationRate ShootPos:vector Change TreadPitch
  9. @inputs [FL FR Base]:entity
  10. @outputs MPH
  11. @persist RPMFL RPMFR EnginePowerReduced Stall EngineDestroyed Pactive
  12. @persist [Pos Turningf Turningb Force]:vector
  13. @inputs AmmoSwitch
  14. @outputs AmmoType
  15. @persist Aon Aimpower Torque TraverseRate ElevateRate Running EnginePitch TrackPitch
  16. @persist ETG2X ETG2Y ETG2Z LoadPitch
  17. @trigger all
  18.  
  19. interval(20)
  20.  
  21.  
  22. #Added support for new ammo system
  23.  
  24. ##### READ ALL THE FUCKING COMMENTS
  25. ##### READ ALL THE FUCKING COMMENTS
  26. ##### READ ALL THE FUCKING COMMENTS
  27. ##### READ ALL THE FUCKING COMMENTS
  28. ##### READ ALL THE FUCKING COMMENTS
  29.  
  30.  
  31. #Version 4 Chip by Sestze, Kickasskyle, & Karbine (credits to Basque and Donovan for E2 soundPlay help)
  32.  
  33.  
  34. #This chip is an ongoing WIP so some parts of it are not totally optimized and are butchered from other things
  35.  
  36. #(this chip used to have an engine damage system but does no longer, has some code from it still)
  37.  
  38. ##### Remember when linking your wheels, link your two rear drive wheels or front wheels (1 per side)
  39. #And link all the wheels on that track to the drive wheel with advanced ballsocket. FR means front right, etc
  40.  
  41. # V4 Changes: Added turret lock (on by default)
  42. #Added Wirelink (for the most part, some inputs won't work with it)
  43. #Turret sounds
  44.  
  45.  
  46.  
  47. # FUCKING IMPORTANT READ THIS:
  48. #For the aim to be true, you need to "Static" your pod (seat)
  49. #simply ballsocket center (check the "simple ballsocket, ignore settings box) your seat to the turret base
  50. #and then with settings of -.1 for min and .1 for max for XYZ for advanced ballsocket (MAKE SURE FREE MOVEMENT IS CHECKED)
  51. #click the pod and then the ground.
  52.  
  53. #MAKE SURE THIS CHIP FACES FORWARD (use the chip with the arrow on it)
  54. #IF YOUR CONTROLS ARE REVERSED just rewire your WASD to the pod controller (use S for W, W for S, etc)
  55.  
  56. #Note about the gunlock- attach a weld latch from your gun to tank base, and wire it to GunLatch
  57. #It is on by default so just tap whatever key you have bound to GunLock OR YOUR AIM WILL NOT WORK
  58.  
  59. #If your tank slides too much, consider applying a no-lift fin of 20-50 efficiency to the side of your base prop
  60.  
  61. #If you want a true crosshair(the hologram does this too), hook up an Adv. Hud Indicator with World and Vector checkboxes checked and the dropdown set to "-1 to 1"
  62. #Wire to XHvec
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. #Movement constants.
  72. Dfor = 0.1 #Forward friction.
  73. Dtur = 0.05 #turning friction. Raise this if it turns too fast.
  74. Torque = 250000*8 #Change the 2.7 multiplier to increase wheel torque. Affects steering speed too.
  75. Offsetfor = 200 # Ignore
  76. StaticPitch = 40 #Idle pitch
  77. DrivingPitch = 100
  78. TurningPitch = 120
  79. TreadPitch = 4
  80. Volume = 30 #Ignore
  81. Ang = ang(1,0,0) #Wheel direction angle. If your wheels don't spin, change the position of the 1
  82. # to 1,0,0 or 0,0,1 etc
  83.  
  84. #Aiming constants
  85. Aimpower = 220
  86. TraverseRate = 0.025
  87. ElevateRate = 0.025
  88.  
  89. HoloOpacity = 0 #(0-255)
  90.  
  91.  
  92.  
  93. if(first()|dupefinished()){
  94.  
  95. Base:soundPlay(1,0,"vehicles/crane/crane_turn_loop2.wav")
  96. Base:soundPlay(2,0,"vehicles/crane/crane_slow_to_idle_loop4.wav")
  97. TurretBase:soundPlay(3,0,"vehicles/tank_turret_loop1.wav")
  98.  
  99. }
  100. if(changed(Ready)&Ready){
  101.  
  102. Gun:soundPlay(4,1,"ambient/levels/outland/ol11_blastdoorlatch.wav")
  103. }
  104.  
  105.  
  106. LoadPitch = 70
  107. soundPitch(1,EnginePitch)
  108. soundPitch(2,TrackPitch)
  109. soundPitch(3,TurretPitch)
  110. soundPitch(4,LoadPitch)
  111.  
  112.  
  113. # IF YOUR CONTROLS ARE REVERSED, REORDER THE CONTROLS
  114. #IE if your tank goes forward when you hit reverse, change W to S, etc
  115. W = ADV["W", number]
  116. S = ADV["S", number]
  117. A = ADV["A", number]
  118. D = ADV["D", number]
  119. Brake = ADV["Space", number]
  120. Active = ADV["Active", number]
  121. if(AmmoSwitch){Pod:hintDriver("Ammo changed next load", 5)}
  122.  
  123.  
  124.  
  125.  
  126. #Constants
  127. TurretPitchMax = 0.6 *100
  128. TurretSmoother = 0.03 *100 #Turret Sound Smoother
  129. RPMPitch = 1 #Amount of RPM before turret sounds activate
  130.  
  131.  
  132.  
  133. #I wouldn't fuck with it, but if your turret sound isn't working, fuck with the :yaw
  134. RPM = abs(TurretBase:angVel():yaw()/6)
  135. if(RPM > RPMPitch) {
  136. TurretPitchAch = TurretPitchMax
  137. }
  138.  
  139. else {
  140. TurretPitchAch = 0
  141. }
  142. #Smoother
  143. TurretPitch = clamp(TurretPitch+(TurretPitchAch-TurretPitch),TurretPitch-TurretSmoother,TurretPitch+TurretSmoother)
  144.  
  145. #You don't need to edit anything below this line--------------------------------
  146.  
  147.  
  148. if(!Pactive) {GunLatch = 1}
  149. else {GunLatch = 0}
  150.  
  151. if(GunLock & ~GunLock) {Pactive = !Pactive}
  152.  
  153. if(!Active) {GunLatch = 1}
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. if(first()|dupefinished())
  163. {
  164. Exclude = 1000 #Ignore
  165. XHExclude = 300 #Ignore
  166. TurningRate = TraverseRate
  167. ElevationRate = ElevateRate
  168. rangerPersist(1)
  169. rangerFilter(entity():getConstraints())
  170.  
  171. ######HOLO CREATION
  172. holoCreate(1,entity():pos(),vec(0.05,0.05,0.05))
  173. holoModel(1,"icosphere")
  174. holoColor(1,vec(0,255,0),HoloOpacity) #Holo sight color/alpha adjustment
  175. holoParent(1,Pod)
  176.  
  177. }
  178.  
  179. #Gun Vectors unlocked
  180. ET = entity():forward()
  181. ET2 = $ET
  182. ET2X = ET2:x()
  183. ET2Y = ET2:y()
  184. ET2Z = ET2:z()
  185.  
  186. #Gun locking vectors (Put under the originals, they'll look the same should be under if(Pod driver)
  187. ETG = Gun:forward()
  188. ETG2 = $ETG
  189. ETG2X = ETG2:x()
  190. ETG2Y = ETG2:y()
  191. ETG2Z = ETG2:z()
  192.  
  193.  
  194. if(Pactive){
  195. if(Pod:driver())
  196. {
  197. Change = 1
  198. User= Pod:driver()
  199. Dran = rangerOffset(30000, User:shootPos() + User:eye() * Exclude, User:eye())
  200.  
  201.  
  202.  
  203. if($Change){
  204. ShootPos = Pod:toLocal(User:shootPos())
  205. }
  206.  
  207. if(Gun)
  208. {
  209. #Xhair
  210. XH = rangerOffset(30000, Gun:pos() + Gun:forward() *XHExclude, Gun:forward())
  211. XHVec = XH:position()
  212. XHVec2 = XH:position() - Pod:toWorld(ShootPos)
  213. #Hologram stuff
  214. HoloPos = Pod:toWorld(ShootPos) + XHVec2:normalized() * 40 #Do not adjust
  215. holoPos(1,HoloPos)
  216. holoAng(1,Gun:angles())
  217.  
  218. Trig2 = (Dran:position() - Gun:pos())
  219. Trig3 = Trig2:normalized()
  220. #Clamp the speed at which the Normalized vector changes, making a delayed turning
  221. #Split into 3 Numbers
  222. TrigX = Trig3:x()
  223. TrigY = Trig3:y()
  224. TrigZ = Trig3:z()
  225. #Add where it wants to aim, to a "delayed" value, that it will slowly obtain.
  226. TrigTX = clamp(TrigX, TrigTX-TurningRate, TrigTX+TurningRate)+ET2X
  227. TrigTY = clamp(TrigY, TrigTY-TurningRate, TrigTY+TurningRate)+ET2Y
  228. TrigTZ = clamp(TrigZ, TrigTZ-ElevationRate, TrigTZ+ElevationRate)+ET2Z
  229.  
  230. TrigT = TrigTX+TrigTY+TrigTZ
  231.  
  232. Trig = vec(TrigTX,TrigTY,TrigTZ)
  233.  
  234. Sam = (Trig) - Gun:forward()
  235. Sac = (Gun:forward():cross(Sam)):cross(Gun:forward())
  236. Fac = (Sac + $Sac * 5)*Gun:mass()
  237.  
  238. Gun:applyOffsetForce(Fac*50,Gun:pos()+Gun:forward()*Aimpower) #Edit the last number here to change force
  239. DDDD = 0
  240. }
  241.  
  242. }else{
  243. holoPos(1,entity():pos())
  244. Change = 0
  245. }
  246. }else{
  247. TrigTX = TrigTX + ETG2X
  248. TrigTY = TrigTY + ETG2Y
  249. TrigTZ = TrigTZ + ETG2Z
  250. TrigX = TrigTX
  251. TrigY = TrigTY
  252. TrigZ = TrigTZ
  253. TurretPitch = 0
  254. DDDD = 1
  255. }
  256.  
  257.  
  258.  
  259.  
  260.  
  261. #Friction Changer, To make it jerk to a stop.
  262. if((!W&!S)){
  263. Dfor = 4
  264. }
  265.  
  266. #Handbrake
  267. if(Brake){
  268. Dfor = 15 #Braking friction
  269. }
  270.  
  271. #Damage Inputs
  272.  
  273. #Default
  274. if(!EnginePowerReduced&!EngineDestroyed&!Stall){
  275. Power = Torque #Adjust multiplier to adjust torque. This affects steering, adjust Dtur if it turns too fast
  276. Running = 1
  277. }
  278.  
  279. #Reduced Engine Power
  280. if(EnginePowerReduced&!EngineDestroyed&!Stall){
  281. Power = 260000*2.7 #Don't change this
  282. Running = 1
  283. }
  284.  
  285. #Engine Destroyed/Stall
  286. if(EngineDestroyed|Stall){
  287. Running = 0
  288. Power = 0
  289. }
  290.  
  291.  
  292.  
  293.  
  294.  
  295. #Rpm Limitation
  296. Limit = 500 #RPM limit
  297. if((Limit > RPMFL)&(-Limit < RPMFL)) {TorqueFL = Power}else{TorqueFL = 0}
  298.  
  299.  
  300. if((Limit > RPMFR)&(-Limit < RPMFR)) {TorqueFR = Power}else{TorqueFR = 0}
  301.  
  302.  
  303.  
  304.  
  305. #Actual Movement Calculations.
  306. Total = (W-S)
  307. Right = (A-D)
  308. Left = -Right
  309. #Right/left side
  310. RHS = (Total*2+Right*4)/2
  311. LHS = (Total*2+Left*4)/2
  312.  
  313. #Applying the Forces
  314. if(W|S|A|D){
  315. FL:applyTorque(vec(Ang)*-TorqueFL*LHS)
  316.  
  317. FR:applyTorque(vec(Ang)*TorqueFR*RHS)
  318.  
  319. }
  320.  
  321. #Base Dampening Friction
  322. #Main drag forces.
  323. Pos = Base:pos()
  324. Vel = $Pos
  325. Vel:setZ(0)
  326.  
  327. #Reset Variables
  328. Force = vec()
  329. Turningf = vec()
  330. Turningb = vec()
  331.  
  332. #Drag Forces
  333. if(clk())
  334. {
  335. Force = Force - Vel * Base:mass() * Dfor
  336. Turningf = Turningf - entity():angVel():yaw() * entity():right() * Dtur * Base:mass()
  337. Turningb = Turningb + entity():angVel():yaw() * entity():right() * Dtur * Base:mass()
  338.  
  339. }
  340. #Applying the forces
  341. if(clk())
  342. {
  343. Force = Force:setZ(0)
  344. Base:applyForce(Force)
  345. Base:applyOffsetForce(entity():forward() * Offsetfor, Turningf)
  346. Base:applyOffsetForce(entity():forward() * -Offsetfor, Turningb)
  347. }
  348.  
  349. ##Sounds for engines (inbuilt smoother)
  350. if(clk()){
  351. if(A|D){
  352. Pitch = TurningPitch
  353. }elseif(W|S){
  354. Pitch = DrivingPitch
  355. }else{
  356. Pitch = StaticPitch
  357. }
  358. #Smoother
  359. EnginePitch = clamp(Pitch,EnginePitch-2,EnginePitch+2)
  360. }
  361.  
  362. #Sounds for Tracks (Inbuilt speedo and Smoother)
  363. if(clk()){
  364. MPH=toUnit("mph", entity():vel():length())
  365.  
  366.  
  367. TPitch = MPH*TreadPitch
  368.  
  369.  
  370.  
  371.  
  372.  
  373. #Smoother
  374. TrackPitch = clamp(TPitch,TrackPitch-20,TrackPitch+20)
  375.  
  376.  
  377. }
  378.  
  379.  
  380. #RPM Calculation
  381. RPMFL = FL:angVel():pitch()/6
  382.  
  383.  
  384. RPMFR = FR:angVel():pitch()/6
  385. # if it isn't working, change the
  386. # :roll to :yaw or :pitch till it works
  387.  
  388. if(AmmoSwitch & ~AmmoSwitch) {Aon = !Aon}
  389. if(Aon) {PrimaryAmmo= 1} else{PrimaryAmmo = 0}
  390. if(!Aon) {SecondaryAmmo = 1} else{SecondaryAmmo = 0}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement