Advertisement
julioCCs

BasicScript.vb

Oct 16th, 2012
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.57 KB | None | 0 0
  1. 'http://www.facebook.com/GtaIVScripting
  2. 'https://www.youtube.com/user/GTAScripting
  3.  
  4. ' ############### this is a basic vb.net script, with this you can handle some important events like KeyPress and Tick #################
  5.  
  6. ' 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
  7. Imports System ' basic imports
  8. Imports GTA ' basic imports
  9. Imports System.Windows.Forms ' needed to have access to "keys" enumeration, for example
  10. Imports System.Drawing ' needed to handle colors referencing the color name, ex: myCar.color = System.Drawing.Color.Black
  11.  
  12. Public Class BasicScript
  13.     Inherits Script
  14.    
  15.     ' good place to declare some global variables
  16.     private myPed as ped
  17.     private myCar as vehicle
  18.    
  19.     ' the following method is called when the script is loaded by the scripthook
  20.     ' you can use it to set default values, load .ini configs, etc
  21.     Public Sub New()
  22.         Me.interval = 10 ' the script interval for "tick" events
  23.     End Sub
  24.    
  25.     ' this method just make easier to print a msg on the screen
  26.     private sub msg(sMsg as string, time as int32)
  27.         Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", sMsg, time, 1)
  28.         ' Native.Function.Call executes an gta native function, in this example it calls PRINT_STRING_WITH_LITERAL_STRING_NOW
  29.         ' "STRING", sMsg, time, 1 are the parameters of the function
  30.     end sub
  31.    
  32.     ' this is an event, when the player press one key, this is called and you can see what key is pressed
  33.     Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
  34.         ' how to discover what key was pressed? simple:
  35.         if (e.key = keys.mbutton) then
  36.         end if
  37.         ' other example
  38.         if (e.key = keys.Q) then
  39.         end if
  40.     End Sub
  41.     Private Sub keyUp(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyUp
  42.         ' this can be used when you need to activate the hotkey only when the user releases the key
  43.     end sub
  44.    
  45.     ' this is an Tick event, this will be called each 10 milliseconds (me.interval), lag can cause delay
  46.     Private Sub general_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
  47.     end sub
  48. End Class
  49.  
  50. ' ###########################################################################################################################
  51.  
  52. ' now the basic programming explanations...
  53. ' the lines above represents a very basic script, with this you can start creating scripts
  54. ' but first there are some important things that must be understood
  55.  
  56. ' 1 - Variables
  57. ' basically you will use two forms to declare variables:
  58. '   Private myGlobalVar as myVarType
  59. '   Dim myLocalVar as myVarType
  60. ' Private means that the variable will be available in the whole script
  61. ' Dim means that the variable will be available in the current block/statement
  62. ' myVarType is the type of the variable, for example,
  63. '  Int32 that are integer numbers (-2, -3, 0, 1, 5, 999999)
  64. '  Double that os a floting point variable (0.2, 0, -1.5, 12, 15.5664)
  65. '  String that is a string ("Test")
  66. '  Ped that is a game object, it represents a Pedestrian, basically all the peds on streets
  67. ' obs.: Variable names must be unique
  68. ' 2 - Methods
  69. ' methods are "blocks os codes" that help do something an make the script easy to read and to fix
  70. ' methods can return values or not
  71. ' an method that return value is a Function, the one that does not return a value is a Sub
  72. ' to declare a method we do the following:
  73. '   Private Sub MySubMethod
  74. '   end sub
  75. ' where MySubMethod is the name of the method
  76. ' for Function its almost the same:
  77. '   Private Function MyFuncMethod
  78. '       Return AnyThing
  79. '   end Function
  80. ' when we call the Return in a Function, the execution of the method stops at that point and returns the especified value
  81. ' methods can receive parameters too, example:
  82. '   Private Function MyFuncMethod(p1 as int32, p2 as double)
  83. '       Return p1 * p2
  84. '   end Function
  85. ' example of use:
  86. '  
  87. '   Private Sub keyUp(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyUp
  88. '       if e.key = keys.O then Test1
  89. '
  90. '       if e.key = keys.P then Test2(125)  
  91. '   end sub
  92. '
  93. '   Private Sub Test1
  94. '   end sub
  95. '
  96. '   Private Function Test2(pParam as int16)
  97. '       return pParam / 2
  98. '   end Function
  99. '
  100. ' 3 - Conditions
  101. ' an condition checks if somthing is True, then do something, if not true do "elsething"
  102. ' example:
  103. '       if myVar = 1 then
  104. '           ' do something
  105. '       else
  106. '           ' do "elsething"
  107. '       end if
  108. ' other example, without else statement:
  109. '       if (myVar > 1) andalso (myVar < 5) then
  110. '           ' do something
  111. '       end if
  112. ' if there is only one thing to do we can use it on a single line:
  113. '       if myVar > 1 then myVar = 0
  114. '
  115. ' 4 - Condition operators
  116. ' basically we use: And, AndAlso, Or, OrElse:
  117. '   And checks if the first condition And the second condition is true
  118. '   AndAlso checks if the first condition is true, if its true then checks the second condition
  119. '   Or checks if the first condition Or the second condition is true
  120. '   OrElse checks if the first condition is true, if its false then checks the second condition
  121. '
  122. ' 5 - Loops
  123. ' While statement
  124. ' while statements are executed while the condition its true
  125. ' example:
  126. '   Dim myVar as in16
  127. '   myVar = 1
  128. '   while myVar < 11
  129. '       myVar += 1
  130. '   end while
  131. ' to force a while to break his execution we use Exit While, example:
  132. '   while myVar < 11
  133. '       myVar += 1
  134. '
  135. '       if myVar = 5 then Exit While
  136. '   end while
  137. '
  138. ' 6 - For statement
  139. ' an For its used in cases were we know the start and the end of the loop
  140. ' example:
  141. '   Dim myVar as int16
  142. '   For myVar = 1 to 10
  143. '       'do something
  144. '   Next
  145. ' we can declare the variable in the For statement:
  146. '   For myVar as int16 = 1 to 10
  147. '       ' do something
  148. '   Next
  149. ' we can use it with list of objects:
  150. '   for each p as Ped in World.GetPeds(Player.Character.Position, 5.0)
  151. '       ' do somethiong
  152. '       if p <> player.character then p.isragdoll = true
  153. '   next
  154. '
  155. ' 7 - "Game Objects"
  156. ' When i say "Game objects" i refer to objects that is in the game and can be controlled like Pedestrians, Vehicles, Camera, etc
  157. ' 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
  158. ' and some Methods like ApplyForce, Die, WarpIntoVehicle
  159. ' 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
  160. ' for example if i wanna heal the player i do this:
  161. ' Player.Character.Health = 100
  162. ' 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