/lock command help
#1

hello i have /lock command to lock vehicle.

pawn Код:
COMMAND:lk(playerid, params[])
{
    return cmd_lock(playerid, params);
}
COMMAND:lock(playerid, params[])
{
    if (PlayerInfo[playerid][pSpawn] == 1)
    {
        new PlayersInVehicle, string[256];

        if (!IsPlayerInAnyVehicle(playerid))
        {
            new VehicleId = GetClosestVehicle(playerid);

            if (VehicleId == INVALID_VEHICLE_ID)
            {
                SendClientMessage(playerid, COLOR_ERROR, "Your Not Close Enough To Activate Your Vehicles Alarm System.");
                return 1;
            }

            for (new i = 0; i < GetMaxPlayers(); i++)
            {
                if (IsPlayerConnected(i))
                {
                    if (i != playerid)
                    {
                        if (IsPlayerInVehicle(i,VehicleId))
                        {
                            PlayersInVehicle ++;
                        }
                    }
                }
            }

            if (PlayersInVehicle > 0)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Cannot Lock A Vehicle While There Is A Player In It.");
                return 1;
            }

            if (CarInfo[VehicleId][cOwned] != -1 && CarInfo[VehicleId][cOwned] != playerid)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
                return 1;
            }

            if (PlayerInfo[playerid][pCar] == 0)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
                return 1;
            }

            if (PlayerInfo[playerid][pCar] != VehicleId)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
                return 1;
            }


            if (CarInfo[VehicleId][cLock] == 1)
            {
                SendClientMessage(playerid, COLOR_ERROR, "The Alarm is Already Activated on this Vehicle.");
                return 1;
            }


            new Float:X, Float:Y, Float:Z;

            PlayerPlaySound(playerid, 1147, X, Y, Z);
            SendClientMessage(playerid, COLOR_SERVER_HELP_MSG, "You have Activated the Alarm System for this Vehicle.");
            GameTextForPlayer(playerid,"~w~Alarm Activated",5000,3);
            CarInfo[VehicleId][cOwned] = playerid;
            CarInfo[VehicleId][cLock] = 1;
            PlayerInfo[playerid][pCar] = VehicleId;

            format(string, sizeof(string), "%s",PlayerInfo[playerid][pName]);
            strmid(CarInfo[CurrentVehicleId][cOwner], string, 0, strlen(string), 256);


        }
        else
        {
            SendClientMessage(playerid, COLOR_ERROR, "You Cannot Activate the Alarm from Inside the Vehicle.");
        }

    }else{
        SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
    }

    return 1;
}
problem is that its get closest vehicle and if 2 vehicles are at same position or distance it do not lock vehicle...
i want to make it with out range of vehicle.

code of closestvehicle

pawn Код:
stock GetClosestVehicle(playerid)
{
    new closest = -1;
    for (new v = 0; v < CurrentVehicleId; v++)
    {

        if (IsPlayerInRangeOfPoint(playerid, 5.0, CarInfo[v][cLocationX],CarInfo[v][cLocationY],CarInfo[v][cLocationZ]))
        {
            closest = v;
        }
    }

    if (closest != -1) return closest;

    return INVALID_VEHICLE_ID;
}
Reply
#2

Quote:
Originally Posted by danish007
Посмотреть сообщение
hello i have /lock command to lock vehicle.

pawn Код:
COMMAND:lk(playerid, params[])
{
    return cmd_lock(playerid, params);
}
COMMAND:lock(playerid, params[])
{
    if (PlayerInfo[playerid][pSpawn] == 1)
    {
        new PlayersInVehicle, string[256];

        if (!IsPlayerInAnyVehicle(playerid))
        {
            new VehicleId = GetClosestVehicle(playerid);

            if (VehicleId == INVALID_VEHICLE_ID)
            {
                SendClientMessage(playerid, COLOR_ERROR, "Your Not Close Enough To Activate Your Vehicles Alarm System.");
                return 1;
            }

            for (new i = 0; i < GetMaxPlayers(); i++)
            {
                if (IsPlayerConnected(i))
                {
                    if (i != playerid)
                    {
                        if (IsPlayerInVehicle(i,VehicleId))
                        {
                            PlayersInVehicle ++;
                        }
                    }
                }
            }

            if (PlayersInVehicle > 0)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Cannot Lock A Vehicle While There Is A Player In It.");
                return 1;
            }

            if (CarInfo[VehicleId][cOwned] != -1 && CarInfo[VehicleId][cOwned] != playerid)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
                return 1;
            }

            if (PlayerInfo[playerid][pCar] == 0)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
                return 1;
            }

            if (PlayerInfo[playerid][pCar] != VehicleId)
            {
                SendClientMessage(playerid, COLOR_ERROR, "You Must Own a Vehicle to Set the Alarm System.");
                return 1;
            }


            if (CarInfo[VehicleId][cLock] == 1)
            {
                SendClientMessage(playerid, COLOR_ERROR, "The Alarm is Already Activated on this Vehicle.");
                return 1;
            }


            new Float:X, Float:Y, Float:Z;

            PlayerPlaySound(playerid, 1147, X, Y, Z);
            SendClientMessage(playerid, COLOR_SERVER_HELP_MSG, "You have Activated the Alarm System for this Vehicle.");
            GameTextForPlayer(playerid,"~w~Alarm Activated",5000,3);
            CarInfo[VehicleId][cOwned] = playerid;
            CarInfo[VehicleId][cLock] = 1;
            PlayerInfo[playerid][pCar] = VehicleId;

            format(string, sizeof(string), "%s",PlayerInfo[playerid][pName]);
            strmid(CarInfo[CurrentVehicleId][cOwner], string, 0, strlen(string), 256);


        }
        else
        {
            SendClientMessage(playerid, COLOR_ERROR, "You Cannot Activate the Alarm from Inside the Vehicle.");
        }

    }else{
        SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
    }

    return 1;
}
problem is that its get closest vehicle and if 2 vehicles are at same position or distance it do not lock vehicle...
i want to make it with out range of vehicle.

code of closestvehicle

pawn Код:
stock GetClosestVehicle(playerid)
{
    new closest = -1;
    for (new v = 0; v < CurrentVehicleId; v++)
    {

        if (IsPlayerInRangeOfPoint(playerid, 5.0, CarInfo[v][cLocationX],CarInfo[v][cLocationY],CarInfo[v][cLocationZ]))
        {
            closest = v;
        }
    }

    if (closest != -1) return closest;

    return INVALID_VEHICLE_ID;
}
My stock from my script, works perfectly without any problems:

Код:
stock GetClosestCar(playerid, exception = INVALID_VEHICLE_ID) {

    new Float: Distance, target = -1, Float: vPos[3];
	if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, vPos[0], vPos[1], vPos[2]);
	else GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]);

    for(new v; v < MAX_VEHICLES; v++) if(GetVehicleModel(v) >= 400) {
        if(v != exception && (target < 0 || Distance > GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]))) {
            target = v;
            Distance = GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]);
        }
    }
    return target;
}
Reply
#3

i dont want to make with distance or range i want to remove closest vehicle and want to make it if anyone type /lock anywhere his vehicle should be locked
Reply
#4

Try this
pawn Код:
native IsValidVehicle(vehicleid);//under includes on top of script THIS IS IMPORTANT


COMMAND:lk(playerid, params[])
{
    return cmd_lock(playerid, params);
}
COMMAND:lock(playerid, params[])
{
    if (PlayerInfo[playerid][pSpawn] == 1)
    {
        new PlayersInVehicle, string[256];

        if (!IsPlayerInAnyVehicle(playerid))
        {
           new VehicleId = PlayerInfo[playerid][pCar];
           if(!IsValidVehicle(VehicleId))return SendClientMessage(playerid, COLOR_ERROR, "You dont own any vehicle");

           for (new i = 0; i < GetMaxPlayers(); i++)
            {
                if (IsPlayerConnected(i))
                {
                    if (i != playerid)
                    {
                        if (IsPlayerInVehicle(i,VehicleId))
                        {
                            PlayersInVehicle ++;
                        }
                    }
                }
            }

            if (CarInfo[VehicleId][cLock] == 1)
            {
                SendClientMessage(playerid, COLOR_ERROR, "The Alarm is Already Activated on this Vehicle.");
                return 1;
            }

            PlayerPlaySound(playerid, 1147, 0.0, 0.0, 0.0);
            SendClientMessage(playerid, COLOR_SERVER_HELP_MSG, "You have Activated the Alarm System for this Vehicle.");
            GameTextForPlayer(playerid,"~w~Alarm Activated",5000,3);
            CarInfo[VehicleId][cOwned] = playerid;
            CarInfo[VehicleId][cLock] = 1;
            PlayerInfo[playerid][pCar] = VehicleId;
            format(string, sizeof(string), "%s",PlayerInfo[playerid][pName]);
            strmid(CarInfo[CurrentVehicleId][cOwner], string, 0, strlen(string), 256);


        }
        else
        {
            SendClientMessage(playerid, COLOR_ERROR, "You Cannot Activate the Alarm from Inside the Vehicle.");
        }

    }else{
        SendClientMessage(playerid, COLOR_ERROR, "You Cannot Use This Command When You're Dead.");
    }

    return 1;
}
And you can simply do PlayerPlaySound(playerid, 1147, 0.0, 0.0, 0.0); you don't need to declare variable like XYZ and then put in the function as its parameter
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)