SaitinN

Untitled

Jan 28th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.94 KB | None | 0 0
  1. @name mini gauge
  2. @inputs A
  3. @outputs Ops
  4. @persist Range Needle Scale Mode Min Max Step Div Red Font Nums Smooth Value HMax
  5. @persist [Lbl LMin LMax]:string Self:entity
  6. @persist [NeedCol RingCol LblCol FaceCol BackCol]:vector
  7. @persist [NeedMat RingMat LblMat FaceMat BackMat]:string
  8. @trigger none
  9. @model models/beer/wiremod/watersensor.mdl
  10.  
  11. # ultimate universal gauge by tweak
  12.  
  13. # changelog:
  14. # v. 2 (12/09/2013)
  15. # - added an option for angled numbering
  16. #
  17. # v. 1 (12/06/2013)
  18. # - initial release
  19.  
  20. interval( 100 )
  21.  
  22. if( first() | duped() )
  23. {
  24. #############################################
  25. ###SETTINGS##################################
  26. #############################################
  27.  
  28. # visual
  29. ###################
  30.  
  31. Scale = 1 # hologram size
  32. Font = 0 # font for numbering and labels (0-3)
  33. Smooth = 2 # smooth out needle movement - higher value is smoother
  34. HMax = 70 # max holos to create - with a lower value here the gauge will
  35. # spawn faster but will break if there are too many elements
  36.  
  37. ## needle
  38. NeedCol = vec( 200, 0, 0 )
  39. NeedMat = "models/ihvtest/eyeball_l"
  40.  
  41. ## tickmarks
  42. RingCol = vec( 25, 25, 25 )
  43. #RingCol = vec( 255 , 255 , 255 )
  44. RingMat = "models/ihvtest/eyeball_l"
  45.  
  46. ## labels
  47. LblCol = vec( 25 , 25 , 25 )
  48. LblMat = "models/ihvtest/eyeball_l"
  49.  
  50. ## gauge face
  51. FaceCol = vec( 200, 200, 200 )
  52. #FaceCol = vec( 20, 20, 20 )
  53. #FaceMat = "phoenix_storms/fender_white"
  54. #FaceMat = "phoenix_storms/fender_wood"
  55. FaceMat = "models/ihvtest/eyeball_l"
  56.  
  57. ## gauge back
  58. #BackCol = vec( 160, 160, 160 )
  59. BackCol = vec( 50, 50, 50 )
  60. BackMat = "models/ihvtest/eyeball_l"
  61. #BackMat = "phoenix_storms/fender_wood"
  62.  
  63. ## gauge profiles
  64. ####################
  65. ## uncomment only the one you want to use
  66. ## modes (raw input will be used if unspecified)
  67. ## 1: test mode - sweep gauge
  68. ## 2: input (absolute)
  69. ## 3: mph
  70. ## 4: kmh
  71. ## nums
  72. ## 0: no numbering
  73. ## 1: normal numbers
  74. ## 2: angled numbers (oldschool mustang style)
  75.  
  76. ## speedo
  77. Lbl = "MPH" # gauge label
  78. Mode = 2 # gauge mode
  79. Min = 0 # lower bound
  80. Max = 10 # upper bound
  81. Div = 1 # tick label divider
  82. Step = 1 # tick interval
  83. Nums = 2 # enable numbering
  84. Red = 8 # enable redline
  85.  
  86. ## tach
  87. #Lbl = "RPM x1000"
  88. #Mode = 0
  89. #Min = 0
  90. #Max = 8000
  91. #Div = 1000
  92. #Step = 1000
  93. #Nums = 2
  94. #Red = 1
  95.  
  96. ## fuel
  97. #Lbl = "Fuel"
  98. #LMin = "E"
  99. #LMax = "F"
  100. #Mode = 2
  101. #Min = 0
  102. #Max = 100
  103. #Step = Max / 8
  104.  
  105. ## temp
  106. #Lbl = "Engine Temp"
  107. #LMin = "L"
  108. #LMax = "H"
  109. #Mode = 2
  110. #Min = 140
  111. #Max = 260
  112. #Step = 30
  113. #Red = 1
  114.  
  115. ## boost/vac
  116. #Lbl = "psi"
  117. #Min = -10
  118. #Max = 30
  119. #Step = 10
  120. #Nums = 1
  121.  
  122. ## some examples for custom gauges
  123. #Lbl = "HomoMeter"
  124. #Min = 0
  125. #Max = 9000
  126. #Div = 10 # the number labels will be divided by 10
  127. #Step = 1000 # one tick every 111 units
  128. #Nums = 1 # number labels are enabled
  129.  
  130. #Lbl = "Homometer"
  131. #Min = 0
  132. #Max = 10
  133. #Step = Max / 8 # just a little shortcut to get exactly 8 ticks over any interval
  134. #Nums = 0 # number labels are disabled here (this line can simply be left out)
  135. #LMin = "0" # you can put custom min and max labels here when numbering is disabled
  136. #LMax = "Gay"
  137.  
  138. #############################################
  139. #############################################
  140. #############################################
  141.  
  142. Self = entity()
  143. Self:setAlpha( 0 )
  144.  
  145. Range = Max - Min
  146. Step = Range / ( Step ) + 1
  147.  
  148. if( !Div ){ Div = 1 }
  149. Smooth = max( Smooth, 0 )
  150. # some helper functions
  151. function void holoSet( Idx:number, Position:vector, Scale:vector, Angle:angle,
  152. Model:string, Material:string, Color:vector )
  153. {
  154. holoPos( Idx, Position )
  155. holoScale( Idx, Scale )
  156. holoAng( Idx, Angle )
  157. holoModel( Idx, Model )
  158. holoMaterial( Idx, Material )
  159. holoColor( Idx, Color )
  160. }
  161.  
  162. function number createLabel( Idx:number, Position:vector, Angle:number, Label:string )
  163. {
  164. local Width = ( Label:length() - 1 ) * 0.3
  165.  
  166. for( N = 0, Label:length() - 1 )
  167. {
  168. local Offset = vec( sin( Angle ), cos( Angle ), 0 ) * ( N * 0.3 - Width / 2 )
  169. local Char = Label:index( N + 1 )
  170. local Asc = toByte( Char )
  171.  
  172. if( !inrange( Asc, 33, 126 ) | Asc == 92 | Asc == 96 )
  173. { # nothing to do if it's a space or invalid char
  174. continue
  175. }
  176. elseif( inrange( Asc, 33, 47 ) )
  177. { # some symbols
  178. Char = Char:replace( "!", "xmark" )
  179. Char = Char:replace( "\"", "quote" )
  180. Char = Char:replace( "#", "pdsign" )
  181. Char = Char:replace( "$", "dlsign" )
  182. Char = Char:replace( "%", "pcnt" )
  183. Char = Char:replace( "&", "and" )
  184. Char = Char:replace( "'", "apost" )
  185. Char = Char:replace( "(", "lpar" )
  186. Char = Char:replace( ")", "rpar" )
  187. Char = Char:replace( "*", "ast" )
  188. Char = Char:replace( "+", "plu" )
  189. Char = Char:replace( ",", "com" )
  190. Char = Char:replace( "-", "min" )
  191. Char = Char:replace( ".", "prd" )
  192. Char = Char:replace( "/", "div" )
  193. } # 48-57 is numbers
  194. elseif( inrange( Asc, 58, 64 ) )
  195. { # some more symbols
  196.  
  197. Char = Char:replace( ":", "colon" )
  198. Char = Char:replace( ";", "scolon" )
  199. Char = Char:replace( "<", "lessthan" )
  200. Char = Char:replace( "=", "equal" )
  201. Char = Char:replace( ">", "greaterthan" )
  202. Char = Char:replace( "?", "qmark" )
  203. Char = Char:replace( "@", "atsign" )
  204.  
  205. } # 65-90 is uppercase letters
  206. elseif( inrange( Asc, 91, 95 ) )
  207. { # even more symbols
  208.  
  209. Char = Char:replace( "[", "lbracket" )
  210. Char = Char:replace( "]", "rbracket" )
  211. Char = Char:replace( "^", "crt" )
  212. Char = Char:replace( "_", "underscore" )
  213. }
  214. elseif( inrange( Asc, 97, 122 ) )
  215. { # lowercase letters
  216. Char = "l_" + Char
  217. }
  218. elseif( inrange( Asc, 123, 126 ) )
  219. { # last of the symbols
  220. Char = Char:replace( "{", "lcbracket" )
  221. Char = Char:replace( "|", "bar" )
  222. Char = Char:replace( "}", "rcbracket" )
  223. Char = Char:replace( "~", "tilde" )
  224. }
  225.  
  226. holoSet( Idx, Self:toWorld( ( Position + Offset ) * Scale ),
  227. vec( 0.03, 0.03, 0.03 ) * Scale, Self:toWorld( ang( 0, -90 - Angle, 90 ) ),
  228. "models/sprops/misc/alphanum/alphanum_" + Char + ".mdl",
  229. LblMat, LblCol )
  230. holoDisableShading( Idx, 1 )
  231. holoBodygroup( Idx, 0, Font )
  232. holoParent( Idx, Self )
  233. Idx++
  234. }
  235.  
  236. return Idx
  237. }
  238.  
  239. I = 0
  240. timer( "spawn", 1 )
  241. }
  242.  
  243. if( clk( "spawn" ) )
  244. {
  245. while( perf() & holoCanCreate() & I < HMax )
  246. {
  247. I++
  248. holoCreate( I )
  249. }
  250.  
  251. if( I < HMax )
  252. {
  253. timer( "spawn", 1 )
  254. }
  255. else
  256. {
  257. timer( "set", 1 )
  258. }
  259. }
  260.  
  261. if( clk( "set" ) )
  262. {
  263. I = 1
  264.  
  265. # gauge body
  266. holoSet( I, Self:toWorld( vec( 0, 0, 0.5 ) * Scale ), vec( 0.62, 0.62, 0.62 ) * Scale,
  267. Self:toWorld( ang( 0, 0, 180 ) ), "hq_hdome_thin", BackMat, BackCol )
  268. holoParent( I, Self )
  269. I++
  270.  
  271. # gauge face
  272. holoSet( I, Self:toWorld( vec( 0, 0, 0 ) * Scale ), vec( 0.6, 0.6, 0.01 ) * Scale,
  273. Self:toWorld( ang() ), "hq_cylinder", FaceMat, FaceCol )
  274. holoDisableShading( I, 1 )
  275. holoParent( I, Self )
  276. I++
  277.  
  278. # needle base
  279. holoSet( I, Self:toWorld( vec( 0, 0, 0.5 ) * Scale ), vec( 0.06, 0.06, 0.01 ) * Scale,
  280. Self:toWorld( ang() ), "hq_cylinder", NeedMat, NeedCol )
  281. holoDisableShading(I, 1)
  282. holoParent(I, Self)
  283. Needle = I
  284. I++
  285.  
  286. # needle
  287. holoSet( I, Self:toWorld( vec( -1.0, 0, 0.45 ) * Scale ), vec( 0.03, 0.01, 0.28 ) * Scale,
  288. Self:toWorld( ang( 0, -90, 90 ) ), "prism", NeedMat, NeedCol )
  289. holoDisableShading( I, 1 )
  290. holoParent( I, Needle )
  291. I++
  292.  
  293. # tick ring
  294. holoSet( I, Self:toWorld( vec( 0, 0, 0.2 ) * Scale ), vec( 0.61, 0.61, 0.02 ) * Scale,
  295. Self:toWorld( ang() ), "hq_tube_thin", RingMat, RingCol )
  296. holoDisableShading( I, 1 )
  297. holoClipEnabled( I, 1 )
  298. holoClip( I, vec(), vec( cos( 210 ), sin( 210 ), 0 ), 0 )
  299. holoParent( I, Self )
  300. I++
  301.  
  302. # tick ring (redline clip)
  303. holoSet( I, Self:toWorld( vec( 0, 0, 0.2 ) * Scale ), vec( 0.61, 0.61, 0.02 ) * Scale,
  304. Self:toWorld( ang() ), "hq_tube_thin", RingMat, Red ? vec( 255, 0, 0 ) : RingCol )
  305. holoDisableShading( I, 1 )
  306. holoClipEnabled( I, 1, 1 )
  307. holoClip( I, 1, vec(), vec( cos( 30 ), sin( 30 ), 0 ), 0 )
  308. holoClipEnabled( I, 2, 1 )
  309. holoClip( I, 2, vec(), vec( cos( 150 ), sin( 150 ), 0 ), 0 )
  310. holoParent( I, Self )
  311. I++
  312.  
  313. N = Min / Div
  314. NumStep = ( Range / Div ) / ( Step - 1 )
  315.  
  316. for( Ang = -210, 30, 240 / ( Step - 1 ) )
  317. for( Ang = -210, 30, 240 / ( Step - 1 ) )
  318. {
  319. # tickmark
  320. holoSet( I, Self:toWorld( vec( sin( Ang ) * 3.2, cos( Ang ) * 3.2, 0.2 ) * Scale ),
  321. vec( 0.03, 0.03, 0.01 ) * Scale, Self:toWorld( ang( 0, -Ang + 90, 0 ) ),
  322. "models/sprops/rectangles_thin/size_1/rect_3x12x1_5.mdl",
  323. RingMat, ( Red & Ang >= -30 ) ? vec( 255, 0, 0 ) : RingCol )
  324. holoDisableShading( I, 1 )
  325. holoParent( I, Self )
  326. I++
  327.  
  328. if( Nums == 1 )
  329. { # numbering
  330. I = createLabel( I, vec( sin( Ang ) * 2.7, cos( Ang ) * 2.7, 0.2 ), 0, round( N, 1 ):toString() )
  331. }
  332. elseif( Nums == 2 )
  333. { # angly numbering
  334. I = createLabel( I, vec( sin( Ang ) * 2.7, cos( Ang ) * 2.7, 0.2 ), Ang + 90, round( N, 1 ):toString() )
  335. }
  336. elseif( LMin & Ang == -210 )
  337. { # custom min label
  338. I = createLabel( I, vec( sin( Ang ) * 2.7, cos( Ang ) * 2.7, 0.2 ), 0, LMin )
  339. }
  340. elseif( LMax & Ang == 30 )
  341. { # custom max label
  342. I = createLabel( I, vec( sin( Ang ) * 2.7, cos( Ang ) * 2.7, 0.2 ), 0, LMax )
  343. }
  344.  
  345. N += NumStep
  346. }
  347.  
  348. if( Lbl )
  349. { # lower center gauge label
  350. I = createLabel( I, vec( 2, 0, 0.2 ), 0, Lbl )
  351. }
  352.  
  353. if( I > HMax )
  354. {
  355. hint( "Hologram max exceeded! Please increase HMax to at least " + I, 7 )
  356. }
  357.  
  358. for( Del = I, HMax )
  359. {
  360. holoDelete( Del ) # lazy ass
  361. }
  362.  
  363. setName( "mini gauge: " + I:toString() + " elements" )
  364. }
  365.  
  366. if( Mode == 1 ) # gauge sweep
  367. {
  368. A = sin( curtime() * 180 ) * ( Range / 2 ) + ( Range / 2 )
  369. Smooth = 0
  370. }
  371. elseif( Mode == 2 ) # absolute value
  372. {
  373. A = abs( A )
  374. }
  375. elseif( Mode == 3 ) # speedo mph
  376. {
  377. A = toUnit( "mi/h", Self:vel():length() )
  378. }
  379. elseif( Mode == 4 ) # speedo kmh
  380. {
  381. A = toUnit( "km/h", Self:vel():length() )
  382. }
  383.  
  384. if( Smooth )
  385. {
  386. Value = clamp( Value + ( A - Value ) / Smooth, Min, Max )
  387. }
  388. else
  389. {
  390. Value = clamp( A, Min, Max )
  391. }
  392.  
  393. Ang = ( Max - Value ) / Range * 240 - 120
  394. holoAng( Needle, Self:toWorld( ang( 0, Ang, 0 ) ) )
  395.  
  396. Ops = ops()
  397. ##############################################################
Advertisement
Add Comment
Please, Sign In to add comment