Sunday, 17 March 2013

[Script] Air Combat IV v1.5 - XBox 360 Controller support


Air combat IV v1.5

Added XBox control support
Added skin (livery) change, you can change ingame using Subtract key (numpad) or in the .ini of the jet or acquirement point
Some small fixes

XBox 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

I believe that this config its cool to play :)

DLL Microsoft.Xna.Framework.dll MUST be inside gtaiv.exe or the game will crash, maybe you need to install this packet:
http://www.microsoft.com/en-us/download/details.aspx?id=20914

Download:

GTA 4 Mods
or
GTA Garage
or
MOD Db



News for jet model developers:

Now we have an vehicle extra auto toggle to be used when firing guns, you can set them in the jet_....ini file, this is the config:


[extra_0]    <-- category that goes from 0 to 4, so we have five extra available
extraID=0   <-- ID of the extra in the car
initiallyEnabled=-1   <-- if will start On/Off
activateWhenFireCannon=1   <-- if will be toggled when firing cannon...
activateWhenFireRocket=-1   <-- ...rocket
activateWhenFireBomb=-1   <-- ...bomb
activateWhenReleaseFlares=-1   <-- ...or releasing flares
hotkey=-1   <-- hotkey to toggle manually
autoOffTime=500   <-- auto toggle time, this is like an timeout, if greater than 0 will toggle the extra to previous state after this amount of milliseconds


Now you can set an different livery (skin) to the jet start with, this new setting will be located in the jet_....ini file in the general category:


[general]
...
skin_count=0 <-- number of skins
skin=1 <-- skin to start with

Also you can set the starting skin in the acquirement point, in the file Jet_Spawn:


[jet_aquirement_1]
...
skin=1


Wednesday, 13 March 2013

[TUT] Script + XBox 360 controller


One of the frequently asked feature is the possibility of use xbox 360 controller with the script, i will show two ways of obtaining xbox control key presses.


First of all i wanna say thanks to pedro2555 for providing info about SlimDX, say thanks to Andrew for providing info about XNA, thanks to MOrdecki for info about the key values for native calls and thanks to "Soyeldiablo" for giving tip about analogue sticks :)

Download the sample project here, let's use this project as the base for this tutorial.


  • Basic native methods (recommended)
IS_USING_CONTROLLER: Will return true when you press one button or move an analogue stick in the control, if you move mouse or press an key in keyboard it will return false again.
IS_BUTTON_PRESSED: Here we use two params: first one is the controller number, second is the number of the key in the controller, if the key is down this will return true.
GET_POSITION_OF_ANALOGUE_STICKS: Return in the params the X and Y of the analogue sticks.

This is the list of all key values for controller:
BUTTON_BACK = 13
BUTTON_START = 12
BUTTON_X = 14
BUTTON_Y = 15
BUTTON_A = 16
BUTTON_B =17
BUTTON_DPAD_UP = 8
BUTTON_DPAD_DOWN = 9
BUTTON_DPAD_LEFT = 10
BUTTON_DPAD_RIGHT = 11
BUTTON_TRIGGER_LEFT = 5,
BUTTON_TRIGGER_RIGHT =7
BUTTON_BUMPER_LEFT = 4
BUTTON_BUMPER_RIGHT = 6
BUTTON_STICK_LEFT = 18
BUTTON_STICK_RIGHT = 19

Example of GET_POSITION_OF_ANALOGUE_STICKS use:


As you can see we need this objects of class Pointer (GTA.Native.Pointer) to be used as parameter in the Native function call, the first param of the native method is the controller number.

Also we need to initialize this pointers indicating their types, if we mismatch the type the pointer will receive nil as result, so be careful with the type, for this native call the correct type is Int32:
LeftStick_X = New GTA.Native.Pointer(GetType(Int32))
The values go from -127 to 127, idle its 0.

I wrote a small class that you can use to handle all the methods


  • Microsoft XNA DLL
With Microsoft XNA we can have access to xbox controller and detect when user press an button, what we need? First let's download the Microsoft XNA Framework Redistributable 4.0 and install it. After installing we need to find the DLL that must go with the script, if you use the windows file search you will find the dll in this folder probably:


Copy this file to the GTAIV.exe folder, when you release your script you need to release this dll too, and tell to the user that it must be placed in GTAIV.exe folder.

Now in our project let's add an reference to this dll file:


We will need an global object of Microsoft.Xna.Framework.Input.GamePadState:


And in the tick event we need to check for updates doing the follow:


If you put an simple message in the keyDown event you will see that none of the control buttons trigger this event, so to check if an button of the control is pressed we need to do this in the tick:


Check if the control is connected and then check for each key that we need to know if its pressed, in this case i showed an message indicating if button A is pressed. We also can check the triggers pressed, the difference here is that we have an float value that goes from 0 to 1 and from 0 to -1:


the same can be done with Thumb sticks specifying if we are looking for X or Y value:


Easy right? Yes, that is, the problem is when you need to use the button press like an hotkey, we need to create an global object of type int64 (or maybe int32) to store the last PacketNumber of the control, each time that we press an button this PacketNumber is increased, so in the tick we check if the last Packet number is different from the actual one and then we consider it an button press event:

and in the tick:


this PacketNumber will change each time that we press an button and when we release too or when we change the Thumb or Trigger position.

The most interesting way is create boolean variable for each button and float variables for each Thumb and Trigger that we plan to use in the script:


and uses an method to check this buttons states:


I'm not sure if we need to send only the XNA dll with the script or the entire packet (Microsoft XNA Framework Redistributable 4.0), in my tests just the dll was enough.

Download this script here


  • SlimDX DLL
Other tool that we can use to make this checks is the SlimDX, you can download it here, download the version for .Net 4.0 that is used by the ScriptHook. After installing we need to find the dll like we did with the XNA, if you use the windows file search you probably will find it here:


Like XNA dll, we need to copy this dll to the GTAIV.exe folder and add as reference in the project.

The object that will do the checks is the following:


Now what changes is how we get the PacketNumber and how we detect what key is pressed:



Download the script here



If you don't have an XBox 360 controller you can simulate one using an simple gamepad, the result its not very precise but it helps, to do this you can use this software:

You will need to download the main files and the application, put then inside the GTAIV.exe folder and run the application to configure the buttons of your gamepad to behave like an XBox 360 controller ;)

Sunday, 10 March 2013

Iron Man IV - Intense air combat [W.I.P.]

This will be very interesting, flying enemies with minigun and rocket launchers to hunt down Iron Man, also now we have flying ally to help Iron Man fight those enemies :)

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

Its very interesting how the uses of classes ( that i will show in an future tutorial :) ) makes some things very easy to change, i just added some properties to my Enemy class and this make possible to easily create the Ally units.





Saturday, 9 March 2013

[TUT-IV] Detecting Targets (peds, vehicles and objects)

Today i will show the idea that i use to detect targeted things in the game, i basically calc the distance between each possible target and the center of aim position.

Download the sample project here, let's use this project as the base for this tutorial.

We have an simple way to detect targeted peds, its the method Player.GetTargetedPed:


With this method and an gun (anything that will make you able to see the aim camera, for example an pistol or even an brick) you can detect the targeted ped, but its too much imprecise, for example if you aim at an car that has an driver, he will be detected as the target even if he is away from center of aim.
Also this method don't detects the peds that are Dead or in Ragdoll state.

My idea consists in get all possible targets, save then on an list, run this list and see who is closer to the center of the aim.

First lets create our list of possible targets, lets start with peds, this will be an global object so we can access it in the tick:

Now lets fill this list when the player press the aim button, so in the keydown event lets check for right mouse click and fill the list:

Now comes the main part, run the list in the tick and calc who is closer to center of aiming:

So, what is happening at each line?

  • If Game.isGameKeyPressed(GameKey.Aim) AndAlso Exists(pedsToTarget) Then
here we check if the user is aiming and if the list is ready to be used

  • Dim dist As Double
  • Dim comparePosition As Vector3
here we declare two variable to help us with the code, "dist" will be the distance between the ped and the camera, "comparePosition" will be the closest position of the center of the camera related to the ped position

  • For Each p As Ped In pedsToTarget
now we start the For that will run the list

  • If Exists(p) AndAlso (p <> Player.Character) Then
check if ped exists and if is different from player character

  • dist = p.Position.DistanceTo(Game.CurrentCamera.Position)
calculates the distance between the ped and the camera

  • comparePosition = Game.CurrentCamera.Position + Game.CurrentCamera.Direction * dist
determine the compare position, we will use this position to see if ped is close to center of aiming

  • If p.Position.DistanceTo(comparePosition) < 0.5 Then
now we see if the distance between the ped position and the compare position is less than 0.5, if true this means that the ped is close enough to be considered the target, we can make it more/less precise changing the 0.5 value

  • p.ForceRagdoll(2000, True)
  • p.ApplyForce(Vector3.WorldUp * 0.5, Vector3.WorldNorth)
  • msg("detected", 10)
here we just do some funny effect in the targeted ped to easily see who is targeted and show an message when the target is set, the result is an floating ped ^^


This is an exemplification of the calc:



The biggest problem with this technique is that we will get targeted peds that are behind walls and when the ped is fallen on ground the ped position is ~0.5 over what we expect as ped pos, this means that you need to aim a little up when he is fallen on ground.

The same idea can be used with vehicles, but to be more precise we will need to compare some extra positions not just the center of the vehicle:


we will need this additional variable in the tick:


we do the basic center position check:


and we compare to the "front position" too using GetOffsetPosition to obtain this position:

we multiply the Y (width) dimension of the model with 0.5 to obtain the half of the width and with relativeFront vector (one step forward)

we do the same with back, top, left and right position of the vehicle:


This makes more easy to target the vehicle when it is big like a bus or a truck, i personally prefer to check just the center position, in great part of cases is enough.

Download the Script of this tutorial.



Tuesday, 5 March 2013

Iron Man IV - [W.I.P. Flying enemies]

What about flying enemies for Iron Man? Maybe with similar powers? Imagine them with repulsor beam, haha that will make it difficult, maybe if we kill some number of enemies i can spawn those "Iron man" enemies to combat.

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




its awesome how this game has so many possibilities of diversification.

Sunday, 3 March 2013

Iron Man IV [W.I.P. Progress: Added rocket for enemies]

The script is almost done, i basically need to fix some bugs and finish the HUD.

*** The script was released, take a look here ***
  • Now we have FBI guys and helicopter passengers with rockets and they can lock on player and shoot:




  • New sound for locking targets (Peds/Vehicles)
  • New weapon selection mode, similar to Crysis, hold a button and move mouse to change:


  • Improved take off
  • Improved Repulsor beam performance
  • Added Basic HUD

Saturday, 2 March 2013

[TUT-IV] First script - Interacting with peds/vehicles/objects

Let's create our first script? Step by step how to create an visual studio project to be used to edit and compile an .net script for GTA IV using VB.NET language :)

You can download the sample project here.


Lets start our first script. First of all lets start an new project in Visual Basic:

Open Visual Basic, click in New Project, in the next window select Class Library and click in Ok:


Now you will see the "empty" script, lets fill it with the basic script, clear the actual script text and access this Pastebin page and copy the Raw text and paste it in the Visual Basic script:


Lets save our project, click in File > Save All, set the Location folder where the files will be saved and the name of the project and click in Save:


You will notice some blue and red lines in the script text, they indicate error in our code, they happen at this moment because we didn't have set the References for the script.
The basic reference is to the ScriptHookDotNet dll, download it here, inside the ZIP, open the folder "scripts", then open folder "for Developers", then folder "Bin", extract the dll "ScriptHookDotNet.dll" to an folder, we will use this dll as reference for each new project, so save it in an good place to avoid mistakenly deleting it.

 Now let's add the dll as reference, in the right side, right click our project name (Script_base) and click in Add Reference:


in the new window, click in Browse and select the folder where the dll is, select it and click in Ok:


We also will need references for the Imports used, actually we have:

Imports System
Imports GTA
Imports System.Drawing
Imports System.Windows.Forms

We don't need to care about System import now, GTA was already referenced by the dll, we need to add reference for System.Drawing and System.Windows.Forms,  right click the project name on the right and click in Add Reference, in the new window click in .NET and then select in the list the name of the imports, you can select more than one holding control and clicking in the item:


Ok, now we are ready to start ^^

Before all, lets test if everything is ok with our script, right click the project name and click in Properties, change Assembly name to Script_base.net and clear Root namescape:


Click in Compile and in the Build output path set the path of your GTA Scripts folder:


Click in the menu Build > Build Script_base, if everything is Ok the text Build succeeded will appear in the left bottom and the script dll will be in the GTA Scripts folder:



Lets start detecting and interacting with game objects like Pedestrians, Vehicles (cars, bikes, trains, boats, helicopters, trucks, etc) and Objects, For example, lets get all peds surrounding player and push then:

In the keyDown event lets check if the player pressed numpad9, then get some peds, do some checks and push then:

What is happening in each line:

   If e.Key = Keys.NumPad9 Then
here we are checking if the key pressed is numpad9

   Dim peds As Ped()
here we declare an object of type Ped array, will be our list of peds

   Dim tmpPed As Ped
here we declare our temporary ped, it will be an item of the peds list

   peds = World.GetPeds(Player.Character.Position, 30)
here we get all peds that are at max distance of 30 from player position and store then in the array

   For Each tmpPed In peds
here we start running the list for the first time, putting the peds in Ragdoll state, this will make the push more interesting, tmpPed will receive the actual ped in the For iteration

   If Exists(tmpPed) AndAlso (tmpPed <> Player.Character) AndAlso Not Exists(tmpPed.CurrentVehicle) Then
here we check if the ped exists, if is different from player and if it are not inside an vehicle

   tmpPed.PreventRagdoll = False
here we avoid that the ped prevent an ragdoll state

   tmpPed.ForceRagdoll(2000, True)
here we force an ragdoll state for the ped

And in the second For:

   tmpPed.ApplyForce(Vector3.Normalize(tmpPed.Position - Player.Character.Position) * 15 + Vector3.WorldUp * 2, Vector3.WorldNorth)
here we apply force to the ped pushing him away from player:

   "Vector3.Normalize(tmpPed.Position - Player.Character.Position) * 15" will return the direction of the push and multiply by 15
   " + Vector3.WorldUp * 2" will make the force move ped Up too
   ", Vector3.WorldNorth" will add an rotation to this force


We can do the same with vehicles just changing the method that will return the vehicles and the types of the objects:


Noticed how i did this different? I didn't have to declare all variables separately, i can do all in the For declaration, this is interesting to do when you don't need to run the list more than one time.

To do the same with objects we just change types and methods, like we did with vehicles and also we detach the objects because great part of them are attached somewhere, also we need to use GTA.Object as type instead of just Object because the word Object is part of the vb.net language:


The most important methods used in those examples was: World.GetPeds, World.GetVehicles and World.GetAllObjects, we also can use World.GetAllPeds and World.GetAllVehicles, but they will return all vehicles/peds and we will have more lag.

An interesting detail about World.GetPeds is the third param that will limit the number of peds found

With World.GetAllPeds we can specify as parameter the model of the pedestrian that we are searching, for example if we want to search for fat cops only:

   peds = World.GetAllPeds("m_m_fatcop_01")

the same we can do with World.GetVehicles and World.GetAllVehicles:

   For Each v As Vehicle In World.GetVehicles(Player.Character.Position, 30, "taxi")

   For Each v As Vehicle In World.GetAllVehicles("taxi")


Download the final script here, you can just put it in the GTA Scripts folder and test it, you don't need an compiled dll to run scripts :)


Tip: Run gta in window mode using commandline.txt with line -windowed or with an shortcut to the LaunchGTAIV.exe with param -windowed

To test the script, press " to see the console window and then type the command reloadscripts, if everything is ok, your script name will appear in the console like this: