Advertisement
TheVideoVolcano

GTA V .NET SCRIPTHOOK ATTACH-HELPER

Jul 21st, 2015
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.98 KB | None | 0 0
  1.   'intermediate progress, need refining, and a custom constructor
  2. Public Class TAttachHelper
  3.         Inherits Script
  4.  
  5.         Private AttachHelperOn As Boolean = False
  6.         Private AttachIncrement As Single = 0.01
  7.         Private attachIncAux As Single = 0.01
  8.         Private RotationMode As Boolean = False
  9.         Private resetConfirm As Boolean = False
  10.         Private cBone As Bone = Bone.IK_L_Hand
  11.  
  12.         Private AttachOffX As Single = 0.0
  13.         Private AttachOffY As Single = 0.0
  14.         Private AttachOffZ As Single = 0.0
  15.  
  16.         Private AttachRotX As Single = 0.0
  17.         Private AttachRotY As Single = 0.0
  18.         Private AttachRotZ As Single = 0.0
  19.  
  20.         Private AttachEntity As Prop = Nothing
  21.  
  22.         Public Function mRnd(ByVal deci As Double, ByVal places As Int16) As Double
  23.             Return Math.Round(deci, places)
  24.         End Function
  25.  
  26.         Public Sub New()
  27.  
  28.             AddHandler Tick, AddressOf onTick
  29.             AddHandler KeyDown, AddressOf onKeyDown
  30.             Interval = 10
  31.         End Sub
  32.  
  33.       Public Sub msg(ByVal text As String, Optional ByVal time As Integer = 2500)
  34.             GTA.Native.Function.Call(Native.Hash._SET_TEXT_ENTRY_2, "STRING")
  35.             GTA.Native.Function.Call(Native.Hash._ADD_TEXT_COMPONENT_STRING, text)
  36.             GTA.Native.Function.Call(Native.Hash._0x9D77056A530643F6, time, 1)
  37.         End Sub
  38.  
  39.         Public Sub AttachEntToEntPhys(ent1 As Entity, ent2 As Entity, boneIndex As Int32, p4 As Single, offset1 As GTA.Math.Vector3, offset2 As GTA.Math.Vector3, rot As GTA.Math.Vector3, breakForce As Single, p14 As Single, p15 As Boolean, p16 As Boolean, p17 As Boolean, p18 As Int16)
  40.             Native.Function.Call(Native.Hash.ATTACH_ENTITY_TO_ENTITY_PHYSICALLY, ent1, ent2, boneIndex, p4, offset1.X, offset1.Y, offset1.Z, offset2.X, offset2.Y, offset2.Z, rot.X, rot.Y, rot.Z, breakForce, p14, p15, p16, p17, p18)
  41.         End Sub
  42.  
  43.         Public Sub AttachEntToEnt(ent1 As Entity, ent2 As Entity, boneIndex As Int32, offset As GTA.Math.Vector3, rot As GTA.Math.Vector3, b1 As Boolean, _
  44.                                    isRelative As Boolean, ignoreUpVec As Boolean, b2 As Boolean, i1 As Int32, b3 As Boolean)
  45.  
  46.             Native.Function.Call(Native.Hash.ATTACH_ENTITY_TO_ENTITY, ent1, ent2, boneIndex, offset.X, offset.Y, offset.Z, rot.X, rot.Y, rot.Z, b1, isRelative, ignoreUpVec, b2, i1, b3)
  47.         End Sub
  48.  
  49.         Public Sub ResetAttachPoints(Optional deleteEnts As Boolean = True)
  50.  
  51.             AttachOffX = 0
  52.             AttachOffY = 0
  53.             AttachOffZ = 0
  54.  
  55.             AttachRotX = 0
  56.             AttachRotY = 0
  57.             AttachRotZ = 0
  58.  
  59.             AttachIncrement = 0.01
  60.             attachIncAux = 0.01
  61.  
  62.             If deleteEnts Then
  63.                 For Each e As Entity In World.GetAllEntities
  64.                     If Exists(e) AndAlso (e <> player.Character) Then
  65.                         If e.IsAttached Then e.Delete()
  66.                     End If
  67.                 Next
  68.             End If
  69.  
  70.         End Sub
  71.  
  72.         Public Function Exists(ByVal mEntity As Entity) As Boolean
  73.             If Not Native.Function.Call(Of Boolean)(Native.Hash.DOES_ENTITY_EXIST, mEntity) _
  74.                 OrElse Not mEntity <> Nothing Then Return False
  75.             Return True
  76.         End Function
  77.  
  78.         Private Sub onTick(ByVal sender As Object, ByVal e As EventArgs)
  79.  
  80.  
  81.             If AttachHelperOn AndAlso Exists(AttachEntity) Then
  82.                 AttachEntToEnt(AttachEntity, player.Character, player.Character.GetBoneIndex(cBone), New GTA.Math.Vector3(AttachOffX, AttachOffY, AttachOffZ), _
  83.                               New GTA.Math.Vector3(AttachRotX, AttachRotY, AttachRotZ), True, True, True, True, 1, True)
  84.  
  85.                 'AttachEntToEntPhys(attachEntity, player.Character, player.Character.GetBoneIndex(Bone.IK_Head), 0.0, New Vector3(AttachOffX, AttachOffY, AttachOffZ), _
  86.                 '            New Vector3(10.0, 5.0, 5.0), New Vector3(AttachRotX, AttachRotY, AttachRotZ), -1.0F, True, True, False, False, 2)
  87.  
  88.                 Dim _rotMode As String = ""
  89.  
  90.                 If RotationMode Then
  91.                     _rotMode = "Rotation Mode ON"
  92.                 Else
  93.                     _rotMode = "Rotation Mode OFF"
  94.                 End If
  95.  
  96.                 If Not resetConfirm Then
  97.                     msg("[" & _rotMode & "] offX: " & mRnd(AttachOffX, 2) & " offY: " & mRnd(AttachOffY, 2) & " offZ: " & mRnd(AttachOffZ, 2) & _
  98.                                " RotX: " & mRnd(AttachRotX, 2) & " RotY: " & mRnd(AttachRotY, 2) & " RotZ: " & mRnd(AttachRotZ, 2) & " AttachInc: " _
  99.                                & mRnd(AttachIncrement, 2) & " Bone: " & cBone.ToString, 10)
  100.                 End If
  101.             End If
  102.  
  103.  
  104.         End Sub
  105.  
  106.         Private Sub onKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
  107.  
  108.             If e.KeyCode = Keys.F9 Then
  109.                 AttachHelperOn = Not AttachHelperOn
  110.  
  111.                 If AttachHelperOn Then
  112.                     msg("Attach Helper ON", 3000)
  113.                     ResetAttachPoints()
  114.                     '
  115.                     AttachEntity = World.CreateProp("p_ld_soc_ball_01", player.Character.Position, True, False)
  116.                     ' attachEntity = World.CreateVehicle("adder", player.Character.Position)
  117.                 Else
  118.                     msg("Attach Helper OFF", 300)
  119.                     ResetAttachPoints()
  120.                     If Exists(AttachEntity) Then
  121.                         AttachEntity.Delete()
  122.                         AttachEntity = Nothing
  123.                     End If
  124.                 End If
  125.             End If
  126.  
  127.             If AttachHelperOn Then
  128.  
  129.                 If e.KeyCode = Keys.F8 Then
  130.                     RotationMode = Not RotationMode
  131.                 End If
  132.  
  133.                 If Not Exists(AttachEntity) Then Exit Sub
  134.  
  135.                 Select Case e.KeyCode
  136.  
  137.                     Case Keys.NumPad7 'FORWARD
  138.  
  139.                         If RotationMode Then
  140.                             AttachRotY += AttachIncrement
  141.                         Else
  142.                             AttachOffY += AttachIncrement
  143.                         End If
  144.  
  145.                         Exit Select
  146.  
  147.                     Case Keys.NumPad1 'BACKWARD
  148.  
  149.                         If RotationMode Then
  150.                             AttachRotY -= AttachIncrement
  151.                         Else
  152.                             AttachOffY -= AttachIncrement
  153.                         End If
  154.  
  155.                         Exit Select
  156.  
  157.                     Case Keys.NumPad8 'UP
  158.  
  159.                         If RotationMode Then
  160.                             AttachRotX += AttachIncrement
  161.                         Else
  162.                             AttachOffX += AttachIncrement
  163.                         End If
  164.  
  165.                         Exit Select
  166.  
  167.                     Case Keys.NumPad2 'DOWN
  168.  
  169.                         If RotationMode Then
  170.                             AttachRotX -= AttachIncrement
  171.                         Else
  172.                             AttachOffX -= AttachIncrement
  173.                         End If
  174.  
  175.                         Exit Select
  176.  
  177.                     Case Keys.NumPad4 'LEFT
  178.  
  179.                         If RotationMode Then
  180.                             AttachRotZ += AttachIncrement
  181.                         Else
  182.                             AttachOffZ += AttachIncrement
  183.                         End If
  184.  
  185.                         Exit Select
  186.  
  187.                     Case Keys.NumPad6 'RIGHT
  188.  
  189.                         If RotationMode Then
  190.                             AttachRotZ -= AttachIncrement
  191.                         Else
  192.                             AttachOffZ -= AttachIncrement
  193.                         End If
  194.  
  195.                     Case Keys.Add '+INC
  196.  
  197.                         If AttachIncrement = 0.01 Then
  198.                             attachIncAux = 0.001
  199.                         Else
  200.                             attachIncAux = 0.01
  201.                         End If
  202.  
  203.                         AttachIncrement += attachIncAux
  204.  
  205.                     Case Keys.Subtract '-INC
  206.  
  207.                         If AttachIncrement = 0.01 Then
  208.                             attachIncAux = 0.001
  209.                         Else
  210.                             attachIncAux = 0.01
  211.                         End If
  212.  
  213.  
  214.                         AttachIncrement -= attachIncAux
  215.  
  216.  
  217.                     Case Keys.NumPad0
  218.  
  219.                         resetConfirm = Not resetConfirm
  220.  
  221.                         msg("Attach Reset: ARE YOU SURE, PRESS Y/N", 10000)
  222.  
  223.                         Dim input As String = Game.GetUserInput(1)
  224.                         If input.ToLower = "y" OrElse input.ToLower = "yes" Then
  225.                             ResetAttachPoints(False)
  226.                             resetConfirm = False
  227.                         Else
  228.                             resetConfirm = False
  229.                             Exit Select
  230.                         End If
  231.                         Exit Select
  232.  
  233.                 End Select
  234.  
  235.             End If
  236.  
  237.         End Sub
  238.  
  239.     End Class '==> TAttachHelper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement