Tại sao script lại lấy được sự kiện nhân vật trong game GTA?

Mọi người ơi, xem giúp em đoạn code này với. đây là đoạn code Visual Basic trong một script do moder tự làm cho game GTA ( Grand theft Auto của RockstarGame ). Cho em hỏi phần đầu import GTA với GTA.Math là gì vậy ?có phải game làm sẵn thư viện không ạ với lại phần event handing, làm sao moder bắt được các sự kiện của nhân vật trong game ? vậy GTA có phải game mã nguồn mở không hay nhà SX cố tình đề người chơi tự chỉnh sửa game ?
P/s: nội dung đoạn code này: bắt sự kiện nhân vật nả đạn vào Peds ( cảnh sát ) mỗi viên đạn thì biến crimes sẽ tăng lên khi crimes > 1000 thì chế độ truy nã 6 sao sẽ kích hoạt sau đó sẽ sẽ spwam quân đội ở toạ độ bla…bla… với tần suất, số lượng và vũ khí trong đoạn switch case … bla … bla… bla
link gốc : https://www.gta5-mods.com/scripts/six-stars-army
(web chuyên cung cấp mod, script cho GTA )

Source code :

Imports System
Imports System.Windows.forms
Imports System.Drawing
Imports System.IO
Imports GTA
Imports GTA.Math

Public Module module1
    Public crimes As Single
    Public sixstars As Boolean = False
End Module
Public Class wanted

Inherits Script
Public Sub New()
    Me.Interval = 10
End Sub
Private punto As New Point, tamaño As Size
Private pedskilled As Ped()
'Private wlthreshold As Integer
Shadows Sub keydown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
    'If e.KeyCode = Keys.Y Then
    '    punto.X = 1126
    '    punto.Y = 0
    '    tamaño.Height = 19
    '    tamaño.Width = 30
    '    UI.DrawTexture(".\scripts\army\star.gif", 0, 0, 4000, punto, tamaño)
    'End If
    '    GTA.Native.Function.Call(Native.Hash.SET_MAX_WANTED_LEVEL, 6)
    '    GTA.Native.Function.Call(Native.Hash.SET_PLAYER_WANTED_LEVEL, Game.Player, 6, False)
    '    GTA.Native.Function.Call(Native.Hash.SET_PLAYER_WANTED_LEVEL_NOW, Game.Player, False)
    '    UI.ShowSubtitle("wantedlevel = 6")
End Sub
Private Sub general_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
    'GTA.Native.Function.Call(Native.Hash.GET_WANTED_LEVEL_THRESHOLD, wlthreshold)
    If Game.Player.WantedLevel = 5 Then
        If sixstars = False Then
            If Game.Player.Character.IsShooting Then
                crimes += 5
            End If
            If Game.Player.Character.IsJacking = True Then
                crimes += 2
            End If
            pedskilled = World.GetNearbyPeds(Game.Player.Character.Position, 100)
            For Each pedk As Ped In pedskilled
                If pedk.HasBeenDamagedBy(Game.Player.Character) And pedk.Money <> 5 Then
                    crimes += 10
                    pedk.Money = 5
                End If
            Next
            If crimes > 1000 Then
                sixstars = True
            End If
            UI.ShowSubtitle(crimes.ToString & "/1000")
        End If
    End If
End Sub
End Class
Public Class army
    Inherits Script

Public Sub New()
    Me.Interval = 10000
End Sub

Private v As Vehicle, s1, s2, s3, s4, s5, s6, s7, s8 As Ped, car, gun As Integer, Rnd As New Random
'Private asiento3 As VehicleSeat = 3, asiento4 As VehicleSeat = 4, asiento5 As VehicleSeat = 5
'Private asiento6 As VehicleSeat = 6, asiento7 As VehicleSeat = 7
Private punto As New Point, tamaño As Size
Private isclose As Boolean = True
Private distancia As Single
Private Rndpeds As New Random, peds As Integer, pedmodel As String
Private Rndweap As New Random, weap As Integer, weaphash As Native.WeaponHash
Shadows Sub keydown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown       
End Sub
Private Sub general_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
    'Chequea que si hay mas de 500 de wantedlevelthreshold te viene el ejercito
    If crimes > 1000 Then
        punto.X = 1126
        punto.Y = 0
        tamaño.Height = 20
        tamaño.Width = 32
        UI.DrawTexture(".\scripts\army\star.gif", 0, 0, 10050, punto, tamaño)
        'If Game.Player.Character.IsInVehicle Then
        '    If Game.Player.Character.CurrentVehicle.Model.IsHelicopter Then
        '        heliselect()
        '    End If
        'Else
        carselect()
        'End If
        If Game.Player.WantedLevel < 5 Then
            crimes = 0
            sixstars = False
        End If
    End If
End Sub

Private Sub carselect()
    car = Rnd.Next(32)
    Select Case car
        Case 0 To 4
            v = World.CreateVehicle("crusader", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s3 = v.CreatePedOnSeat(VehicleSeat.RightRear, pedmodel)
                weapselect()
                s3.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s4 = v.CreatePedOnSeat(VehicleSeat.LeftRear, pedmodel)
                weapselect()
                s4.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s3.Task.Wait(8000)
                s4.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                s3.MarkAsNoLongerNeeded()
                s4.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 5 To 9
            v = World.CreateVehicle("mesa3", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s3 = v.CreatePedOnSeat(VehicleSeat.RightRear, pedmodel)
                weapselect()
                s3.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s4 = v.CreatePedOnSeat(VehicleSeat.LeftRear, pedmodel)
                weapselect()
                s4.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s3.Task.Wait(8000)
                s4.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                s3.MarkAsNoLongerNeeded()
                s4.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 10 To 13
            v = World.CreateVehicle("insurgent2", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s3 = v.CreatePedOnSeat(VehicleSeat.RightRear, pedmodel)
                weapselect()
                s3.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s4 = v.CreatePedOnSeat(VehicleSeat.LeftRear, pedmodel)
                weapselect()
                s4.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s3.Task.Wait(8000)
                s4.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                s3.MarkAsNoLongerNeeded()
                s4.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 14 To 17
            v = World.CreateVehicle("insurgent", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s3 = v.CreatePedOnSeat(VehicleSeat.RightRear, pedmodel)
                weapselect()
                s3.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s4 = v.CreatePedOnSeat(VehicleSeat.LeftRear, pedmodel)
                weapselect()
                s4.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s5 = v.CreatePedOnSeat(7, pedmodel)
                weapselect()
                s5.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s3.Task.Wait(8000)
                s4.Task.Wait(8000)
                s5.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                s3.MarkAsNoLongerNeeded()
                s4.MarkAsNoLongerNeeded()
                s5.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 18 To 20
            v = World.CreateVehicle("barracks", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s3 = v.CreatePedOnSeat(VehicleSeat.RightRear, pedmodel)
                weapselect()
                s3.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s4 = v.CreatePedOnSeat(VehicleSeat.LeftRear, pedmodel)
                weapselect()
                s4.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s5 = v.CreatePedOnSeat(3, pedmodel)
                weapselect()
                s5.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s6 = v.CreatePedOnSeat(4, pedmodel)
                weapselect()
                s6.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s7 = v.CreatePedOnSeat(5, pedmodel)
                weapselect()
                s7.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s8 = v.CreatePedOnSeat(6, pedmodel)
                weapselect()
                s8.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s3.Task.Wait(8000)
                s4.Task.Wait(8000)
                s5.Task.Wait(8000)
                s6.Task.Wait(8000)
                s7.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                s3.MarkAsNoLongerNeeded()
                s4.MarkAsNoLongerNeeded()
                s5.MarkAsNoLongerNeeded()
                s6.MarkAsNoLongerNeeded()
                s7.MarkAsNoLongerNeeded()
                s8.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 21 To 23
            v = World.CreateVehicle("barracks2", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 24 To 26
            v = World.CreateVehicle("barracks3", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s3 = v.CreatePedOnSeat(VehicleSeat.RightRear, pedmodel)
                weapselect()
                s3.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s4 = v.CreatePedOnSeat(VehicleSeat.LeftRear, pedmodel)
                weapselect()
                s4.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s5 = v.CreatePedOnSeat(3, pedmodel)
                weapselect()
                s5.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s6 = v.CreatePedOnSeat(4, pedmodel)
                weapselect()
                s6.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s7 = v.CreatePedOnSeat(5, pedmodel)
                weapselect()
                s7.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s8 = v.CreatePedOnSeat(6, pedmodel)
                weapselect()
                s8.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s3.Task.Wait(8000)
                s4.Task.Wait(8000)
                s5.Task.Wait(8000)
                s6.Task.Wait(8000)
                s6.Task.Wait(8000)
                s7.Task.Wait(8000)
                s8.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                s3.MarkAsNoLongerNeeded()
                s4.MarkAsNoLongerNeeded()
                s5.MarkAsNoLongerNeeded()
                s6.MarkAsNoLongerNeeded()
                s7.MarkAsNoLongerNeeded()
                s8.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 27 To 29
            v = World.CreateVehicle("technical", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)

                pedselect()
                s3 = v.CreatePedOnSeat(VehicleSeat.LeftRear, pedmodel)
                weapselect()
                s3.Weapons.Give(weaphash, 999, True, True)

                s1.MarkAsNoLongerNeeded()
                s2.Task.Wait(8000)
                s2.MarkAsNoLongerNeeded()
                s3.Task.Wait(8000)
                s3.MarkAsNoLongerNeeded()
                v.MarkAsNoLongerNeeded()
            End If
        Case 30
            v = World.CreateVehicle("rhino", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)
                s1.MarkAsNoLongerNeeded()
            End If
        Case Else
            v = World.CreateVehicle("APC", Game.Player.Character.Position.Around(90.0F))
            v.PlaceOnNextStreet()
            checkdist()
            If isclose = False Then
                pedselect()
                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, pedmodel)
                weapselect()
                s1.Weapons.Give(weaphash, 999, True, True)
                s1.MarkAsNoLongerNeeded()

                pedselect()
                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, pedmodel)
                weapselect()
                s2.Weapons.Give(weaphash, 999, True, True)
                s2.MarkAsNoLongerNeeded()
            End If
    End Select
    If Game.Player.Character.IsInVehicle = True Then
        v.Heading = Game.Player.Character.CurrentVehicle.Heading
        v.Speed = Game.Player.Character.CurrentVehicle.Speed
    End If
End Sub

'Private Sub heliselect()
'    car = Rnd.Next(3)
'    Select Case car
'        Case 0
'            v = World.CreateVehicle("buzzard", Game.Player.Character.Position.Around(90.0F))
'            checkdist()
'            If isclose = False Then
'                s1 = v.CreatePedOnSeat(VehicleSeat.Driver, "S_M_Y_Marine_01")
'                s2 = v.CreatePedOnSeat(VehicleSeat.RightFront, "S_M_Y_Marine_02")
'                s3 = v.CreatePedOnSeat(VehicleSeat.LeftRear, "S_M_Y_Marine_01")
'                s4 = v.CreatePedOnSeat(VehicleSeat.RightRear, "S_M_Y_Marine_02")
'                s1.Weapons.Give(Native.WeaponHash.CarbineRifle, 999, True, True)
'                s2.Weapons.Give(Native.WeaponHash.CarbineRifle, 999, True, True)
'                s3.Weapons.Give(Native.WeaponHash.CarbineRifle, 999, True, True)
'                s4.Weapons.Give(Native.WeaponHash.CarbineRifle, 999, True, True)
'                s1.AlwaysKeepTask = True
'                s1.Task.ShootAt(Game.Player.Character, 99999, FiringPattern.BurstFireHeli)
'                s1.MarkAsNoLongerNeeded()
'                s2.Task.Wait(8000)
'                s3.Task.Wait(8000)
'                s4.Task.Wait(8000)
'                s2.MarkAsNoLongerNeeded()
'

Mở thì có luôn cả mã nguồn gốc, chưa biên dịch.
Có lẽ đây là bộ thư viện đã biên dịch (.dll).

4 Likes

Không.

Nếu bạn chịu khó đọc kĩ nội dung bản mod trong đường link kia, thì người ta code trên nền của cái này:


Nên, đấy, không phải tự nhiên mà script từ trên trời rơi xuống.

5 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?