Car engine help
#1

Hey guys,

Im trying to make a car die if the carhealth is below 350.
It's all working, but when you're in a car & the car health is below 350 nothing will happen. The engine will stop, just when you get out, and back in. Anyone can help me?

pawn Код:
if(newstate == PLAYER_STATE_DRIVER)
    {
    new vehicleid = GetPlayerVehicleID(playerid);
    new Float:chealth;
    GetVehicleHealth(vehicleid, chealth);
    {
    if(chealth < 350.0)
    {
    SetVehicleParamsEx(vehicleid, false, true, true, true, false, false, false);
    TogglePlayerControllable(playerid,0);
    SendClientMessage(playerid, orange, "Your engine died. Please call a repairsman to repair it");
    return 1;
    } else if (GetVehicleHealth(vehicleid, chealth) >350) {
    SetVehicleParamsEx(vehicleid, true, false, false, false, false, false, false);
    TogglePlayerControllable(playerid, 1);
    }
    }
    return 1;
    }
Reply
#2

you'd need a timer or put it under the vehicle damage update one.
Reply
#3

Quote:
Originally Posted by cessil
Посмотреть сообщение
you'd need a timer or put it under the vehicle damage update one.
What you mean with vehicle damgage update?
Reply
#4

Your code only checks the health if someone enters the car not whilst he drivers, So here
Код:
forward CarWrecked();
Under Ongamemodeint     SetTimer("CarWrecked", 500, true);
anywhere
public CarWrecked()
{
	for(new i; i < MAX_PLAYERS; i++)
	{
	    new Float:VehHealth;
	    new PlayerVehicle;
	    PlayerVehicle = GetPlayerVehicleID(i);
	    GetVehicleHealth(PlayerVehicle, VehHealth);
	    if(IsPlayerInAnyVehicle(i))
	    {
	    if(VehHealth < 300)
	    {
	        RemovePlayerFromVehicle(i);
	        SetVehicleHealth(PlayerVehicle, 299);
	        GameTextForPlayer(i, "~r~ Wrecked", 2000, 4);
			}
		}
	}
	return 1;
}
Reply
#5

the OnVehicleDamageStatusUpdate callback
Reply
#6

Hey,

Ive made a little changes, but im getting some errors: already tried something but that didnt work neither.

pawn Код:
public CarWrecked()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        new Float:VehHealth;
        new PlayerVehicle;
        new PID;
        PID = GetPlayerName(playerid, PID, sizeof(PID)); <--  line 1693
        PlayerVehicle = GetPlayerVehicleID(i);
        GetVehicleHealth(PlayerVehicle, VehHealth);
        if(IsPlayerInAnyVehicle(i))
        {
        if(VehHealth < 350)
        {
            SetVehicleParamsEx(PlayerVehicle, false, true, true, true, false, false, false);
            TogglePlayerControllable(PID,0);
            SendClientMessage(PID, orange, "Your engine died. Please call a repairsman to repair it");
            SetVehicleHealth(PlayerVehicle, 349);
            return 1;
            } else if(VehHealth > 350) {
            SetVehicleParamsEx(PlayerVehicle, true, false, false, false, false, false, false);
            TogglePlayerControllable(PID, 1);
            SendClientMessage(PID, orange, "Your engine have been fixed.");
            SendClientMessage(PID, orange, "You gave the repairsman 500$.");
            return 1;
            }
        }
    }
    return 1;
}
Made it like that, but getting those errors:

Код:
C:\Users\wesley.PC_van_Kelsey\Desktop\RolePlay\gamemodes\RolePlay.pwn(1693) : error 017: undefined symbol "playerid"
C:\Users\wesley.PC_van_Kelsey\Desktop\RolePlay\gamemodes\RolePlay.pwn(1693) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
Reply
#7

Hey, it is forevery function so no playerid, use "i" instead of playerid
Reply
#8

Ooh okay,

So if you have "for(new i; i < MAX_PLAYERS; i++)" in your callback, all the "playerid's" are changed by "i"?

Edit:

Still got a little problem, when the car health is below 350, it sets the player health back to 349, and gives a message "Your Engine Died, etc etc etc". But the only thing is, it keeps spamming the message Your Engine Died.. Is there somehow i can get rid of this? (It is the same if the car is repaired

pawn Код:
public CarWrecked()
{
    for(new i; i < MAX_PLAYERS; i++)
    {
        new Float:VehHealth;
        new PlayerVehicle;
        PlayerVehicle = GetPlayerVehicleID(i);
        GetVehicleHealth(PlayerVehicle, VehHealth);
        if(IsPlayerInAnyVehicle(i))
        {
        if(VehHealth < 350)
        {
            SetVehicleParamsEx(PlayerVehicle, false, true, true, true, false, false, false);
            TogglePlayerControllable(i,0);
            SendClientMessage(i, orange, "Your engine died. Please call a repairsman to repair it");
            SetVehicleHealth(PlayerVehicle, 349);
            return 1;
            } else if(VehHealth > 998) {
            SetVehicleParamsEx(PlayerVehicle, true, false, false, false, false, false, false);
            TogglePlayerControllable(i, 1);
            SendClientMessage(i, orange, "Your engine have been fixed.");
            SendClientMessage(i, orange, "You gave the repairsman 500$.");
            return 1;
            }
        }
    }
    return 1;
}
Reply
#9

you'd need to set a new global variable such as
pawn Код:
new isTotalled[MAX_PLAYERS];
pawn Код:
OnVehicleDamageStatusUpdate(vehicleid,playerid)
{
        new Float:VehHealth;
        new PlayerVehicle;
        GetVehicleHealth(vehicleid, VehHealth);
        if(VehHealth < 350 && isTotalled[playerid] == 0)
        {
            SetVehicleParamsEx(PlayerVehicle, false, true, true, true, false, false, false);
            TogglePlayerControllable(i,0);
            SendClientMessage(playerid, orange, "Your engine died. Please call a repairsman to repair it");
            SetVehicleHealth(vehicleid, 349);

            isTotalled[playerid] = 1;

            return 1;
            } else if(VehHealth > 998) {
            SetVehicleParamsEx(vehicleid, true, false, false, false, false, false, false);
            TogglePlayerControllable(playerid, 1);
            SendClientMessage(playerid, orange, "Your engine have been fixed.");
            SendClientMessage(playerid, orange, "You gave the repairsman 500$.");
            return 1;
            }
        }
that's just a rough example, don't copy/paste it.

and with loops this is what happens
for(new i; i < MAX_PLAYERS; i++)

new i;
creates a new variable called 'i', this variable is 0 by default,

i < MAX_PLAYERS;
while i is less than MAX_PLAYERS do what ever you want in the brackets

i++
and then after you've done stuff in the brackets increase i by 1.

so this creates a loop from 0 - MAX_PLAYERS which is all the playerids on the server
Reply
#10

Ooh now i understand it

And about the variable: DUH >_<
I gotta think further i guess =P

Thanks for your help!
~Wesley
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)