Advertisement
qiangqiang101

MP Point in SP

Dec 7th, 2018
1,383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.61 KB | None | 0 0
  1. 'Reference from https://forum.fivem.net/t/help-finger-point/25652
  2.  
  3. Imports System.Runtime.CompilerServices
  4. Imports GTA
  5. Imports GTA.Native
  6. Imports System.Math
  7. Imports GTA.Math
  8.  
  9. Public Class mpPoint
  10.     Inherits Script
  11.  
  12.     Dim mp_pointing As Boolean = False
  13.     Dim ped As Ped
  14.     Public Shared config As ScriptSettings = ScriptSettings.Load("scripts\MP_Point.ini")
  15.     Dim dtTimer As Integer = 0
  16.     Dim timeout As Integer = 0
  17.  
  18.     Dim once As Boolean = False
  19.     Dim oldval As Boolean = False
  20.     Dim oldvalped As Boolean = False
  21.  
  22.     Public Sub New()
  23.     End Sub
  24.  
  25.     Private Sub Point_Tick(sender As Object, e As EventArgs) Handles Me.Tick
  26.         ped = Game.Player.Character
  27.         config = ScriptSettings.Load("scripts\MP_Point.ini")
  28.  
  29.         If once Then once = False
  30.  
  31.         If Not config.GetValue(Of Boolean)("GENERAL", "DoubleTap", False) Then 'Keyboard
  32.             If Game.IsControlJustReleased(0, Control.SpecialAbilitySecondary) AndAlso Not mp_pointing AndAlso ped.IsOnFoot AndAlso Not Game.Player.IsPlayerFreeAiming Then
  33.                 Script.Wait(200)
  34.                 StartPointing()
  35.                 mp_pointing = True
  36.             End If
  37.  
  38.             If Game.IsControlJustReleased(0, Control.SpecialAbilitySecondary) AndAlso mp_pointing AndAlso ped.IsOnFoot AndAlso Not Game.Player.IsPlayerFreeAiming Then
  39.                 Script.Wait(200)
  40.                 StopPointing()
  41.                 mp_pointing = False
  42.             End If
  43.         Else 'Joypad
  44.             If Game.IsControlJustReleased(0, Control.SpecialAbilitySecondary) Then
  45.                 dtTimer += 1
  46.                 timeout = Game.GameTime
  47.             End If
  48.  
  49.             If dtTimer >= 2 AndAlso Not mp_pointing AndAlso ped.IsOnFoot AndAlso Not Game.Player.IsPlayerFreeAiming Then
  50.                 Script.Wait(200)
  51.                 StartPointing()
  52.                 mp_pointing = True
  53.                 dtTimer = 0
  54.             End If
  55.  
  56.             If dtTimer >= 2 AndAlso mp_pointing AndAlso ped.IsOnFoot AndAlso Not Game.Player.IsPlayerFreeAiming Then
  57.                 Script.Wait(200)
  58.                 StopPointing()
  59.                 mp_pointing = False
  60.                 dtTimer = 0
  61.             End If
  62.         End If
  63.  
  64.         If ped.UnkNative_0x921CE12C489C4C41() AndAlso Not mp_pointing Then
  65.             StopPointing()
  66.         End If
  67.         If ped.UnkNative_0x921CE12C489C4C41() Then
  68.             If Not ped.IsOnFoot Then
  69.                 StopPointing()
  70.             Else
  71.                 Dim camPitch = GameplayCamera.RelativePitch
  72.                 If camPitch < -70.0F Then
  73.                     camPitch = -70.0F
  74.                 ElseIf camPitch > 42.0F Then
  75.                     camPitch = 42.0F
  76.                 End If
  77.                 camPitch = (camPitch + 70.0F) / 112.0F
  78.  
  79.                 Dim camHeading = GameplayCamera.RelativeHeading
  80.                 Dim cosCamHeading = Cos(camHeading)
  81.                 Dim sinCamHeading = Sin(camHeading)
  82.                 If camHeading < -180.0F Then
  83.                     camHeading = -180.0F
  84.                 ElseIf camHeading > 180.0F Then
  85.                     camHeading = 180.0F
  86.                 End If
  87.                 camHeading = (camHeading + 180.0F) / 360.0F
  88.  
  89.                 Dim blocked = 0
  90.                 Dim nn = 0
  91.  
  92.                 Dim coords = ped.GetOffsetInWorldCoords(New Vector3((cosCamHeading * -0.2F) - (sinCamHeading * (0.4F * camHeading + 0.3F)), (sinCamHeading * -0.2F) + (cosCamHeading * (0.4F * camHeading + 0.3F)), 0.6F))
  93.                 Dim ray = World.Raycast(New Vector3(coords.X, coords.Y, coords.Z - 0.2F), New Vector3(coords.X, coords.Y, coords.Z + 0.2F), 0.4F, 95, ped)
  94.                 nn = ray.Result
  95.                 blocked = ray.Result
  96.  
  97.                 ped.UnkNative_0xD5BB4025AE449A4E("Pitch", camPitch)
  98.                 ped.UnkNative_0xD5BB4025AE449A4E("Heading", camHeading * -1.0F + 1.0F)
  99.                 ped.UnkNative_0xB0A6CFD2C69C1088("isBlocked", blocked)
  100.                 ped.UnkNative_0xB0A6CFD2C69C1088("isFirstPerson", UnkNative_0xEE778F8C7E1142E2() = 4)
  101.             End If
  102.         End If
  103.  
  104.         If timeout <= (Game.GameTime - 500) Then
  105.             dtTimer = 0
  106.         End If
  107.  
  108.         If Game.IsControlJustPressed(0, Control.Attack) OrElse Game.IsControlJustPressed(0, Control.Aim) Then
  109.             StopPointing()
  110.             mp_pointing = False
  111.             dtTimer = 0
  112.         End If
  113.     End Sub
  114.  
  115.     Public Sub StartPointing()
  116.         RequestAnimDict("anim@mp_point")
  117.         If config.GetValue(Of Boolean)("GENERAL", "HideWeapon", True) Then ped.SetPedCurrentWeaponVisible()
  118.         ped.SetPedConfigFlag(PedConfigFlags.PointingFlag)
  119.         ped.TaskMoveNetwork("task_mp_pointing", 0.5F, "anim@mp_point", 24)
  120.         RemoveAnimDict("anim@mp_point")
  121.     End Sub
  122.  
  123.     Public Sub StopPointing()
  124.         ped.UnkNative_0xD01015C7316AE176("Stop")
  125.         If Not ped.IsInjured Then ped.Task.ClearSecondary()
  126.         If Not ped.IsInVehicle() Then
  127.             If config.GetValue(Of Boolean)("GENERAL", "HideWeapon", True) Then ped.SetPedCurrentWeaponVisible()
  128.         End If
  129.         ped.SetPedConfigFlag(PedConfigFlags.PointingFlag)
  130.         ped.Task.ClearSecondary()
  131.     End Sub
  132. End Class
  133.  
  134. Public Module PointHelper
  135.  
  136.     <Extension()>
  137.     Public Sub SetPedCurrentWeaponVisible(ped As Ped)
  138.         Native.Function.Call(Hash.SET_PED_CURRENT_WEAPON_VISIBLE, ped.Handle, False, True, True, True)
  139.     End Sub
  140.  
  141.     <Extension()>
  142.     Public Sub SetPedConfigFlag(ped As Ped, flags As PedConfigFlags)
  143.         Native.Function.Call(Hash.SET_PED_CONFIG_FLAG, ped.Handle, flags, 1)
  144.     End Sub
  145.  
  146.     Public Enum PedConfigFlags
  147.         PED_FLAG_CAN_FLY_THRU_WINDSCREEN = 32
  148.         PED_FLAG_DIES_BY_RAGDOLL = 33
  149.         PointingFlag = 36
  150.         PED_FLAG_NO_COLLISION = 52
  151.         _PED_FLAG_IS_SHOOTING = 58
  152.         _PED_FLAG_IS_ON_GROUND = 60
  153.         PED_FLAG_NO_COLLIDE = 62
  154.         PED_WAS_KILLED_BY_TAKEDOWN = 70
  155.         PED_FLAG_DEAD = 71
  156.         PED_FLAG_IS_SNIPER_SCOPE_ACTIVE = 72
  157.         PED_FLAG_SUPER_DEAD = 73
  158.         _PED_FLAG_IS_IN_AIR = 76
  159.         PED_FLAG_IS_AIMING = 78
  160.         PED_FLAG_DRUNK = 100
  161.         _PED_FLAG_IS_NOT_RAGDOLL_AND_NOT_PLAYING_ANIM = 104
  162.         PED_FLAG_NO_PLAYER_MELEE = 122
  163.         PED_FLAG_NM_MESSAGE_466 = 125
  164.         PED_FLAG_INJURED_LIMP = 166
  165.         PED_FLAG_INJURED_LIMP_2 = 170
  166.         PED_FLAG_INJURED_DOWN = 187
  167.         PED_FLAG_SHRINK = 223
  168.         PED_FLAG_MELEE_COMBAT = 224
  169.         _PED_FLAG_IS_ON_STAIRS = 253
  170.         _PED_FLAG_HAS_ONE_LEG_ON_GROUND = 276
  171.         PED_FLAG_NO_WRITHE = 281
  172.         PED_FLAG_FREEZE = 292
  173.         PED_FLAG_IS_STILL = 301
  174.         PED_FLAG_NO_PED_MELEE = 314
  175.         _PED_SWITCHING_WEAPON = 331
  176.         PED_FLAG_ALPHA = 410
  177.     End Enum
  178.  
  179.     <Extension()>
  180.     Public Sub TaskMoveNetwork(ped As Ped, task As String, multiplier As Single, anim As String, flag As Integer)
  181.         Native.Function.Call(Hash._0x2D537BA194896636, ped.Handle, task, multiplier, False, anim, flag)
  182.     End Sub
  183.  
  184.     <Extension()>
  185.     Public Sub UnkNative_0xD01015C7316AE176(ped As Ped, p1 As String)
  186.         Native.Function.Call(Hash._0xD01015C7316AE176, ped.Handle, p1)
  187.     End Sub
  188.  
  189.     Public Sub RequestAnimDict(value As String)
  190.         Native.Function.Call(Hash.REQUEST_ANIM_DICT, value)
  191.         Dim endtime = DateTime.UtcNow + New TimeSpan(0, 0, 0, 0, 1000)
  192.         While Not Native.Function.Call(Of Boolean)(Hash.HAS_ANIM_DICT_LOADED, value)
  193.             Script.Yield()
  194.             If DateTime.UtcNow >= endtime Then
  195.                 Return
  196.             End If
  197.         End While
  198.     End Sub
  199.  
  200.     Public Sub RemoveAnimDict(value As String)
  201.         Native.Function.Call(Hash.REMOVE_ANIM_DICT, value)
  202.     End Sub
  203.  
  204.     <Extension()>
  205.     Public Function UnkNative_0x921CE12C489C4C41(ped As Ped) As Boolean
  206.         Return Native.Function.Call(Of Boolean)(Hash._0x921CE12C489C4C41, ped.Handle)
  207.     End Function
  208.  
  209.     <Extension()>
  210.     Public Sub UnkNative_0xD5BB4025AE449A4E(ped As Ped, p1 As String, p2 As Single)
  211.         Native.Function.Call(Hash._0xD5BB4025AE449A4E, ped, p1, p2)
  212.     End Sub
  213.  
  214.     <Extension()>
  215.     Public Sub UnkNative_0xB0A6CFD2C69C1088(ped As Ped, p1 As String, p2 As Integer)
  216.         Native.Function.Call(Hash._0xB0A6CFD2C69C1088, ped, p1, p2)
  217.     End Sub
  218.  
  219.     Public Function UnkNative_0xEE778F8C7E1142E2() As Integer
  220.         Dim unk = Native.Function.Call(Of Integer)(Hash._0x19CAFA3C87F7C2FF)
  221.         Return Native.Function.Call(Of Integer)(Hash._0xEE778F8C7E1142E2, unk)
  222.     End Function
  223.  
  224.     <Extension()>
  225.     Public Function IsPlayerFreeAiming(player As Player) As Boolean
  226.         Return Native.Function.Call(Of Boolean)(Hash.IS_PLAYER_FREE_AIMING, player)
  227.     End Function
  228. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement