Quantcast

Jump to content

» «
Photo

Scripting Guide with Visual Basic 2008

8 replies to this topic
Ferna_22
  • Ferna_22

    Punk-ass Bitch

  • Members
  • Joined: 30 Dec 2008

#1

Posted 01 April 2009 - 07:54 PM

First of all we have to download Visual Basic 2008, it´s free, we only need to make a free account because it´s a 30 days trial, Download it here...

Visual Basic is the simpliest way to programme, well, at least for me lol.gif ...

We need .NET Script Hook too, Download it here ...

1) Making the scripts work:

To call the scripts in game we´ve got 3 easy ways to do it (There are more, but these are the easiest): Using a Key, Using the Cell Phone or by the Console (Press "Ñ" to make the console appear)...

Using a key(in this case I´ll use "Y" to call my Script):
CODE
Public Class MyScript
   Inherits Script
   Public Sub New()
       BindKey(keys.Y, AddressOf ScriptName)
   End Sub

   Public Sub ScriptName()
'Here Goes Our Script Code...
   End Sub
End Class


Using the Cell Phone(in this case I´ll use the number "1805" to call my Script, we can use letters, too):
CODE
Public Class MyScript
   Inherits Script
   Public Sub New()
       BindPhoneNumber("1805", AddressOf ScriptName)
   End Sub

   Public Sub ScriptName()
'Here Goes Our Script Code...
   End Sub
End Class


Using the Console(in this case I´ll use the word "My Script 2009" to call my Script):
CODE
Public Class MyScript
   Inherits Script
   Public Sub New()
BindConsoleCommand("My Script 2009", AddressOf ScriptName)
   End Sub

   Public Sub ScriptName()
'Here Goes Our Script Code...
   End Sub
End Class


2) Adding Comments to our Script Codes:

If you want to share your Scripts or just remember what is each part of the Script, we can add a " ' " at the start of the comment, all the things written with a ' at the start will be ignored by the Game/Application, it´s just for comment, instruction, etc...

For Example:
CODE
Public Class MyScript
   Inherits Script
   Public Sub New()
BindConsoleCommand("Tell me Hello", AddressOf MessageDisplayExample)
   End Sub

   Public Sub MessageDisplayExample()
'When you write "Tell me Hello" (without the quotes), in the console, the game will display a message saying "Hello"...
Game.DisplayText("Hello")
   End Sub
End Class


If you add the "'" at the start, the ignored test will change the color to green (In VB, because in the game it will be white)...

3) Using "Private" and "Dim":

When you name an object, action, number, etc. we have to declare what kind of thing it is, here you´ve got some examples:
CODE
Public Class MyScript
   Inherits Script
   Private PedestrianX As Ped
   Public Sub New()
       BindKey(keys.H, AddressOf PedKiller)
   End Sub

   Public Sub MessageDisplayExample()
'When you press "H" the closest ped in 5 meters will die...
Pedestrian = World.GetClosestPed(Player.Character.Position, 5.0F)
       If Exists(Pedestrian) Then
           Pedestrian.Die()
       End If
   End Sub
End Class


"Dim" is used for the same reason, but it´s written inside the Script, I mean, for example above "Pedestrian =..."...

4) Using "If":

"If" is used to make a condition, it works to call a Script, too:

Condition Example:
CODE
Public Class MyScript
   Inherits Script
   Public Sub New()
       BindKey(keys.NumPad0, AddressOf ConditionExample)
   End Sub

   Public Sub ConditionExample()
'When you press "0" in the NumPad, and if player´s health is less or equals 10, the game will display a text saying "You are dying!!!"...
       If Player.Character.Health <= 10 Then
           Game.DisplayText("You are dying!!!")
       End If
   End Sub
End Class


Calling a Script Example:
CODE
Public Class MyScript
   Inherits Script

   Public Sub New()
   End Sub

   Private Sub CallingScriptExample(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
       'When you press "0" in the NumPad, and if player´s health is less or equals 25, the game will display a text saying "You are dying!!!"...
       If isKeyPressed(Keys.NumPad0) Then
           If Player.Character.Health <= 25 Then
               Game.DisplayText("You are dying!!!")
           End If
       End If
   End Sub
End Class


5) Using Arithmetic Operators:

Operators allow us to operate, validate, compare, assign, distinguish, etc ...

These operators allow us to work with mathematical calculations like addition (+), subtraction (-), division (/) and multiplication (*)...

Operations Example:
CODE
Public Class MyScript
   Inherits Script

         Private MoneyX As Integer = ((150 * 3) / 25) + (5 - 3)

   Public Sub New()
       BindKey(keys.NumPad8, AddressOf OperationsScriptExample)
   End Sub

   Public Sub OperationsScriptExample()
'When you press "8" in the NumPad, you will earn the result of MoneyX...
Player.Money += MoneyX
           Game.DisplayText("you earned " & MoneyX & " dollars")
   End Sub
End Class


6) Using Comparison Operators:

Comparison Operators are used to compare expressions, the most used Comparison Operators are: Equals (=), Less than (<), Bigger than (>), Less or equals(<=), Bigger or equals (>=), Different than (<>), for example:

In this case i will compare player´s money:
CODE
Public Class MyScript
   Inherits Script

  Public Sub New()
     Me.Interval = 3000 ' Interval is the time between two Ticks (in milliseconds)
  End Sub

   Private Sub ComparisonExample(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
       'When your money is less or equals 2000, the game will display every 3 seconds a text saying "You're getting poor!!!"...
       If Player.Money <= 2000 Then
           Game.DisplayText("You're getting poor!!!")
       End If
   End Sub
End Class


7) Using the Concatenation Operator:

The Concatenation operator is used to join 2 members, for example:

In this case I will join 3 different results:
CODE
Public Class MyScript
   Inherits Script

   Private X As Integer = 15 * 3
   Private Y As Integer = 40 / 2
   Private Z As Integer = (18 * 3) + 1
   Private ResultX As Integer = X + Y + Z

   Public Sub New()
   End Sub

   Private Sub ConcatenationExample(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
       'When you press "F1" the game will display a text saying the 3 results of the operations under this description, and after 2 seconds, will display the result of the sum of the 3...
       If isKeyPressed(Keys.F1) Then
           Game.DisplayText(X & " + " & Y & " + " & Z & " = ")
           Wait(2000)
           Game.DisplayText(ResultX)
       End If
   End Sub
End Class


8) Using "And" and "Or":

"And" and "Or" are used to return expressions of type True or False, for example:

In this case I will use "And" to link 2 "If"s:

Now I will use the same example with "Or":
CODE
Public Class MyScript
   Inherits Script

   Public Sub New()
       Me.Interval = 3000 ' Interval is the time between two Ticks (in milliseconds)
   End Sub

   Private Sub OrExample(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
       'When your money is less or equals 2000, or if your health is less than 30, the game will display every 3 seconds a text saying "You're getting poor or you are dying!!!"...
       If Player.Money <= 2000 Or Player.Character.Health <= 30 Then
           Game.DisplayText("You're getting poor or you are dying!!!")
       End If
   End Sub
End Class


9) Using Random:

Random is used to make the game select random number between two values, for example:

In this case I will Random to change my Health:

CODE
Public Class MyScript
   Inherits Script

   Private RandomX As New Random(DateTime.Now.Millisecond)

   Public Sub New()
       Me.Interval = 1000 ' Interval is the time between two Ticks (in milliseconds)
   End Sub

   Private Sub RandomExample(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
       'If you press F8, the game will change your actual health to a number between 10 and 100...
       If isKeyPressed(Keys.F8) Then
           Player.Character.Health = RandomX.Next(10, 100)
       End If
   End Sub
End Class


10) Adding Sound to our Scripts:

It´s an easy function and it´s innovative because I didn´t see any script with extra sounds, except mine:

Adding a External Sound example:
CODE
Public Class MyScript
   Inherits Script

   Public Sub New()
       Me.Interval = 3000 ' Interval is the time between two Ticks (in milliseconds)
   End Sub

   Private Sub ExternalSoundExample(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
       'When your health is less or equals 30, the game will play a sound every 3 seconds...
       If Player.Character.Health <= 30 Then
           My.Computer.Audio.Play("C:\My_Sounds\Sound3.wav") 'Between the quotes you must write the path, you can only use .wav files...
       End If
   End Sub
End Class


If you don´t understand something tell me it smile.gif ...

rootman
  • rootman

    Rat

  • Members
  • Joined: 18 Jun 2004

#2

Posted 19 May 2009 - 04:32 AM

hey man pretty cool vb 2008 tutorial, its not often to see some scripting done in other languages like vb 2008. id love to see and read more of your tutorials for using vb 2008 for gtaiv, as im very unconfident about using c++ style coding, even tho im studying a course on it and let me tell you, its very complex hehehe. least vb is right up my ally, i can make splash screens and make some programs calculate stuff and all that basic s**t. ive even made a rock paper sissors game, smile.gif

anyway keep up the good work ferna. if you could, can you make more code used for vb 2008 useful for gtaiv? looking forward to some more vb related stuff from you. gimme a buzz!!

Ferna_22
  • Ferna_22

    Punk-ass Bitch

  • Members
  • Joined: 30 Dec 2008

#3

Posted 19 May 2009 - 11:22 PM

Well, I´m glad to hear this tutorial helps you...

I will send you a PM if I update the guide...

I use VB because it´s the only languaje that I can handle (I used to use Action Script in Flash, but I´m not as good as in VB, anyway AS is not a very optimized languaje, I mean, some simple games run slow in AS).

I tried C# but it´s harder than VB, I don´t know how to compile a project in C lol.gif ...

rootman
  • rootman

    Rat

  • Members
  • Joined: 18 Jun 2004

#4

Posted 20 May 2009 - 02:05 AM Edited by rootman, 20 May 2009 - 02:16 AM.

so what's flash like to use ferna? im looking to get into other coding methods other than c++ as im all for other alternatives for making code. do you know any vb related websites that you may think of that is to do with vb 2008? i could do with a few links if you know any.

oh and your english is ok not that bad hehe. have u ever done any mission coding in vb 2008 for gtaiv, can that be done?

oh and was wondering, im looking to make a program that lets you hear all the dialogue of all the characters in gtaiv and wanna make it in vb 2008, yeh i know its nothing gamey about it but just for fun and knowledge purposes as well. i was wondering if you could make a tutorial of that kinda thing regarding adding all dialogue sounds from all characters and putting it into a vb program that i could make so i can select which character and hear all dialogue from that person and what i was hoping to do was be able to select any dialogue spoken not just from niko but also from everyone including the pedestrians in all of liberty city. yes i know what youre thinking, thats too full on. hopefully if you are up to it you could help make that kinda tutorial so that i could make it.

Ferna_22
  • Ferna_22

    Punk-ass Bitch

  • Members
  • Joined: 30 Dec 2008

#5

Posted 20 May 2009 - 03:58 PM

QUOTE
so what's flash like to use?

It´s not very hard to use, and it works directly associated with Flash graphics, but it isn´t compatible with 3D as far as I know...

QUOTE
do you know any vb related websites that you may think of that is to do with vb 2008?

To learn the functions and some more technical information about VB follow this link...

QUOTE
have u ever done any mission coding in vb 2008 for gtaiv, can that be done?

I wrote a script that transports niko to a rooftop and some enemies are spawned, too, and they try to kill you with their hands, I didn´t post this script...

I wrote other script that makes you fight against Johnny, I published it...

QUOTE
im looking to make a program that lets you hear all the dialogue of all the characters

I didn´t try to use sounds directly from the game, but there is a command that was made for it...

CODE
       GTA.Game.PlayGameSound("SoundName As String")

rootman
  • rootman

    Rat

  • Members
  • Joined: 18 Jun 2004

#6

Posted 20 May 2009 - 10:31 PM

cool, ill keep that code bit in mind. thx again. hope to read more tutorials from you. if there's more script stuff you made in vb 2008 for gtaiv have em here.

gtaivEflc
  • gtaivEflc

    Player Hater

  • Members
  • Joined: 01 Nov 2011

#7

Posted 01 November 2011 - 09:42 AM

How to play sound like "DISPATCHING_TO" (eflc) (pc/audio/sfx/police_scanner.rpf/DISPATCH_TO.ivaud/DISPATCH_TO)?

gtaivEflc
  • gtaivEflc

    Player Hater

  • Members
  • Joined: 01 Nov 2011

#8

Posted 01 November 2011 - 11:49 AM

And if:

Dim hellicopter as Vehicle
hellicopter = World.CreateVehicle(Model.FromString("Polmav"), Player.Characher.Position.Around(1))
Dim driver as Ped = hellicopter.CreatePedOnSeat(VehicleSeat.Driver)
Player.Characher.WarpIntoVehicle(hellicopter, VehicleSeat.RightFront)
driver.Task.*** 'What task can I give for driver fly chopper?

froggz19
  • froggz19

    Player Hater

  • Members
  • Joined: 25 Jul 2006

#9

Posted 09 November 2012 - 04:23 AM

Could you help me to create a vb script?

I want to lock/unlock the car doors remotely, after locking the doors, set alarm and when a ped is trying to steal the car alarm will start.

I can't create a script from start, I managed to edit some vb scripts but nothing more ...

An example of a lock/unlock script but this works only if the player is in vehicle.

CODE
Public Class LockPick
Inherits Script

Public vehlockveh As Vehicle

Public Sub New()
Interval = 1500
End Sub

Private Sub LockPick(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
If e.Key = Keys.L Then
If Player.Character.isInVehicle Then
carlock()
End If
End If
End Sub
Private Sub carlock()
If ((Player.Character.CurrentVehicle.Model.isHelicopter Or Player.Character.CurrentVehicle.Model.isCar) And Player.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.Driver) = Player.Character) Then
If Not Player.Character.CurrentVehicle.DoorLock = DoorLock.None Then
Player.Character.CurrentVehicle.DoorLock = DoorLock.None
My.Computer.Audio.Play(Game.InstallFolder & "\scripts\LockPick\audio\unlock.wav")
Game.DisplayText("Doors open", 1000)
Else
Player.Character.CurrentVehicle.DoorLock = DoorLock.ImpossibleToOpen
My.Computer.Audio.Play(Game.InstallFolder & "\scripts\LockPick\audio\lock.wav")
Game.DisplayText("Doors locked!", 1000)
vehlockveh = Player.Character.CurrentVehicle
End If
End If
End Sub


Thank you!




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users