SA-MP Forums Archive
How can I break down the car engine? - 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: How can I break down the car engine? (/showthread.php?tid=384839)



How can I break down the car engine? - HeLiOn_PrImE - 13.10.2012

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);
    }
}



Re : How can I break down the car engine? - lelemaster - 13.10.2012

Код:
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);
    }
}



Re: How can I break down the car engine? - HeLiOn_PrImE - 13.10.2012

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


Re: How can I break down the car engine? - JhnzRep - 13.10.2012

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);
        }
    }




Re: How can I break down the car engine? - HeLiOn_PrImE - 13.10.2012

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


Re: How can I break down the car engine? - JhnzRep - 13.10.2012

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


Re : How can I break down the car engine? - lelemaster - 13.10.2012

Oups, I totaly forgot my brackets xD.


Re: How can I break down the car engine? - HeLiOn_PrImE - 13.10.2012

nevermind...Thank you for your help!