Custom Vehicle health - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Custom Vehicle health (
/showthread.php?tid=632614)
Custom Vehicle health -
1fret - 16.04.2017
So im trying to make all vehicles armoured vehicles used by law enforcers in my server health be more than 1000, now i made this code but its not working could someone tell me where i go wrong.. If you are posting a reply please ensure to explain it because im not only posting for the help but posting to learn as well..
PHP код:
for(new i = 0; i <= MAX_VEHICLES; i++)
{
if(IsValidVehicle(i))
{
new vehm = GetVehicleModel(i);
if(vehm == 427 || vehm == 470 || vehm == 447)
{
SetVehicleHealth(i, 2500.0);
}
}
}
Re: Custom Vehicle health -
DarkSkull - 16.04.2017
Where do you use this code?
Re: Custom Vehicle health -
1fret - 16.04.2017
Quote:
Originally Posted by DarkSkull
Where do you use this code?
|
Ongamemodeinit and onvehiclespawn
Re: Custom Vehicle health -
RIDE2DAY - 16.04.2017
You must run that code after you load/create the vehicles. Keep in mind that vehicle ids start at 1, not 0, so:
PHP код:
/* OnGameModeInit */
AddStaticVehicle(...);
AddStaticVehicle(...);
for(new i = 1, t = GetVehiclePoolSize(); i <= t; i++)
{
new v_model = GetVehicleModel(i);
if(v_model == 427 || v_model == 470 || v_model == 447)
{
SetVehicleHealth(i, 2500.0);
}
}
PHP код:
/* OnVehicleSpawn */
new v_model = GetVehicleModel(vehicleid);
if(v_model == 427 || v_model == 470 || v_model == 447)
{
SetVehicleHealth(vehicleid, 2500.0);
}
You can skip IsValidVehicle because GetVehicleModel returns 0 if the vehicle doesn't exist.
Re: Custom Vehicle health -
1fret - 16.04.2017
Quote:
Originally Posted by RIDE2DAY
You must run that code after you load/create the vehicles. Keep in mind that vehicle ids start at 1, not 0, so:
PHP код:
/* OnGameModeInit */
AddStaticVehicle(...);
AddStaticVehicle(...);
for(new i = 1, t = GetVehiclePoolSize(); i <= t; i++)
{
new v_model = GetVehicleModel(i);
if(v_model == 427 || v_model == 470 || v_model == 447)
{
SetVehicleHealth(i, 2500.0);
}
}
PHP код:
/* OnVehicleSpawn */
new v_model = GetVehicleModel(vehicleid);
if(v_model == 427 || v_model == 470 || v_model == 447)
{
SetVehicleHealth(vehicleid, 2500.0);
}
You can skip IsValidVehicle because GetVehicleModel returns 0 if the vehicle doesn't exist.
|
Do i have to use addstaticvehicle, cause for my scripts i used CreateVehicle
Re: Custom Vehicle health -
DarkSkull - 16.04.2017
No, It can be CreateVehicle as well.
Re: Custom Vehicle health -
1fret - 16.04.2017
Quote:
Originally Posted by DarkSkull
No, It can be CreateVehicle as well.
|
Its not working
Re: Custom Vehicle health -
1fret - 16.04.2017
bump
Re: Custom Vehicle health -
ISmokezU - 16.04.2017
You shouldn't check by model because eventually it's gonna catch up on you, you should check by vehicle ids instead.
Re: Custom Vehicle health -
DarkSkull - 16.04.2017
Are you sure that the code Ride2Day gave you is run after all the vehicles are loaded in?