- Imports area: here we will declare the added libraries/classes/what ever its known as items that we will want in the script, the simple is:
Imports Method
Imports GTA
yet another fascinating imports are:
Imports Method.Windows.Types
Imports Method.Drawing
Imports Program.Collections.Generic
Imports Technique.IO
- Class header: right here the primary class begins, here we can set the name of the script that will seem in the console window when the script is loaded
Public Class myBasicScript
    Inherits Script
- Variables/Constants/Classes/Enumerations location: right here we can declare the variables that we will need to have along the script, also declare classes, constants:
Private bScriptOn As Boolean = False
Private sMessage As string
Private Class TDarts
        Public dart As GTA.Object = Practically nothing
        Public launched As Boolean = False
        Public target As Ped = Nothing at all
end class
- Then comes the "event" that will occur when the script is loaded by the scripthook:
Sub New()
       me.Interval = ten
       sMessage = "Script loaded :)"
end sub
Here we can initiate variables/objects, load textures, sounds, what ever you need to do only a single time in the script execution.
- The keydown occasion: this event will occur each time that the player press an key or click with mouse
Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
the object "e" will receive the info about the keypress, it can have the name that you want, for instance you can use "k As GTA.KeyEventArgs" alternatively of "e As GTA.KeyEventArgs",  through this we can determine what essential was pressed through the element e.Important, for instance, if we wish to identify when user press important "A":
Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
        if e.essential = keys.A then 
        finish if
finish sub
the keyUp event has the very same parameters and will occur when the key is released:
Private Sub keyUp(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyUp
- The Console event: this will occur when user input some text in the console window and press enter:
Private Sub console_CMD(ByVal sender As Object, ByVal cmd As ConsoleEventArgs) Handles MyBase.ConsoleCommand
Private Sub console_CMD(ByVal sender As Object, ByVal cmd  s ConsoleEventArgs) Handles MyBase.ConsoleCommand
        If cmd.Command = "die" Then
            If cmd.ParameterCount > Then
                If cmd.Parameter().ToLower = "now" Then
                    Player.Character.Die()
                ElseIf Int16.Parse(cmd.Parameter()) > Then
                    Wait(Int16.Parse(cmd.Parameter()))
                    Player.Character.Die()
                End If
            Finish If
        End If
 End Sub
via approach Game.Console.Print we can display an message on the console:
Private Sub console_CMD(ByVal sender As Object, ByVal cmd As ConsoleEventArgs) Handles MyBase.ConsoleCommand
        Game.Console.Print("You typed an console command..." & cmd.Command)
 End Sub
- Tick occasion: this occur each and every X miliseconds, primarily based on variable me.Interval:
Private Sub common_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
for instance, if we want to heal player life each and every 10 miliseconds (me.Interval):
Private Sub basic_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
        player.character.health += 1
end sub
- PerFrameDrawing event: this will occur at each and every frame of the game, you should be carefull when employing this event
Private Sub GraphicsEventHandler(ByVal sender As Object, ByVal g As GTA.GraphicsEventArgs) Handles MyBase.PerFrameDrawing
via element g.Graphics we can draw texts, rectangles, lines and textues:
Private Sub GraphicsEventHandler(ByVal sender As Object, ByVal e As GTA.GraphicsEventArgs) Handles MyBase.PerFrameDrawing
        e.Graphics.DrawText("my text inside the PerFrameDrawing event", ten, 10)
' draw the text beginning at ten, 10 (X, Y screen position)
        e.Graphics.DrawLine(ten, 20, one hundred, 20, 1, Color.Red)
' draw an line starting at ten, 20, ending at 100, 20, with 1of width and red colour
        e.Graphics.DrawRectangle(100, 100, 200, 200, colour.FromArgb(one hundred, 255, 255, 255))
' draw an rectangle with center at one hundred, one hundred, with 200 of width, 200 of height and with semi transparent white colour
        e.Graphics.DrawSprite(textureTest, 300, 300, one hundred, 100, )
' draw an texture with center at 300, 300, with 100 of widht, 100 of height and of rotation
end sub
an extra technique that i like to use when creating is:
Private Sub msg(ByVal sMsg As String, ByVal time As Int32)
        Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", sMsg, time, 1)
End Sub
this just show an message in the botton center of the screen, really usefull to see variable values
- the principal Class ending: right here the major class of the script ends
End Class
an crucial thing about the events is the text "Handles", this portion will figure out what the event will handle, for example:
Handles MyBase.KeyDown
Handles MyBase.KeyUp
Handles MyBase.ConsoleCommand
Handles MyBase.PerFrameDrawing
an additional critical portion is the element that will get the events approaches/properties, for instance, here we employed:
e As GTA.KeyEventArgs in the keydown occasion
cmd  As ConsoleEventArgs in the console event
e As GTA.GraphicsEventArgs in the PerFrameDrawing
you can download an sample script here.
[TIP-IV] Basic scripting - Script structure and main events [GTA IV
vb.net]
9out of 10 based on 10 ratings. 9 user reviews.
9out of 10 based on 10 ratings. 9 user reviews.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.