Vehicle Armour Intention

Started by GangstaRas, May 27, 2015, 03:48 AM

Previous topic - Next topic

GangstaRas

The idea is that certain vehicle IDs receive less damage from weapons than others. the first approach I did was to increase vehicle.Health past 1000 but that didn't work, looks like 1000 is the max allowed. My next thought would be to manipulate what I found to be a damage multipler for weapons on cars. Each weapon seems to do 3x the damage it would do hitting another player. Is it possible to manipulate this in script and individualize it to the vehicle ID i want? If not, I'm open to suggestions on how I would go about coding this idea.

maxorator

It is possible via changing vehicle handling settings. This can be changed for each vehicle individually. However different vehicles have different base values. You can either ignore the different base values and use your own multipliers or multiply the base value with whatever you want. First option is as easy as:
vehicle.SetHandlingData(23, multiplier);
The second approach would involve getting the default value for that vehicle model:
vehicle.SetHandlingData(23, GetHandlingRule(vehicle.Model, 23) * multiplier);
23 is the ID for DamageMultiplier handling field, the list of the IDs can be found at: https://vcmpdev.wordpress.com/2012/02/18/changing-vehicle-handling/

GangstaRas

Nice but I'm going to need some more guidance with this.

I have this under the onPlayerEnterVehicle function but it doesn't seem to work (no runtime errors on it). I'm guessing its in the wrong place but guide me where to set it up.


const veh_FBIRancher = 220;
const veh_FBIWashington = 147;

switch (player.Vehicle.Model)
{
case veh_FBIRancher: case veh_FBIWashington:
vehicle.SetHandlingData(23, GetHandlingRule(vehicle.Model, 23) * 0.2);
break;
}

Thijn

Did you define the vehicle variable? You seem to be using player.Vehicle for switching the Model.

GangstaRas

Hmm. Changed to this now but nothing


local vehModel = player.Vehicle.Model;
const veh_FBIRancher = 220;
const veh_FBIWashington = 147;

switch (vehModel)
{
case veh_FBIRancher: case veh_FBIWashington:
vehicle.SetHandlingData(23, GetHandlingRule(vehModel, 23) * 0.2);
break;
}

aXXo

I tried to create a bullet proof car some months ago and concluded this:

It takes same amount of M60 bullets to destroy a Barracks OL and a Cheetah. Most likely, the DamageMultiplier is only for collision damage. Setting the Vehicle HP above 1000 worked, but that also made the vehicle immune to collisions.

What Thijn pointed is that the variable "vehicle" is not defined in the SetHandling line.
You should add a line somewhere above the switch statement, if not done already.
local vehicle = player.Vehicle;

GangstaRas

Added but to no luck  :-\. Tell me what you did to get the vehicle health past 1000 cuz I couldn't get that to work either. I'd sacrifice collision damage for it

GangstaRas

Quite awhile since the last post here. Either way I did my experimentation and you're right about the damage multiplier aXXo, seems to only be for collisions. I also got the vehicle over 1000 unlike my first attempt however during my tests it took damage from any scenario, bullets, collisions so thats good. The problem is how do I set this at the start of the server. I found this function that would be perfect, SetVehicleHeatlh, but it seems to be too old and gone for 0.4. Is there any equivalent function I could use to set it that the start?

aXXo

You need to set vehicle's health to any value above 1000.
vehicle.Health = 99999;

To do it for every vehicle on server start, you need to loop through all vehicles on the server and set their health to whatever value.
A method to do it would be:

//Define a function to set all the vehicle's health to 99999
function VehicleImmunity()
{
// Initialize a 'veh' variable that will hold the vehicle instance
local veh;

// Loop from 0 to Vehicle Count in the server
for( local i = 0; i < GetVehicleCount(); i++ )
{
// Check if the vehicle with ID 'i' exists, store the instance of the vehicle 'i' in 'veh'
if( ( veh = FindVehicle( i ) ) != null )
{
// If valid, set the HP to 99999
veh.Health = 99999;
}
}
}

// Call the function we just defined.
VehicleImmunity();

You could add more flavor to this. Instead of a constant 99999, if you want you can set vehicle's HP relative to their Mass. So, heavier cars can take more damage.
To get the mass, use:
GetHandlingRule( vehicle.Model, 1 )
https://vcmpdev.wordpress.com/2012/02/18/changing-vehicle-handling/

GangstaRas

There's an issue I'm having with this and custom functions in general. They don't seem to load. I get no errors or anything but they just don't work and idk why. I added a print command to what you had in the if statement as a proof it's not loading

aXXo

You would need to call that function that you defined.

The syntax to define a function is:
function FunctionName( parameter1, parameter2, ... )
{
  // Stuff that this function does
}

This will define the function and tell the server what to do when it is called.
But you still need to call it.

To call the above function, use:
FunctionName( 1, 2 );
This will call the function, parameter1 will be assigned 1 and parameter2 will be assigned 2.
The choice is yours where you want to call it.

You may call it under a command, on player connect or on server start.

In this case, you want to call it on server start, so you have two options:
VCMP has an inbuilt onScriptLoad() function, which can be used.
Make sure the onScriptLoad function is defined only once. If you have multiple definitions, the one defined in the last will overwrite previous definitions. This function automatically gets called internally in VCMP so you don't need to call it.
function onScriptLoad()
{
// Your other server stuff
VehicleImmunity();
}

The other option is to call it in your Main.nut
Put it anywhere in the file, after it has been defined(In global scope). That file is read top to bottom when your server starts, so it will automatically call the function.
You might want to explain your directory structure and elaborate how many script files you are linking with each other to make this work.

GangstaRas

I had exactly this and it didn't work. At first I changed what you had to suit the fact that I only wanted to alter a select set of cars, not necessarily all of them, so I took out the for loop and define veh to the car ID I pleased. I have this diagnostic command.

function onPlayerEnterVehicle( player, vehicle, door )
{
print (vehicle.Health);
}

This is what I used and prove any changes that happen to the car's health from the beginning of this topic. So when I enter the vehicle, my code was still spitting back 1000 so I dumped all my for loop changes and just copy and pasted what you had in the form you just explained, function defined and then in OnScriptLoad was where I called the function. I saw no changes so then I modified the if statement in what you wrote as a second way to prove if it was running or not.

This is my modification

function VehicleImmunity()
{
 local veh;
 for( local i = 0; i < GetVehicleCount(); i++ )
 {
  if( ( veh = FindVehicle( i ) ) != null )
  {
   veh.Health = 99999;
   print("worked");
  }
 }
}

function onScriptLoad()
{
VehicleImmunity();
}

That "worked" isn't printing and I have so far used the OnScriptLoad for many other things that are working I just can't understand why custom functions don't work for me

ℛḝξ☂

 veh = FindVehicle( i ) ) != null?
I may be a slow walker but I am always walking.

Thijn

Quote from: Sentral on Jun 17, 2015, 04:22 AMveh = FindVehicle( i ) ) != null?
Isn't really pretty, but works fine.



Try putting prints all over the place. in your onScriptLoad, in your custom function at the end of your custom function, at the end of your onScriptLoad etc.

GangstaRas

I already have print functions in the OnScriptLoad so I know that's fine but I did as you requested and all the random prints that were not associated with the custom function worked however within the custom function I've made a discovery. This is the code of the random prints I did within it and the function is still being called within OnScriptLoad.

function VehicleImmunity()
{
 local veh;
 print("from function");
 for( local i = 0; i < GetVehicleCount(); i++ )
 {
  print("forloopstep");
  if( ( veh = FindVehicle( i ) ) != null )
  {
   print("if statement");
   veh.Health = 99999;
   print("worked");
  }
 }
 print("end of the road");
}

Of all the prints I now added, only the "from function" and "end of the road" printed back so something is wrong with this for loop. At least we truly know the function is being called