finicu212

efficient target practice

Aug 29th, 2020 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. ##########################################################
  2. #
  3. # Customizable, modular, CPU efficient target practice
  4. #
  5. # Author: /u/finicu
  6. # Last modified: 2020/08/29
  7. # For /r/wiremod
  8. # Requires propcore, constraintcore
  9. #
  10.  
  11.  
  12. @name shooting target
  13. @outputs TargetPitch
  14. @persist TARGET_MASS HEIGHT RAND_TIME_SET_UPRIGHT TARGET_PROP:string
  15. @persist [BOUNDS TARGET]:entity
  16. @persist TargetPitch
  17. @trigger none
  18.  
  19. if (first())
  20. {
  21. # Customize settings here
  22. HEIGHT = 75 # Distance from chip in source units
  23. TARGET_MASS = 15000 # in kg
  24. RAND_TIME_SET_UPRIGHT = 1000 # in ms
  25. TARGET_PROP = "models/hunter/plates/plate025x025.mdl" # path to prop
  26.  
  27.  
  28. # Do not change things below here
  29. function number getRelativeRoll(Ent1:entity, Ent2:entity)
  30. {
  31. return Ent1:angles():roll() - Ent2:angles():roll()
  32. }
  33.  
  34.  
  35. entity():propGravity(0)
  36. entity():setAlpha(0)
  37. POS = entity():pos() + vec(0, 0, HEIGHT)
  38.  
  39. BOUNDS = propSpawn("models/props_phx/construct/metal_wire1x1.mdl", POS, ang(0, 0, 90), 1)
  40. TARGET = propSpawn(TARGET_PROP, BOUNDS:boxCenterW(), ang(0, 0, 90), 1)
  41. LINK = holoCreate(0, TARGET:pos() - vec(1, -1, 22), vec(0.3, 0.55, 0.3), ang(0, 0, 90), vec4(255), "models/phxtended/bar1x.mdl")
  42. holoParent(0, TARGET)
  43. #Entity=holoCreate(number index,vector position,vector scale,angle ang,vector4 color,string model)
  44.  
  45. BOUNDS:setMaterial("models/props_wasteland/wood_fence01a_skin2")
  46. TARGET:setMaterial("phoenix_storms/stripes")
  47. noCollideAll(BOUNDS, 1)
  48. noCollideAll(TARGET, 1)
  49. TARGET:setMass(TARGET_MASS)
  50. BOUNDS:setMass(TARGET_MASS * 2)
  51.  
  52. BOUNDS:propGravity(0)
  53.  
  54. ANCHOR_POINT = BOUNDS:boxCenter() - vec(0, 21, 0)
  55. BOUNDS:ballsocketTo(TARGET, ANCHOR_POINT, 0, 0, 1)
  56. BOUNDS:advBallsocketTo(
  57. 0,
  58. TARGET,
  59. 0,
  60. 0,
  61. vec(0),
  62. vec(0),
  63. 0,
  64. 0,
  65. vec(0.1, -0.001, -0.001),
  66. vec(87.5, 0.001, 0.001),
  67. vec(0.07),
  68. 1,
  69. 0)
  70.  
  71. runOnDamage(1, TARGET)
  72. runOnKeys(owner(), 1)
  73. }
  74.  
  75. # clean up
  76. if (owner():keyPressed("Z"))
  77. {
  78. TARGET:propDelete()
  79. BOUNDS:propDelete()
  80.  
  81. selfDestruct()
  82. }
  83.  
  84. TickDamage = TARGET:getDamage()
  85. if (TickDamage != 0)
  86. {
  87. print("dealt " + TickDamage)
  88. TARGET:propFreeze(0)
  89. owner():soundPlay(0, 0, "hl1/fvox/bell.wav")
  90. TARGET:applyForce(TARGET:up() * vec(TARGET_MASS * 50)) # just a small impulse to knock it over
  91. timer("ResetTarget", 2000 + randint(-RAND_TIME_SET_UPRIGHT, RAND_TIME_SET_UPRIGHT))
  92. }
  93.  
  94. if (clk("ResetTarget"))
  95. {
  96. timer("checkOrientation", 50)
  97. TargetPitch = getRelativeRoll(TARGET, BOUNDS)
  98. }
  99. elseif(clk("checkOrientation"))
  100. {
  101. TargetPitch = getRelativeRoll(TARGET, BOUNDS)
  102.  
  103. if (abs(TargetPitch) > 2.35)
  104. {
  105. timer("checkOrientation", 50)
  106. TARGET:applyForce(TARGET:up() * vec(-TARGET_MASS * 41))
  107. }
  108. else
  109. {
  110. TARGET:propFreeze(1)
  111. owner():soundPlay(1, 0, "hl1/fvox/fuzz.wav")
  112. }
  113. }
  114.  
Add Comment
Please, Sign In to add comment