/lock Command Help
#1

Hello

I am just wondering if anyone can guide me in the right direction to look at a decent tutorial on how to /lock to lock/unlock your car.....

Much appreciated


Thank You


Please Help Me Please
Reply
#2

Have a variable that indicates the player's owned vehicle ID, check the example below. If a player buys a vehicle, the variable would be changed to the vehicle's ID.

For example:
pawn Код:
// place this under OnPlayerConnect()
PlayerStats[playerid][VehicleKey] = INVALID_VEHICLE_ID // alternatively, you can set it to -1
After buying a vehicle, set this variable to the vehicle's ID, in this case, the player needs to be on the driver's seat for him/her to be able to buy it.
pawn Код:
// this would be under the command for buying a vehicle
new vehicle = GetPlayerVehicleID(playerid);
PlayerStats[playerid][VehicleKey] = vehicle;
Now, for the lock, you'll have to get the player's vehicle position to determine whether it's within range or not.
pawn Код:
new Float:vPos[3];
GetVehiclePos(PlayerStats[playerid][VehicleKey], vPos[0], vPos[1], vPos[2]);
Checking if it's within range:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 5.0, vPos[0], vPos[1], vPos[2]))
{

}
The code for locking/unlocking your vehicle:
pawn Код:
new engine, lights, alarm, doors, hood, trunk, objective;
SetVehicleParamsEx(PlayerStats[playerid][VehicleKey], engine, lights, alarm, VEHICLE_PARAMS_ON, hood, trunk, objective);
The code above would lock the vehicle, you can change the "doors" parameter to VEHICLE_PARAMS_OFF for unlocking it.
Reply
#3

Quote:
Originally Posted by Skribblez
Посмотреть сообщение
Have a variable that indicates the player's owned vehicle ID, check the example below. If a player buys a vehicle, the variable would be changed to the vehicle's ID.

For example:
pawn Код:
// place this under OnPlayerConnect()
PlayerStats[playerid][VehicleKey] = INVALID_VEHICLE_ID // alternatively, you can set it to -1
After buying a vehicle, set this variable to the vehicle's ID, in this case, the player needs to be on the driver's seat for him/her to be able to buy it.
pawn Код:
// this would be under the command for buying a vehicle
new vehicle = GetPlayerVehicleID(playerid);
PlayerStats[playerid][VehicleKey] = vehicle;
Now, for the lock, you'll have to get the player's vehicle position to determine whether it's within range or not.
pawn Код:
new Float:vPos[3];
GetVehiclePos(PlayerStats[playerid][VehicleKey], vPos[0], vPos[1], vPos[2]);
Checking if it's within range:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 5.0, vPos[0], vPos[1], vPos[2]))
{

}
The code for locking/unlocking your vehicle:
pawn Код:
new engine, lights, alarm, doors, hood, trunk, objective;
SetVehicleParamsEx(PlayerStats[playerid][VehicleKey], engine, lights, alarm, VEHICLE_PARAMS_ON, hood, trunk, objective);
The code above would lock the vehicle, you can change the "doors" parameter to VEHICLE_PARAMS_OFF for unlocking it.
Thank You Very Much For The Reply

Im just wondering is there any way immediately after you buy it from the dealer ship it will make you owner of the car


Thank You


Please Help Me Please
Reply
#4

That's what the second code is for. Although, you must implement the vehicle dealership system first before doing the lock system. You should also have enumerations for vehicles so that you could have a variable which indicates the owner of the vehicle using the player's name. So something like:

pawn Код:
VehicleStats[vehicleid][Owner]
Reply
#5

Quote:
Originally Posted by Skribblez
Посмотреть сообщение
That's what the second code is for. Although, you must implement the vehicle dealership system first before doing the lock system. You should also have enumerations for vehicles so that you could have a variable which indicates the owner of the vehicle using the player's name. So something like:

pawn Код:
VehicleStats[vehicleid][Owner]
Sorry i am kind of new to scripting how would i put this in


If you need any part of my code just ask


Thank You


Please Help Me Please
Reply
#6

Well, having a lock system would be kind of long if it would only be possible for bought vehicles. If you already have an existing lock command and vehicle dealership system, post your codes. Include the enums that you've used for the vehicles and players.
Reply
#7

Quote:
Originally Posted by Skribblez
Посмотреть сообщение
Well, having a lock system would be kind of long if it would only be possible for bought vehicles. If you already have an existing lock command and vehicle dealership system, post your codes. Include the enums that you've used for the vehicles and players.
Here


pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pTutorial,
    pSex,
    pAge,
Float:pPos_x,
Float:pPos_y,
Float:pPos_z,
      pSkin,
      pTeam,
      pAccent,
      pFrozen,
      PCarMods
}

pawn Код:
CMD:buyvehicle(playerid, params[])
    {
        if(IsPlayerInRangeOfPoint(playerid, 1, -2235.4712,130.2268,1035.41, -1))
            ShowPlayerDialog(playerid, DIALOG_BUYVEHICLE, DIALOG_STYLE_LIST, "Car Menu", "Casual Cars\nSports Cars\nVIP Cars\nSpecial Deals", "Select", "Cancel");
        else
            return SendClientMessage(playerid, 0xFF0000FF, "You are not in the dealer ship");
        return 1;
    }
pawn Код:
if(dialogid == DIALOG_BUYVEHICLE)
    {
        if(response)
        {
            if(listitem == 0)
            {
                ShowPlayerDialog(playerid, DIALOG_CASUALVEHICLEMENU, DIALOG_STYLE_LIST, "Casual Car Menu", "TEST CAR - SENITAL", "Buy", "Cancel");
            }
        }
    return 1;
    }
    if(dialogid == DIALOG_CASUALVEHICLEMENU)
    {
        if(response)
        {
            if(listitem == 0)
            {
                CreateVehicle(405, 540.0750,-1281.7159,17.2422,309.3207, 0, 1, 0);
            }
        }
        return 1;
    }

Thank You


Please Help Me Please
Reply
#8

pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pTutorial,
    pSex,
    pAge,
    Float:pPos_x,
    Float:pPos_y,
    Float:pPos_z,
    pSkin,
    pTeam,
    pAccent,
    pFrozen,
    PCarMods,
    pVehicle, // added this, the variable to store the player's vehicle ID
};
// i'll assume that you're also using PlayerInfo
new PlayerInfo[MAX_PLAYERS][pInfo];
pawn Код:
if(dialogid == DIALOG_BUYVEHICLE)
{
    if(response)
    {
        if(listitem == 0)
        {
            ShowPlayerDialog(playerid, DIALOG_CASUALVEHICLEMENU, DIALOG_STYLE_LIST, "Casual Car Menu", "TEST CAR - SENITAL", "Buy", "Cancel");
        }
    }
    return 1;
}

if(dialogid == DIALOG_CASUALVEHICLEMENU)
{
    if(response)
    {
        if(listitem == 0)
        {
            new vehicle; // added this
            vehicle = CreateVehicle(405, 540.0750,-1281.7159,17.2422,309.3207, 0, 1, 0);
            // lines added below
            PutPlayerInVehicle(playerid, vehicle, 0);
            new PlayerVehicle = GetPlayerVehicleID(playerid);
            PlayerInfo[playerid][pVehicle] = PlayerVehicle;
        }
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Skribblez
Посмотреть сообщение
pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pTutorial,
    pSex,
    pAge,
    Float:pPos_x,
    Float:pPos_y,
    Float:pPos_z,
    pSkin,
    pTeam,
    pAccent,
    pFrozen,
    PCarMods,
    pVehicle, // added this, the variable to store the player's vehicle ID
};
// i'll assume that you're also using PlayerInfo
new PlayerInfo[MAX_PLAYERS][pInfo];
pawn Код:
if(dialogid == DIALOG_BUYVEHICLE)
{
    if(response)
    {
        if(listitem == 0)
        {
            ShowPlayerDialog(playerid, DIALOG_CASUALVEHICLEMENU, DIALOG_STYLE_LIST, "Casual Car Menu", "TEST CAR - SENITAL", "Buy", "Cancel");
        }
    }
    return 1;
}

if(dialogid == DIALOG_CASUALVEHICLEMENU)
{
    if(response)
    {
        if(listitem == 0)
        {
            new vehicle; // added this
            vehicle = CreateVehicle(405, 540.0750,-1281.7159,17.2422,309.3207, 0, 1, 0);
            // lines added below
            PutPlayerInVehicle(playerid, vehicle, 0);
            new PlayerVehicle = GetPlayerVehicleID(playerid);
            PlayerInfo[playerid][pVehicle] = PlayerVehicle;
        }
    }
    return 1;
}
I still dont quite understand it how will this make it so it when i do /lock it will lock it or unlock it


Also how will it make who ever bought it the owner of the car


Thank You


Please Help Me Please
Reply
#10

This is just the first part where only the owner of the vehicle can lock or unlock the vehicle, unless you're satisfied with anyone being able to lock or unlock any vehicle.

Like I said, if you want a vehicle system with ownership, then enumerate another set of variables for vehicles such as the "pInfo" that you've made.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)