Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'http://www.facebook.com/GtaIVScripting
- 'https://www.youtube.com/user/GTAScripting
- ' ############### this is a basic vb.net script, with this you can handle some important events like KeyPress and Tick #################
- ' in this area we declare the imports, we will have to change this part in specific cases, for example, when we want to handle files, to use colors based on color name, etc
- Imports System ' basic imports
- Imports GTA ' basic imports
- Imports System.Windows.Forms ' needed to have access to "keys" enumeration, for example
- Imports System.Drawing ' needed to handle colors referencing the color name, ex: myCar.color = System.Drawing.Color.Black
- Public Class BasicScript
- Inherits Script
- ' good place to declare some global variables
- private myPed as ped
- private myCar as vehicle
- ' the following method is called when the script is loaded by the scripthook
- ' you can use it to set default values, load .ini configs, etc
- Public Sub New()
- Me.interval = 10 ' the script interval for "tick" events
- End Sub
- ' this method just make easier to print a msg on the screen
- private sub msg(sMsg as string, time as int32)
- Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", sMsg, time, 1)
- ' Native.Function.Call executes an gta native function, in this example it calls PRINT_STRING_WITH_LITERAL_STRING_NOW
- ' "STRING", sMsg, time, 1 are the parameters of the function
- end sub
- ' this is an event, when the player press one key, this is called and you can see what key is pressed
- Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
- ' how to discover what key was pressed? simple:
- if (e.key = keys.mbutton) then
- end if
- ' other example
- if (e.key = keys.Q) then
- end if
- End Sub
- Private Sub keyUp(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyUp
- ' this can be used when you need to activate the hotkey only when the user releases the key
- end sub
- ' this is an Tick event, this will be called each 10 milliseconds (me.interval), lag can cause delay
- Private Sub general_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
- end sub
- End Class
- ' ###########################################################################################################################
- ' now the basic programming explanations...
- ' the lines above represents a very basic script, with this you can start creating scripts
- ' but first there are some important things that must be understood
- ' 1 - Variables
- ' basically you will use two forms to declare variables:
- ' Private myGlobalVar as myVarType
- ' Dim myLocalVar as myVarType
- ' Private means that the variable will be available in the whole script
- ' Dim means that the variable will be available in the current block/statement
- ' myVarType is the type of the variable, for example,
- ' Int32 that are integer numbers (-2, -3, 0, 1, 5, 999999)
- ' Double that os a floting point variable (0.2, 0, -1.5, 12, 15.5664)
- ' String that is a string ("Test")
- ' Ped that is a game object, it represents a Pedestrian, basically all the peds on streets
- ' obs.: Variable names must be unique
- ' 2 - Methods
- ' methods are "blocks os codes" that help do something an make the script easy to read and to fix
- ' methods can return values or not
- ' an method that return value is a Function, the one that does not return a value is a Sub
- ' to declare a method we do the following:
- ' Private Sub MySubMethod
- ' end sub
- ' where MySubMethod is the name of the method
- ' for Function its almost the same:
- ' Private Function MyFuncMethod
- ' Return AnyThing
- ' end Function
- ' when we call the Return in a Function, the execution of the method stops at that point and returns the especified value
- ' methods can receive parameters too, example:
- ' Private Function MyFuncMethod(p1 as int32, p2 as double)
- ' Return p1 * p2
- ' end Function
- ' example of use:
- '
- ' Private Sub keyUp(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyUp
- ' if e.key = keys.O then Test1
- '
- ' if e.key = keys.P then Test2(125)
- ' end sub
- '
- ' Private Sub Test1
- ' end sub
- '
- ' Private Function Test2(pParam as int16)
- ' return pParam / 2
- ' end Function
- '
- ' 3 - Conditions
- ' an condition checks if somthing is True, then do something, if not true do "elsething"
- ' example:
- ' if myVar = 1 then
- ' ' do something
- ' else
- ' ' do "elsething"
- ' end if
- ' other example, without else statement:
- ' if (myVar > 1) andalso (myVar < 5) then
- ' ' do something
- ' end if
- ' if there is only one thing to do we can use it on a single line:
- ' if myVar > 1 then myVar = 0
- '
- ' 4 - Condition operators
- ' basically we use: And, AndAlso, Or, OrElse:
- ' And checks if the first condition And the second condition is true
- ' AndAlso checks if the first condition is true, if its true then checks the second condition
- ' Or checks if the first condition Or the second condition is true
- ' OrElse checks if the first condition is true, if its false then checks the second condition
- '
- ' 5 - Loops
- ' While statement
- ' while statements are executed while the condition its true
- ' example:
- ' Dim myVar as in16
- ' myVar = 1
- ' while myVar < 11
- ' myVar += 1
- ' end while
- ' to force a while to break his execution we use Exit While, example:
- ' while myVar < 11
- ' myVar += 1
- '
- ' if myVar = 5 then Exit While
- ' end while
- '
- ' 6 - For statement
- ' an For its used in cases were we know the start and the end of the loop
- ' example:
- ' Dim myVar as int16
- ' For myVar = 1 to 10
- ' 'do something
- ' Next
- ' we can declare the variable in the For statement:
- ' For myVar as int16 = 1 to 10
- ' ' do something
- ' Next
- ' we can use it with list of objects:
- ' for each p as Ped in World.GetPeds(Player.Character.Position, 5.0)
- ' ' do somethiong
- ' if p <> player.character then p.isragdoll = true
- ' next
- '
- ' 7 - "Game Objects"
- ' When i say "Game objects" i refer to objects that is in the game and can be controlled like Pedestrians, Vehicles, Camera, etc
- ' for example we have the Ped, the Ped is all the people on the streets including the player, the Ped has some properties like Health, Direction, isAlive, Velocity
- ' and some Methods like ApplyForce, Die, WarpIntoVehicle
- ' get the values of properties and the values returned by the methods and set properties values and call some methods is basically what we need to do to make things happen
- ' for example if i wanna heal the player i do this:
- ' Player.Character.Health = 100
- ' done, the Ped that represents the Player (Character) is now with 100 "points" of health
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement