How can I break down the car engine?
#1

Hey there!
I have a little problem. I created a timer that checks the car health, If it's below 250, it will restore it to exactly 250, so the car doesn't blow up (the code is below). I also want the car engine to stop when the health is below the limit, so the player would be forced to somehow, repair the car, or change it. How can I do that in my code?
Код:
public OnFilterScriptInit()
{
    SetTimer("carhealthcheck",500,1);
	return 1;
}
#else

main(){}

#endif
forward carhealthcheck();
public carhealthcheck()
{
    new Float:vhp;
    for(new vehicleid; vehicleid<MAX_VEHICLES;vehicleid++)
    {
		if(GetVehicleModel(vehicleid)==0)continue; //only returns 0 when vehicle is invalid (not spawned)
        GetVehicleHealth(vehicleid,vhp);
        if(vhp<250.0)SetVehicleHealth(vehicleid,250);
    }
}
Reply
#2

Код:
public OnFilterScriptInit()
{
    SetTimer("carhealthcheck",500,1);
	return 1;
}
#else

main(){}

#endif
forward carhealthcheck();
public carhealthcheck()
{
    new Float:vhp;
    for(new vehicleid; vehicleid<MAX_VEHICLES;vehicleid++)
    {
		if(GetVehicleModel(vehicleid)==0)continue; //only returns 0 when vehicle is invalid (not spawned)
        GetVehicleHealth(vehicleid,vhp);
        if(vhp<250.0)SetVehicleHealth(vehicleid,250);
        new engine,lights,alarm,doors,bonnet,boot,objective;
	GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
	SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
    }
}
Reply
#3

I tried exactly the same code. It stops the car engine as soon as I enter the car.
Reply
#4

PHP код:
forward carhealthcheck();
public 
carhealthcheck()
{
    new 
Float:vhp;
    for(new 
vehicleidvehicleid<MAX_VEHICLES;vehicleid++)
    {
        if(
GetVehicleModel(vehicleid)==0)continue;
        
GetVehicleHealth(vehicleid,vhp);
        if(
vhp<250.0)
        {
            
SetVehicleHealth(vehicleid,250)
            new 
engine,lights,alarm,doors,bonnet,boot,objective;
            
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
            
SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
        }
    }

Reply
#5

Thanks. That one worked perfectly.
What is the difference between 0 and VEHICLE_PARAMS_OFF?
Reply
#6

Nothing really, that's not what I changed.. They both give the value 0.
Reply
#7

Oups, I totaly forgot my brackets xD.
Reply
#8

nevermind...Thank you for your help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)