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.
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/
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;
}
Did you define the vehicle variable? You seem to be using player.Vehicle for switching the Model.
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;
}
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;
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
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?
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/
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
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.
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?
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.
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
So I did a couple of tests and surprisingly what I found is that the
GetVehicleCount();
is returning 0, that means a loop won't even start because the value of that is 0, and when I set it to any other number bigger than 0, for instance i got 5 vehicles, So I used this code
function VehicleImmunity()
{
print( GetVehicleCount() );
local veh;
print("from function");
for( local i = 0; i < 5; i++ )
{
print("forloopstep");
local veh = FindVehicle( i );
if( veh )
{
print("if statement");
veh.Health = 99999;
print("worked");
}
}
print("end of the road");
}
and it worked totally fine, So basically you need to get correctly the total amount of vehicles you have, I don't know if that function is bugged or whatsoever but it is returning 0;
A good find but now I found something myself. Is there a bug on FindVehicle as well? I remember experimenting with getting a vehicle's name and I must of did print(vehicle) and it gave me this 0x0000blahblah value. I bring that up because if the FindVehicle is suppose to be working would it have some 0x000blahblah value defined to veh rather than being empty?
function VehicleImmunity()
{
print( GetVehicleCount() );
local veh;
print("from function");
for( local i = 0; i < 106; i++ )
{
print("forloopstep");
local veh = FindVehicle( i );
print ( veh );
if( veh )
{
print("if statement");
veh.Health = 99999;
print("worked");
}
}
print("end of the road");
}
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi583.photobucket.com%2Falbums%2Fss273%2FThe_Bad_Tiger%2FUntitled_zpsruxmdm5e.png&hash=06fa8d5d90bcc6ff2fb4ed3f9ad8b1bb99501790)
That's not a bug, there is a function to get the namr of the vehicle, I guess it was GetVehicleNameFromModel, maybe that, can't check wiki right now i'm on phonr.
So basically you can just do:
local veh = FindVehicle( i );
if( veh )
{
name = GetVehiclrNameFromModel( veh.Model );
print( name );
}
Have a try ;)
printing FindVehicle should indeed print a pointer instead of null values, which means FindVehicle can't find your vehicle ;)
Might sound obvious, but do you actually have any vehicles?
If so, where and how do you add them? If it's in the config file, do you have the xmlconfloader plugin loaded?
Quote from: Doom_Killer on Jun 17, 2015, 05:04 PMThat's not a bug, there is a function to get the namr of the vehicle, I guess it was GetVehicleNameFromModel, maybe that, can't check wiki right now i'm on phonr.
So basically you can just do:
local veh = FindVehicle( i );
if( veh )
{
name = GetVehiclrNameFromModel( veh.Model );
print( name );
}
Have a try ;)
Thanks for the lookout Doom but I had that prob sorted a long time ago :), I just brought up that part.
And yh Thijn I have the vehicles, they're in the config file and xmlconfloader has been loaded. I have other vehicle commands that work perfectly fine so I'm not sure whats the deal here
Try calling your custom function on, for example, onPlayerJoin. Maybe the vehicles aren't properly loaded when your script loads, for some unknown reason.
Well I'll be...it works :D the 99999 value didn't register though, had to use something more realistic like 3000 but it works, if statement finally worked and all cars health are changed but as it is right now in its placement won't it run every time someone joins?
An explanation would be, that vehicles from the Config file are loaded after the onScriptLoad() executes. That explains GetVehicleCount being 0 and FindVehicle(1) returning NULL.
Anyway, config file was a practice in 0.3z and it is too old school for 0.4. The plugin which allows it to be read will probably not be updated in future. Quite a lot of 0.4 server settings are already not available in the config and you need to call them in your scripts anyway.
Get rid of the config.
Quote from: aXXo on Jun 17, 2015, 07:03 PMAn explanation would be, that vehicles from the Config file are loaded after the onScriptLoad() executes. That explains GetVehicleCount being 0 and FindVehicle(1) returning NULL.
Anyway, config file was a practice in 0.3z and it is too old school for 0.4. The plugin which allows it to be read will probably not be updated in future. Quite a lot of 0.4 server settings are already not available in the config and you need to call them in your scripts anyway.
Get rid of the config.
Damn :/. Well I guess it's cars.nut time. Thank you all guys, its been quite a hell this one.