Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'intermediate progress, need refining, and a custom constructor
- Public Class TAttachHelper
- Inherits Script
- Private AttachHelperOn As Boolean = False
- Private AttachIncrement As Single = 0.01
- Private attachIncAux As Single = 0.01
- Private RotationMode As Boolean = False
- Private resetConfirm As Boolean = False
- Private cBone As Bone = Bone.IK_L_Hand
- Private AttachOffX As Single = 0.0
- Private AttachOffY As Single = 0.0
- Private AttachOffZ As Single = 0.0
- Private AttachRotX As Single = 0.0
- Private AttachRotY As Single = 0.0
- Private AttachRotZ As Single = 0.0
- Private AttachEntity As Prop = Nothing
- Public Function mRnd(ByVal deci As Double, ByVal places As Int16) As Double
- Return Math.Round(deci, places)
- End Function
- Public Sub New()
- AddHandler Tick, AddressOf onTick
- AddHandler KeyDown, AddressOf onKeyDown
- Interval = 10
- End Sub
- Public Sub msg(ByVal text As String, Optional ByVal time As Integer = 2500)
- GTA.Native.Function.Call(Native.Hash._SET_TEXT_ENTRY_2, "STRING")
- GTA.Native.Function.Call(Native.Hash._ADD_TEXT_COMPONENT_STRING, text)
- GTA.Native.Function.Call(Native.Hash._0x9D77056A530643F6, time, 1)
- End Sub
- 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)
- 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)
- End Sub
- 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, _
- isRelative As Boolean, ignoreUpVec As Boolean, b2 As Boolean, i1 As Int32, b3 As Boolean)
- 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)
- End Sub
- Public Sub ResetAttachPoints(Optional deleteEnts As Boolean = True)
- AttachOffX = 0
- AttachOffY = 0
- AttachOffZ = 0
- AttachRotX = 0
- AttachRotY = 0
- AttachRotZ = 0
- AttachIncrement = 0.01
- attachIncAux = 0.01
- If deleteEnts Then
- For Each e As Entity In World.GetAllEntities
- If Exists(e) AndAlso (e <> player.Character) Then
- If e.IsAttached Then e.Delete()
- End If
- Next
- End If
- End Sub
- Public Function Exists(ByVal mEntity As Entity) As Boolean
- If Not Native.Function.Call(Of Boolean)(Native.Hash.DOES_ENTITY_EXIST, mEntity) _
- OrElse Not mEntity <> Nothing Then Return False
- Return True
- End Function
- Private Sub onTick(ByVal sender As Object, ByVal e As EventArgs)
- If AttachHelperOn AndAlso Exists(AttachEntity) Then
- AttachEntToEnt(AttachEntity, player.Character, player.Character.GetBoneIndex(cBone), New GTA.Math.Vector3(AttachOffX, AttachOffY, AttachOffZ), _
- New GTA.Math.Vector3(AttachRotX, AttachRotY, AttachRotZ), True, True, True, True, 1, True)
- 'AttachEntToEntPhys(attachEntity, player.Character, player.Character.GetBoneIndex(Bone.IK_Head), 0.0, New Vector3(AttachOffX, AttachOffY, AttachOffZ), _
- ' New Vector3(10.0, 5.0, 5.0), New Vector3(AttachRotX, AttachRotY, AttachRotZ), -1.0F, True, True, False, False, 2)
- Dim _rotMode As String = ""
- If RotationMode Then
- _rotMode = "Rotation Mode ON"
- Else
- _rotMode = "Rotation Mode OFF"
- End If
- If Not resetConfirm Then
- msg("[" & _rotMode & "] offX: " & mRnd(AttachOffX, 2) & " offY: " & mRnd(AttachOffY, 2) & " offZ: " & mRnd(AttachOffZ, 2) & _
- " RotX: " & mRnd(AttachRotX, 2) & " RotY: " & mRnd(AttachRotY, 2) & " RotZ: " & mRnd(AttachRotZ, 2) & " AttachInc: " _
- & mRnd(AttachIncrement, 2) & " Bone: " & cBone.ToString, 10)
- End If
- End If
- End Sub
- Private Sub onKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
- If e.KeyCode = Keys.F9 Then
- AttachHelperOn = Not AttachHelperOn
- If AttachHelperOn Then
- msg("Attach Helper ON", 3000)
- ResetAttachPoints()
- '
- AttachEntity = World.CreateProp("p_ld_soc_ball_01", player.Character.Position, True, False)
- ' attachEntity = World.CreateVehicle("adder", player.Character.Position)
- Else
- msg("Attach Helper OFF", 300)
- ResetAttachPoints()
- If Exists(AttachEntity) Then
- AttachEntity.Delete()
- AttachEntity = Nothing
- End If
- End If
- End If
- If AttachHelperOn Then
- If e.KeyCode = Keys.F8 Then
- RotationMode = Not RotationMode
- End If
- If Not Exists(AttachEntity) Then Exit Sub
- Select Case e.KeyCode
- Case Keys.NumPad7 'FORWARD
- If RotationMode Then
- AttachRotY += AttachIncrement
- Else
- AttachOffY += AttachIncrement
- End If
- Exit Select
- Case Keys.NumPad1 'BACKWARD
- If RotationMode Then
- AttachRotY -= AttachIncrement
- Else
- AttachOffY -= AttachIncrement
- End If
- Exit Select
- Case Keys.NumPad8 'UP
- If RotationMode Then
- AttachRotX += AttachIncrement
- Else
- AttachOffX += AttachIncrement
- End If
- Exit Select
- Case Keys.NumPad2 'DOWN
- If RotationMode Then
- AttachRotX -= AttachIncrement
- Else
- AttachOffX -= AttachIncrement
- End If
- Exit Select
- Case Keys.NumPad4 'LEFT
- If RotationMode Then
- AttachRotZ += AttachIncrement
- Else
- AttachOffZ += AttachIncrement
- End If
- Exit Select
- Case Keys.NumPad6 'RIGHT
- If RotationMode Then
- AttachRotZ -= AttachIncrement
- Else
- AttachOffZ -= AttachIncrement
- End If
- Case Keys.Add '+INC
- If AttachIncrement = 0.01 Then
- attachIncAux = 0.001
- Else
- attachIncAux = 0.01
- End If
- AttachIncrement += attachIncAux
- Case Keys.Subtract '-INC
- If AttachIncrement = 0.01 Then
- attachIncAux = 0.001
- Else
- attachIncAux = 0.01
- End If
- AttachIncrement -= attachIncAux
- Case Keys.NumPad0
- resetConfirm = Not resetConfirm
- msg("Attach Reset: ARE YOU SURE, PRESS Y/N", 10000)
- Dim input As String = Game.GetUserInput(1)
- If input.ToLower = "y" OrElse input.ToLower = "yes" Then
- ResetAttachPoints(False)
- resetConfirm = False
- Else
- resetConfirm = False
- Exit Select
- End If
- Exit Select
- End Select
- End If
- End Sub
- End Class '==> TAttachHelper
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement