Advertisement
Guest User

e2 thing

a guest
Aug 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. @name Utility connector thing
  2. @inputs ToggleAttach ToggleExtend [Base]:entity
  3. @outputs Lock Locked Other_Base:entity Step LiftHeight LiftSpeed RopeDistance
  4. @outputs E2_pos:vector Find:entity [Force_Vec AxisPos]:vector Dist Sound Extend ExtendActive RopeLength SetLength
  5. #made by Pote
  6.  
  7. LiftHeight = 12
  8. LiftSpeed = 1
  9. AxisPos = vec(-30, 0, 0) #local to e2, dont set it tiny values
  10.  
  11. #[
  12.  
  13. HOW TO USE:
  14.  
  15. +- INPUTS ------------------------------------------------------------------------------------------+
  16. | ToggleAttach is a key to toggle the connector |
  17. | ToggleExtend is a key to raise or lower the tool |
  18. | Base is the baseplate of your vehicle |
  19. | |
  20. +- VEHICLE -----------------------------------------------------------------------------------------+
  21. | place this e2 wherever you want the vehicle connector to be (in lowered position) |
  22. | little arrow on the e2 needs to face forward |
  23. | the chip should be parented to Base (no constraints needed) |
  24. | |
  25. +- TOOL --------------------------------------------------------------------------------------------+
  26. | on your utility tool, at the position of the connector, place an e2 named 'Tool connector' |
  27. | it should be at the same angle as the vehicle e2 |
  28. | contents of this e2 can be anything, we only need its name to be Tool connector |
  29. | parent it to the base of the tool, then apply a nocollide constraint between it and the tool base |
  30. +---------------------------------------------------------------------------------------------------+
  31.  
  32. # ah btw when the tool is frozen or physgunned something could explode
  33.  
  34. ]#
  35.  
  36. if( first() | dupefinished() )
  37. {
  38. enableConstraintUndo(0)
  39. }
  40.  
  41. if( ~ToggleAttach & ToggleAttach )
  42. {
  43. Lock = !Lock
  44. soundPlay( 1, 1, "buttons/lightswitch2.wav" )
  45. }
  46.  
  47. if( Lock )
  48. {
  49. E2_pos = entity():pos()
  50. findClearWhiteList()
  51. findExcludeEntity( entity() )
  52. findIncludeClass( "gmod_wire_expression2" )
  53. findInSphere( E2_pos, 72 )
  54. Find = findClosest( E2_pos )
  55. if( Find:getName() == "Tool connector" )
  56. {
  57. Other_Base = Find:isConstrainedTo()
  58. }
  59. else
  60. {
  61. Find = noentity()
  62. Lock = 0
  63. soundPlay( 2, 1, "buttons/button8.wav" )
  64. }
  65. }
  66. if(Locked)
  67. {
  68. switch(Step)
  69. {
  70. case 1,
  71. Other_Base:setAng(entity():angles() - Other_Base:toLocal(Find:angles()))
  72. Other_Base:setPos(entity():toWorld(Find:toLocal(Other_Base:pos())))
  73. break
  74. case 2,
  75. axis(Base, Base:toLocal(entity():toWorld(AxisPos)), Other_Base, vec(), 0, Base:toLocal(entity():toWorld(AxisPos+vec(0,1,0))))
  76.  
  77. # id ent1 local pos to ent1 ent2 local pos to ent2 addlength w mat rigid
  78. #rope(1, Base, Base:toLocal(entity():toWorld(vec(0,0,LiftHeight))), Other_Base, Other_Base:toLocal(E2_pos), 0, 0, "", 0)
  79. #rope(2, Base, Base:toLocal(E2_pos), Other_Base, Other_Base:toLocal(E2_pos), LiftHeight, 0, "", 0)
  80. # id ent1 local pos to ent1 ent2 local pos to ent2 width
  81. hydraulic(323, Base, Base:toLocal(entity():toWorld(vec(0,0,LiftHeight*4))), Other_Base, Other_Base:toLocal(entity():toWorld(vec(-AxisPos:x(),0,0))), 0)
  82. break
  83. case 3,
  84. Other_Base:propFreeze(0)
  85. Base:propFreeze(0)
  86. ExtendActive = 1
  87. Extend = 1
  88. Base:constraintBreak( "weld", Other_Base )
  89. break
  90. }
  91. if(Step < 4)
  92. {
  93. interval(15)
  94. Step++
  95. }
  96. if(~ToggleExtend & ToggleExtend)
  97. {
  98. Extend = !Extend
  99. ExtendActive = 1
  100. Base:constraintBreak( "weld", Other_Base )
  101. }
  102. if(ExtendActive)
  103. {
  104. interval(15)
  105. RopeLength += clamp(LiftHeight*Extend - RopeLength, -LiftSpeed/10, LiftSpeed/10)
  106. SetLength = LiftHeight*4 - RopeLength*2
  107. Base:setLength(323, SetLength)
  108.  
  109. if(Dist*Extend > LiftHeight*Extend | !RopeLength)
  110. {
  111. ExtendActive = 0
  112. }
  113. }
  114. elseif(Extend)
  115. {
  116. weld(Base, Other_Base)
  117. }
  118. }
  119. if( Lock )
  120. {
  121. Dist = E2_pos:distance( Find:pos() )
  122.  
  123. if( Dist > 1 & !Locked )
  124. {
  125. interval(15)
  126. Force_Vec = ( E2_pos - Find:pos() ) * Other_Base:mass() * 10 / clamp(Dist + ( Find:vel() - Base:vel() ):length()/20, 1, 30)
  127. Other_Base:applyOffsetForce( Force_Vec + $Force_Vec * 5, Find:pos() )
  128. Base:applyOffsetForce( -( Force_Vec + $Force_Vec * 5), E2_pos )
  129. }
  130. elseif( !Locked )
  131. {
  132. Other_Base:propFreeze(1)
  133. Base:propFreeze(1)
  134. Locked = 1
  135. Step = 1
  136. soundPlay( 4, 1, "buttons/latchunlocked2.wav" )
  137. interval(15)
  138. }
  139.  
  140. if( Sound )
  141. {
  142. Sound = 0
  143. soundPlay( 3, 1, "buttons/button9.wav" )
  144. }
  145. }
  146. else
  147. {
  148. Base:constraintBreak( "rope", Other_Base )
  149. Base:constraintBreak( "axis", Other_Base )
  150. Base:constraintBreak( "weld", Other_Base )
  151. Base:constraintBreak( "elastic", Other_Base )
  152.  
  153. Locked = 0
  154. Sound = 1
  155. Step = 0
  156. RopeLength = 0
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement