How to stop vehicles from blowing up?
#1

Well today i need help on how to stop the vehicles form blowing up like i want to make it so when the vehicle health gets to 0.350 or something the engine will stop and it will say this vehicle engine is broken any idea or can you help me



engine command below
Код:
if(newstate == PLAYER_STATE_DRIVER)
	{
 		new vehicleid = GetPlayerVehicleID(playerid);
		GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
		if(engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET)
		{
        	SendClientMessage(playerid, COLOR_WHITE,"< To turn on the vehicle engine type {800040}/engine{FFFFFF} - to check radio commands type {800040}/radiohelp{FFFFFF} >");
		}
	}
Код:
if(strcmp(cmd, "/engine", true) == 0 || strcmp(cmd, "/engine", true) == 0)
	{
        new vid = GetPlayerVehicleID(playerid);
        GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
		if(vid != INVALID_VEHICLE_ID)
		if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GRAD2, "You must be in a vehicle before you can do this!");
		if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_GRAD2, "Only the driver can do this!");
		if(engine == VEHICLE_PARAMS_OFF || engine == VEHICLE_PARAMS_UNSET)
		{
            SendClientMessage(playerid, -1, ""#COL_WHITE"> You have "#COL_GREEN" started"#COL_WHITE" the engine");
            GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "* %s takes out the keys - inserts it into the ignition and twists it.", sendername);
			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            SetVehicleParamsEx(vid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
        }
        else if(engine == VEHICLE_PARAMS_ON)
		{
            SendClientMessage(playerid, -1, ""#COL_WHITE"> You have "#COL_RED"stopped"#COL_WHITE" the engine");
            GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "* %s extends his hand towards the ignition, twisting the keys.", sendername);
			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            SetVehicleParamsEx(vid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
        }
		return 1;
    }
Reply
#2

You can use a timer to check if the car's health it's under 380.0 then use SetVehicleHealth(vehicleid, Float:health)
Reply
#3

Going to edit this post when i go home and show what to do.
Reply
#4

I'd use SetTimerEx for checking if the new state was driver and I'd get vehicle's health, if it was under 350/1000, then I'd set vehicle params ex > engine to false and then return a message.
Reply
#5

This may or may not work, but you can try it. It uses y_timers and y_hooks.

pawn Код:
new
    Timer:healthCheckTimer[MAX_VEHICLES]
;

hook OnVehicleSpawn(vehicleid)
{
    healthCheckTimer[vehicleid] = repeat checkVehicleHealth(vehicleid);
    return 1;
}

hook OnVehicleDeath(vehicleid)
{
    stop healthCheckTimer[vehicleid];
    return 1;
}

timer checkVehicleHealth[3000](vehicleid)
{
    new
        Float:vehicleHealth
    ;
   
    GetVehicleHealth(vehicleid, vehicleHealth);
    if(vehicleHealth < 400.0)
    {
        foreach(new i : Player)
            if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                if(GetPlayerVehicleID(i) == vehicleid) GameTextForPlayer(i, "~w~You broke the vehicle, ~r~idiot~w~!", 3000, 3);
       
        SetVehicleHealth(vehicleid, 400.0);
       
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
    }
    return 1;
}
You could expand on it and run checks to see if the vehicle is flipped on its top. If it is, you could put it back on its wheels to prevent it from blowing up. I'd recommend using a time-stamp to make sure that it isn't "on its top" simply because the driver made it roll...
Reply
#6

yea just like when the vehicle near sets on fire it pops up with a message this vehicle is broken or something like that anyways, realcop i will give that a try and see if it works thanks guys.
Reply
#7

I remembered that you can't hook functions using y_hooks and I couldn't figure out how to do it with ALS. Here's the new code, I added a game text and made the timer call every 3 seconds, instead of every 1.5. 3 seconds is still more than enough time. Also note that the OnVehicleSpawn callback only gets called when a vehicle respawns. When I figure out the function hooking, I'll try to hook CreateVehicle to add the health check timer for you!

pawn Код:
new
    Timer:healthCheckTimer[MAX_VEHICLES]
;

hook OnVehicleSpawn(vehicleid)
{
    healthCheckTimer[vehicleid] = repeat checkVehicleHealth(vehicleid);
    return 1;
}

hook OnVehicleDeath(vehicleid)
{
    stop healthCheckTimer[vehicleid];
    return 1;
}

timer checkVehicleHealth[3000](vehicleid)
{
    new
        Float:vehicleHealth
    ;
   
    GetVehicleHealth(vehicleid, vehicleHealth);
    if(vehicleHealth < 400.0)
    {
        foreach(new i : Player)
            if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                if(GetPlayerVehicleID(i) == vehicleid) GameTextForPlayer(i, "~w~You broke the vehicle, ~r~idiot~w~!", 3000, 3);
       
        SetVehicleHealth(vehicleid, 400.0);
       
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
    }
    return 1;
}
Reply
#8

oh thank you realcop


EDIT: i had errors when i put this in

Код:
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(113) : warning 201: redefinition of constant/macro (symbol "MAX_ROADBLOCKS")
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27705) : error 017: undefined symbol "hook"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27706) : error 001: expected token: ";", but found "{"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27707) : error 017: undefined symbol "repeat"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27707) : error 017: undefined symbol "checkVehicleHealth"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27711) : warning 225: unreachable code
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27711) : error 017: undefined symbol "hook"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27711) : warning 202: number of arguments does not match definition
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27712) : error 001: expected token: ";", but found "{"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27713) : error 017: undefined symbol "stop"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27713) : warning 215: expression has no effect
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27717) : warning 225: unreachable code
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27717) : error 017: undefined symbol "timer"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27717) : error 017: undefined symbol "checkVehicleHealth"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27717) : warning 215: expression has no effect
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27717) : error 001: expected token: ";", but found "]"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27717) : fatal error 107: too many error messages on one line
Reply
#9

Did you include y_hooks, y_timers, and foreach?
Reply
#10

oh wait haha no i didnt sorry let me do that my bad Police officer
EDIT: new errors when i add it to my system gamemode

Код:
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(115) : warning 201: redefinition of constant/macro (symbol "MAX_ROADBLOCKS")
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(328) : warning 201: redefinition of constant/macro (symbol "isnull(%1)")
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27646) : error 017: undefined symbol "hook"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27647) : error 001: expected token: ";", but found "{"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27648) : error 017: undefined symbol "repeat"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27648) : error 017: undefined symbol "checkVehicleHealth"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27652) : warning 225: unreachable code
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27652) : error 017: undefined symbol "hook"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27652) : warning 202: number of arguments does not match definition
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27653) : error 001: expected token: ";", but found "{"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27654) : error 017: undefined symbol "stop"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27654) : warning 215: expression has no effect
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27658) : warning 225: unreachable code
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27658) : error 017: undefined symbol "timer"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27658) : error 017: undefined symbol "checkVehicleHealth"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27658) : warning 215: expression has no effect
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27658) : error 001: expected token: ";", but found "]"
C:\Users\Brandon\Desktop\Project Roleplay By Yves\gamemodes\PERP.pwn(27658) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


11 Errors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)