Vehicle Health Command, Is broken, Need help !!
#1

pawn Код:
if(strcmp(cmd, "/vhealth", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
           
            new carid;
            carid = GetPlayerVehicleID(playerid);

            if(IsPlayerInAnyVehicle(playerid))
            {
            if(IsAnOwnableCar(carid))
            {
            new Float:health;
            GetVehicleHealth(carid, health);
            if(health <350) return SendClientMessage(playerid,COLOR_LIGHTRED,"Vehicle Health: Damaged!!");
            if(health >351) return SendClientMessage(playerid,COLOR_GREEN,"Vehicle Health: Good!!");
            }
            else
            {
            SendClientMessage(playerid, COLOR_GREY, "* You are not in a vehicle!");
            return 1;
        }
        return 1;
    }
}
}
Problem is, It doesn't say You are not in a vehicle.

Please could someone check this, and fix for me?

Thankyou.
Reply
#2

pawn Код:
if(strcmp(cmd, "/vhealth", true) == 0)
{
        if(IsPlayerConnected(playerid))
        {
            new carid;
            carid = GetPlayerVehicleID(playerid);

            if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "* You are not in a vehicle!");
           
            if(IsAnOwnableCar(carid))
            {
               new Float:health;
               GetVehicleHealth(carid, health);
               if(health <350) return SendClientMessage(playerid,COLOR_LIGHTRED,"Vehicle Health: Damaged!!");
               if(health >351) return SendClientMessage(playerid,COLOR_GREEN,"Vehicle Health: Good!!");
            }
            return 1;
        }
        return 1;
}
Reply
#3

You are trying to replicate another servers script but you can't even grasp proper indentation?

Reply
#4

Quote:
Originally Posted by new121
Посмотреть сообщение
You are trying to replicate another servers script but you can't even grasp proper indentation?

Why do you think this is a copy of HBG again,

Nothing of it, I made a command to tell users if the damage of the vehicle.

(HBG have on-screen thing)
Reply
#5

Quote:
Originally Posted by Cypress
Посмотреть сообщение
pawn Код:
if(strcmp(cmd, "/vhealth", true) == 0)
{
        if(IsPlayerConnected(playerid))
        {
            new carid;
            carid = GetPlayerVehicleID(playerid);

            if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "* You are not in a vehicle!");
           
            if(IsAnOwnableCar(carid))
            {
               new Float:health;
               GetVehicleHealth(carid, health);
               if(health <350) return SendClientMessage(playerid,COLOR_LIGHTRED,"Vehicle Health: Damaged!!");
               if(health >351) return SendClientMessage(playerid,COLOR_GREEN,"Vehicle Health: Good!!");
            }
            return 1;
        }
        return 1;
}
Even though this code is good, I would like to point out a few things. The GetVehicleID stuff, should also be inside the isPlayerinAnyVehicle function call. Also, I'd check if the player is NOT connected. It saves you a lot of code and thus making your code more maintainable.
Reply
#6

Problem should be here:
Код:
IsAnOwnableCar(carid)
Also, I don't know why'd you check for IsPlayerConnected..
Reply
#7

pawn Код:
if(strcmp(cmd, "/vhealth", true) == 0)
{
    new carid = GetPlayerVehicleID(playerid);
    if(carid == 0) return SendClientMessage(playerid, COLOR_GREY, "* You are not in a vehicle!");
    if(!IsAnOwnableCar(carid)) return 1;

    new Float:health;
    GetVehicleHealth(carid, health);

    if(health <= 350) return SendClientMessage(playerid,COLOR_LIGHTRED,"Vehicle Health: Damaged!!");
    else return SendClientMessage(playerid,COLOR_GREEN,"Vehicle Health: Good!!");
}
Also at your previous code if health was 350 or 351 it wouldn't say anything.
Smaller and organised.
Reply
#8

pawn Код:
if(strcmp(cmd, "/vhealth", true) == 0)
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_GREY, "* You are not in a vehicle!");
    if(!IsAnOwnableCar(carid)) return 1;

    new carid = GetPlayerVehicleID(playerid);
    new Float:health;
    GetVehicleHealth(carid, health);

    if(health <= 350)
    {
        SendClientMessage(playerid,0xFF0000FF,"Vehicle Health: Damaged!!");
    }
    else return SendClientMessage(playerid,0x00FF00FF,"Vehicle Health: Good!!");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)