SA-MP Forums Archive
Vehicle Health Command, Is broken, Need help !! - 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: Vehicle Health Command, Is broken, Need help !! (/showthread.php?tid=377061)



Vehicle Health Command, Is broken, Need help !! - UnknownGamer - 12.09.2012

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.


Re: Vehicle Health Command, Is broken, Need help !! - Cypress - 12.09.2012

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



Re: Vehicle Health Command, Is broken, Need help !! - new121 - 14.09.2012

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




Re: Vehicle Health Command, Is broken, Need help !! - UnknownGamer - 14.09.2012

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)


Re: Vehicle Health Command, Is broken, Need help !! - mamorunl - 14.09.2012

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.


Re: Vehicle Health Command, Is broken, Need help !! - Seven_of_Nine - 14.09.2012

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


Re: Vehicle Health Command, Is broken, Need help !! - Dark_Kostas - 14.09.2012

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.


Re: Vehicle Health Command, Is broken, Need help !! - clarencecuzz - 14.09.2012

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