Thursday, February 28, 2013

[TUT-IV] Basic tools to script

To help we implement scripts for GTA iV we need some tools/links, the most important in my opinion are:

The scripthook help file: Through this help file we can have easy access to any .net scripthook object and see their properties and methods, the parameters needed and some basic info about the behavior.

The Microsoft Visual Basic: What about an program to help us insert the code showing list of objects, methods and parameters? Yeah, Visual Studio will help a lot in the script develop, and we can test the compilation before trying it in the game.

  • You can download an free version here or here.

The GTA Modding sites: Very useful pages listing game native functions, animations, particle effects, models, etc.. Add in your Bookmarks, you will need it ^^

  • List of native functions: List of game native functions, great part of them with parameters specification and description of the effect/result.

  • List of models: List of game models, vehicles, pedestrians, objects, weapons, all...

  • List of animations: List of game animations, here we can find all game animations and play it with the pedestrians.

  • List of particle effects: List of all particle effects like fire effects, water effects, bullet hit, blood splash, explosions, etc..

Open IV or Spark IV: With those programs we can search and preview game models, extract and replace them, the same we can do about textures and sounds, also we can extract or replace animations, very useful when you need to search for some model to use in your script.
  • Download Open IV here
  • Download Spark IV here

Decompiled scripts: This is pure gold, we can see how they use some methods with those files, it's very interesting to find how to use an method, you need some luck and logic to identify the params (if they are not listed at the list of native functions) but it's not so hard.

For example let's say that we wanna see how to use this method: PLAY_SOUND_FROM_PED
This method has no info in the wiki (list of native func.) but we can search into the decompiled files and find something like this:

PLAY_SOUND_FROM_PED( l_U375, "E1_RB2_SCREAM", l_U697[2] );

First param is a variable, we search for this variable and see his type:

l_U375 = GET_SOUND_ID(); - based on what we know about get_sound_id, this variable can be one integer. And based on what this variable is receiving we notice that it's an sound id, and it's the first param of the native call (play_sound_f...)

Now we look at next param, it's a string: "E1_RB2_SCREAM", based on method name we can imagine that this is the sound name.

Now the last param: l_U697[2], this is an array (because of the [ and ]) and based on the method name (that ends with from_ped) we can imagine that it is a Ped id, like the return of Player.Character.

So if we do this on

Native.Function.Call("PLAY_SOUND_FROM_PED", -1, "E1_RB2_SCREAM", Player.Character)

we probably will hear a sound, but you must pay attention from what folder this decompiled script is, some scripts uses methods and names of particle effects, sounds or whatever from a specific game version (GTA IV or EFLC), some methods will work only in EFLC. To make sure test in both before give up :)

Basicaly those are the main tools/sites that i use as reference/source when coding scripts for GTA iV, in next tutorial i will show how to start an new script in visual basic and show some basic scripting ideas.

Download the sample project here,

Tuesday, February 26, 2013

[TIP-IV] Basic scripting - Script structure and main events [GTA IV]

Considering that you know the basic of programming (what is variable, object, methods, loops, conditions, etc.) i will start showing the basic script structure and the main events that are very usefull when creating an script.

  • Imports area: here we will declare the additional libraries/classes/whatever its called things that we will need in the script, the basic is:

Imports System
Imports GTA

another interesting imports are:

Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections.Generic
Imports System.IO

  • Class header: here the main class starts, here we can set the name of the script that will appear in the console window when the script is loaded

Public Class myBasicScript
    Inherits Script

  • Variables/Constants/Classes/Enumerations area: here we can declare the variables that we will need along the script, also declare classes, constants:

Private bScriptOn As Boolean = False
Private sMessage As string

Private Class TDarts
        Public dart As GTA.Object = Nothing
        Public launched As Boolean = False
        Public target As Ped = Nothing
end class

  • Then comes the "event" that will happen when the script is loaded by the scripthook:

Sub New()
       me.Interval = 10

       sMessage = "Script loaded :)"
end sub

Here we can initiate variables/objects, load textures, sounds, whatever you need to do only one time in the script execution.

  • The keydown event: this event will happen 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 example you can use "k As GTA.KeyEventArgs" instead of "e As GTA.KeyEventArgs",  through this we can identify what key was pressed through the element e.Key, for example, if we wish to identify when user press key "A":

Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
        if e.key = keys.A then 
        end if
end sub

the keyUp event has the same parameters and will happen 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 happen 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

through element Command we can identify the command typed by the user, and through the element ParameterCount we can see if there is parameters in the command and through element Parameter we can read the parameters, they are inside the object cmd:

Private Sub console_CMD(ByVal sender As Object, ByVal cmd  s ConsoleEventArgs) Handles MyBase.ConsoleCommand
        If cmd.Command = "die" Then
            If cmd.ParameterCount > 0 Then
                If cmd.Parameter(0).ToLower = "now" Then
                ElseIf Int16.Parse(cmd.Parameter(0)) > 0 Then
                End If
            End If
        End If
 End Sub

through method 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 event: this happen each X miliseconds, based on variable me.Interval:

Private Sub general_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick

for example, if we want to heal player life every 10 miliseconds (me.Interval):

Private Sub general_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick += 1
end sub

  • PerFrameDrawing event: this will happen at each frame of the game, you must be carefull when using this event

Private Sub GraphicsEventHandler(ByVal sender As Object, ByVal g As GTA.GraphicsEventArgs) Handles MyBase.PerFrameDrawing

through 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", 10, 10)
' draw the text starting at 10, 10 (X, Y screen position)

        e.Graphics.DrawLine(10, 20, 100, 20, 1, Color.Red)
' draw an line starting at 10, 20, ending at 100, 20, with 1of width and red color

        e.Graphics.DrawRectangle(100, 100, 200, 200, color.FromArgb(100, 255, 255, 255))
' draw an rectangle with center at 100, 100, with 200 of width, 200 of height and with semi transparent white color

        e.Graphics.DrawSprite(textureTest, 300, 300, 100, 100, 0)
' draw an texture with center at 300, 300, with 100 of widht, 100 of height and 0 of rotation
end sub

an additional method that i like to use when developing 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, very usefull to see variable values

  • the main Class ending: here the main class of the script ends

End Class

an important thing about the events is the text "Handles", this part will determine what the event will handle, for example:

Handles MyBase.KeyDown
Handles MyBase.KeyUp
Handles MyBase.ConsoleCommand
Handles MyBase.PerFrameDrawing

another important part is the element that will receive the events methods/properties, for example, here we used:

e As GTA.KeyEventArgs in the keydown event
cmd  As ConsoleEventArgs in the console event
e As GTA.GraphicsEventArgs in the PerFrameDrawing

you can download an sample script here.

Saturday, February 23, 2013

[Script] Simple car fly cheat

This was requested by taltigolt but i think that he didnt liked the result hehe

This script tryes to recreate San Andreas fly cheat for cars, the big problem is control the flight, i tryed a lot of ideas but my results was always bad, with some practice you can fly very well.

Download: GTA 4 Mods

The idea is simple:

Use the native function SET_CAR_FORWARD_SPEED to control the forward speed of the car, and apply force in the right directions and rotations to make it go Up/Down/Left/Right/Roll Leftt/Roll Right, the big issue is when you hit anything and the vehicle start spinning, its hard to stop. I have some ideas here that i didnt used in this script, maybe i can improve it and make it flyes better :)

[Script] Javelin/Stinger rocket lock

Started based on Modern Warfare 2 Javelin behavior and modified until reachs an behavior similar to real Javelin launchers, this was an interesting and, at same time, hard to do script. Requested by GoldenDarknezz, this script allows you to lock rockets on vehicles or ground and shoot with TOP attack or DIR (Direct? probably) attack mode, also have nightvision effect :)

Download: GTA 4 Mods

You can change to Stinger mode too (based on MW2 Stinger behavior)

The Nightvision effect its very cool and gives an real impression of nightvision if the objects are away and you are looking from a high position, this idea i used first in AC-130 script, but with an different way to make it work because in AC-130 we always look from high position and this makes it require less tricks to work properly.

The idea is:

-Draw an green rectangle in the entire screen with reduced alpha value
-List peds/vehicles (targets)
-Put Green lights between each target and the camera, for vehicels we need more lights to fill the vehicle surface, for example, an Bus needs four lights, an taxi car needs two
-Move the lights with the objects considering camera position too, the light will be always one or more steps in front of object

Seems to be simple? Yep, but its not hehe.

[Script] Air Combat IV (AC-IV)

This script makes possible to spawn Jets with custom number of engines, flaps/elevators, gears, cannons, rockets with lock on target feature, bombs and flares. Also you can spawn enemies in jets to combat

Download: GTA 4 Mods

This one im really proud of, really complex script, started with an request of CORE.MAX2010 to create engine fire and jet sound for jets, when i finished this task i tested the idea of using AI drivers in jets and worked very well, then the real complex script started.

To control the jet:
W (accel.)
S (desaccel.)
A (or numpad 4)
D (or numpad 6)
Shift (or numpad 8)
Control (or numpad 5)
numpad 7 - turn left
numpad 9 - turn right
X - Switch cam
Right click - Follow missile/bomb with camera
Space shoot missiles
Numpad0 - Shoot cannon
Q - Drop bomb
E - Release flare to avoid missiles (hold to release one by one)
F - Enter Jet / Exit Jet / Eject (if flying)
Left/Right help "drive" the jet while in the ground
0 - Spawn menu
Enter - Spawn select Jet in spawn menu, hold shift to spawn and start flying
2 - Spawn enemy
3 - Spawn fugitive
When on ground:
Left/Right (or numpads 7/9) - turn left or right
S - Break

XBox 360 controller controls:
Hold left and right Shoulders to see/hide jet spawn menu, use A to spawn on air or use X to spawn on ground
A - Shoot rockets
X - Shoot cannon
Y - Release flares
DPad Down - Drop bombs
B - Eject/Exit/Enter jet
Left Thumb stick - Pitch and Roll
Left/Right Shoulder - Turn left or right
Left Trigger - slow down
Right Trigger - Accelerate

In this one i used a lot of custom classes to be used in lists, this helped a lot and make the script more easy to modify.

You can have one list of jets to spawn, each one with custom configuration for weapons, engines, flaps, etc

Also its possible to set jet spawn/aquirement points

To create the rocket lock feature i must list the possible targets in a list of vehicles, then use this calc to see if the object is close to center of aiming position:

Dim tmpDist As Double = v.Position.DistanceTo(Game.CurrentCamera.Position)
Dim tmpPos As Vector3 = Game.CurrentCamera.Position + Game.CurrentCamera.Direction * tmpDist

If v.Position.DistanceTo(tmpPos) < (tmpDist / 3) Then

' mark the vehicle as an locked target...
end if

obs.: "v" is one vehicle in the possible targets list

The use of classes made easy to make the enemy jets do the same rocket lock on the player and control they flight

[Script] AC-130

This script, as many ideas, started with simple ideas, actually me and TheVideoVolcano was talking about scripts, he was asking how to do things, and he asked me if i can create one script to make an air attack, like call one stealth bomber to fly over the city and launch some bombs in a waypoint, then the name AC-130 came out.

I played Modern Warfare 2 multiplayer a lot, so i knew something about the AC-130 features (at least in MW2 game), so i started the development trying to recreate MW2's AC-130 features.

First i made an custom camera and made it fly over city, just going always in same direction, when press A or D the direction change, and after some tests i figured out that the cars and peds are only loaded by the game in an region close to player position, so i did  a litle trick: move the player with the camera hehe.

Download: GTA 4 Mods

First weapon was the .105mm:

Very powerfull, i used one rocket model (cj_rpg_rocket) that is launched from an position close to camera position, applied the same rocket particle effect used by the game, and used the native function
SET_OBJECT_RECORDS_COLLISIONS and HAS_OBJECT_COLLIDED_WITH_ANYTHING to identify when the rocket collided with anything, and when it happens i detect peds and cars surround rocket position and push them away, also use an explosion particle effect with increased size

Second weapon as .40mm, this one was composed by ten objects, i throw then one by one and do the same that i did with .105 to detect collision, then add an litle explosion in the collision position, also i move the camera in the direction of ground to simulate an zoom in

Third was the .20mm, just using FIRE_SINGLE_BULLET to shoot bullets against the ground and used graphics draw event to draw an fake bullet trace, i did this because the particle effect for bullet trace dont work well sometimes

One of the most interesting ideas that i had in this script was the train derail, when the .105 collision detects an train (that is an object of type gta.vehicle) i get info about the train position, rotation and speed, then delete the original and create an fake train, put in same place, same rotation and same speed, then apply force to it pushing away :)

Also i created an ground control system, using an fake binocular you can aim at peds, vehicles or ground and call an attack of .105, .40 or .20mm gun, its very interesting and more fun than the normal attack mode:

[Script] Fus Ro Dah power

This was another user request, its simple, detect pedestrians, objects and cars in front of player then push then away from player.

Download: here

When the user press the hotkey i play the intial sound ("Fus") and while the hotkey is down the amount of push force its increased.
When release the hotkey the player do an animation moving his head backward, when animation finish i detect the game objects and push them away and play the last sound ("Ro Dah")

To create some visual effect i draw one rectangle in entire screen and reduce its Alpha value until zero very fast, causing the impression of an flash, also i use one particle effect, an smoke, the idea its make it similar to wind effect

[Script] Simple wall ride

This script was requested by Ghost rider users, they want the wall ride feature available for any vehicle, so i did. Very simple script, the idea is get the car direction while its on ground, then activate the effect pushing the car up and rotating it to make it touch the wheels on the wall, then apply some force in the direction saved (the one saved when car was on ground) and apply some force up to avoid the possible fall of the car, when user accelerates the car just drive on the wall hehe:

Source/Download: GTA 4 Mods

Iron Man IV [W.I.P.]

This is my actual work in progress: Iron Man IV script requested by original Iron Man's script creator: H1Vltg3
This will be a very nice script

*** The script was released, take a look here ***

Actual features:

Darts (or mini rockets, idk ^^)
Rocket lock
Repulsor beam


Create enemies with good weapons, like rockets and vehicles with mounted guns
Maybe create an flying enemy, i say maybe because it should be very hard
Fix some problems ^^

Friday, February 22, 2013

[Script] Ghost rider - GTA iV

My second script, this one was hard, 3480 lines of code :P, requested by GEL06, models by wapeddel and Quechus09



Read the readme.txt that goes with the mod

this time using particle effects (flames on head, bike and chain for example), playing .wav files, using ped animations...

the most complicated part was make the chain weapon work properly, the chain is composed by 10 chain pieces, each one is an model with 4 chain links (created by wapeddel):

 i used ATTACH_OBJECT_TO_OBJECT_PHYSICALLY  to attach each chain piece to the previous one and used the property velocity of the chain objects to help the attach method to keep they attached, in the tick i was always trying to move the chains to the attach position

 this give the impression of an real chain:

when moving the chain to attack peds or vehicles or just to make the player "climb" to the top of buildings, i just move the last chain object and the other chain pieces follow it because of the attach method used and the velocity changed in the tick

another interesting idea that i created for this script was the "Wall ride" feature, with this feature we can ride the bike on walls (or any 4 wheel vehicle if the option is set in the .ini file), reaching the top of the buildings

Another features:

Penance stare
Super strength
Super shotgun (super impact + fire)
Spit Fire (like in second movie)
Throw flames with mouth
"Water ride" (ride the bike on the sea)
Spawn bike
Auto heal
Slow motion when using shotgun

[Script] myTelekinesis powers

My first script: myTelekinesis Powers, all started making modifications on an open source script, unfortunatelly i cant remember the author's name now:

Source code: here

Very basic script without animations, particle effects, sprites, nothing, just normal game animations and explosions, if i recreate this script today it will be a lot better considering animations, particle effects and all other stuff that i learned how to use.

How works:

Hold Aim key and press the skill key:

  Skill Key 1: Throw targeted ped/vehicle automatically
  Skill Key 2: Put ped/vehicle to float
  Skill Key 3: Throw floating things into a target
  Skill Key 4: Warp into targeted vehicle
  Skill Key 5: Hold to see the target, release to warp to targeted floor/ceil/whatever
  Skill Key 6: Warp to waypoint, this don't need the Aim key pressed
  Switch the float mode press Tab

Its funny, make things float them throw then, make the player fly to targeted car or ground position, very usefull to make player go to top of buildings ^^
//propaganda YT float style='display:none;'