Detecting if a player is in their owned vehicle REP+
#1

Hey, how can I detect if a player is in their owned vehicle, for example I need it so they can only use certain commands in there OWN vehicle, like /lock, /savecar etc

Would I use like

new vehid = GetPlayerVehicleID(playerid);
if(PlayerInfo[playerid][Vehicle] != vehid); well, you get my point.
Reply
#2

Depends on how u save the car id of the player
Reply
#3

I save the car id in their player variable..

This forum requires that you wait 120 seconds between posts. Please try again in 15 seconds.
Reply
#4

yes then that would be a way to do it
Reply
#5

personaly I use this:

pawn Код:
if(ispr[GetPlayerVehicleID(playerid)] == 1)
    {
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        if(PlayerInfo[playerid][Pid] == CarInfo[CarID][Carid] || PlayerInfo[playerid][Vehkey] == CarInfo[CarID][Carid] || PlayerInfo[playerid][Vehkey2] == CarInfo[CarID][Carid] || PlayerInfo[playerid][Vehkey3] == CarInfo[CarID][Carid])
        {
            SendClientMessage(playerid, COLOR_ORANGE, "Welcome back to your vehicle!");
        }
        else
        {
            RemovePlayerFromVehicle(playerid);
            TogglePlayerControllable(playerid, 1);
            SendClientMessage(playerid, 0x999999AA, "You don't have the key of this vehicle.");
        }
    }
different style of scripting
Reply
#6

Heres my CMD:
pawn Код:
CMD:savemycar(playerid,params[])
{
    if(PlayerInfo[playerid][Vehicle] != GetPlayerVehicleID(playerid)) return SendClientMessage(playerid,-1,EMBED_RED"[ERROR]: "EMBED_WHITE"You need to be in your vehicle.");
    new Float:cp[3];
    GetPlayerPos(playerid,cp[0],cp[1],cp[2]);
    PlayerInfo[playerid][CarX] = cp[0];
    PlayerInfo[playerid][CarY] = cp[1];
    PlayerInfo[playerid][CarZ] = cp[2];
    SendClientMessage(playerid,COLOR_GRAY,">> Vehicle Saved");
    return 1;
}
But Yet I go in game to my purchased vehicle, and type /savemycar but yet it says I need to be in my vehicle.
Reply
#7

Quote:
Originally Posted by Azzeto
Посмотреть сообщение
Heres my CMD:
pawn Код:
CMD:savemycar(playerid,params[])
{
    if(PlayerInfo[playerid][Vehicle] != GetPlayerVehicleID(playerid)) return SendClientMessage(playerid,-1,EMBED_RED"[ERROR]: "EMBED_WHITE"You need to be in your vehicle.");
    new Float:cp[3];
    GetPlayerPos(playerid,cp[0],cp[1],cp[2]);
    PlayerInfo[playerid][CarX] = cp[0];
    PlayerInfo[playerid][CarY] = cp[1];
    PlayerInfo[playerid][CarZ] = cp[2];
    SendClientMessage(playerid,COLOR_GRAY,">> Vehicle Saved");
    return 1;
}
But Yet I go in game to my purchased vehicle, and type /savemycar but yet it says I need to be in my vehicle.
uhmm, I think that should work yeah. Not sure if the PlayerInfo[ blabla can read directly from floats..
might want to set it to the save file(ini, or SQL)
Reply
#8

The car save position works great, I just cant figure out to check if there in there car/savemycar and their car will get saved there, I want it so they have to be in THERE car, not any other vehicle, I just can't figure the sensable way to do it.
Reply
#9

Make a variable for the car, that would hold the name of the car owner. Make it, so the variable saves and then check if the player is in his car.
Reply
#10

Show us buy vehicle cmd
Reply
#11

I'm not having issues with the buy car.. i'm having issues detecting if the player is in there car, but here

pawn Код:
CMD:buycar(playerid,params[])
{
    if(CARSPAWNED[playerid] == 1) return SendClientMessage(playerid,-1,EMBED_RED"[ERROR]: You must have your car despawned before purchasing a new one!");
    new car = GetPlayerVehicleID(playerid);
    if(car == dealercar[0])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"hotring"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 494;
        PlayerInfo[playerid][Money] -= 120000;
        CreateVehicle(494,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[1])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"cheetah"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 415;
        PlayerInfo[playerid][Money] -= 90000;
        CreateVehicle(415,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[2])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"banshee"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 429;
        PlayerInfo[playerid][Money] -= 100000;
        CreateVehicle(429,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[3])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"bullet"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 541;
        PlayerInfo[playerid][Money] -= 105000;
        CreateVehicle(541,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[4])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"buffalo"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 402;
        PlayerInfo[playerid][Money] -= 92000;
        CreateVehicle(402,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[5])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"ZR-350"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 477;
        PlayerInfo[playerid][Money] -= 85000;
        CreateVehicle(477,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[6])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"windsor"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 555;
        PlayerInfo[playerid][Money] -= 250000;
        CreateVehicle(555,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[7])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"FCR-900"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 521;
        PlayerInfo[playerid][Money] -= 75000;
        CreateVehicle(521,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[8])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"NRG-900"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 522;
        PlayerInfo[playerid][Money] -= 98000;
        CreateVehicle(522,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[9])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"freeway"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 463;
        PlayerInfo[playerid][Money] -= 75000;
        CreateVehicle(463,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[10])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"wayfarer"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 486;
        PlayerInfo[playerid][Money] -= 43000;
        CreateVehicle(486,-1969.5432,258.5425,34.7968,358.2475,0,0,99999);
    }
    if(car == dealercar[11])
    {
        SendClientMessage(playerid,-1,EMBED_CYAN"[DEALERSHIP]: "EMBED_WHITE"You've purchased a "EMBED_GREEN"PCJ-600"EMBED_WHITE".");
        PlayerInfo[playerid][Vehicle] = 461;
        PlayerInfo[playerid][Money] -= 88000;
        CreateVehicle(461,-1969.5432,258.5425,34.7968,358.2475,0,0,999999);
    }
    CARSPAWNED[playerid] = 1;
    RemovePlayerFromVehicle(playerid);
    SetTimer("Unfreeze",1500,0);
    return 1;
}
Reply
#12

Bump?
Reply
#13

Another bump.. I need help ASAP...
Reply
#14

just use onplayerstatechange then check if

GetPlayerVehicleID(playerid) == dealercar

and

GetPlayerVehicleID(playerid) == PlayerInfo[playerid][vehicle]
Reply
#15

Heres my /savemycar cmd, but it doesn't work when I add if(GetPlayerVehicleID blah blah)
pawn Код:
CMD:savemycar(playerid,params[])
{
    new Float:cp[4];
    if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][Vehicle])
    {
        GetPlayerPos(playerid,cp[0],cp[1],cp[2]);
        PlayerInfo[playerid][CarX] = cp[0];
        PlayerInfo[playerid][CarY] = cp[1];
        PlayerInfo[playerid][CarZ] = cp[2];
        PlayerInfo[playerid][CarA] = cp[3];
        SendClientMessage(playerid,COLOR_GRAY,">> Vehicle Saved");
    }
    return 1;
}
Why?
Reply
#16

dont use the return 1, use

pawn Код:
else return SendClientMessage(playerid, *ur color here*, "You are not in your own vehicle!");
Reply
#17

Quote:
Originally Posted by Azzeto
Посмотреть сообщение
Heres my /savemycar cmd, but it doesn't work when I add if(GetPlayerVehicleID blah blah)
pawn Код:
CMD:savemycar(playerid,params[])
{
    new Float:cp[4];
    if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][Vehicle])
    {
        GetPlayerPos(playerid,cp[0],cp[1],cp[2]);
        PlayerInfo[playerid][CarX] = cp[0];
        PlayerInfo[playerid][CarY] = cp[1];
        PlayerInfo[playerid][CarZ] = cp[2];
        PlayerInfo[playerid][CarA] = cp[3];
        SendClientMessage(playerid,COLOR_GRAY,">> Vehicle Saved");
    }
    return 1;
}
Why?
Because PlayerInfo[playerid][Vehicle] stores the model of the vehicle and not the id.
pawn Код:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == PlayerInfo[playerid][Vehicle])
{
    //code
}
Reply
#18

Quote:
Originally Posted by Fj0rtizFredde
Посмотреть сообщение
Because PlayerInfo[playerid][Vehicle] stores the model of the vehicle and not the id.
pawn Код:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == PlayerInfo[playerid][Vehicle])
{
    //code
}
my fault, thought vehilce was the id

My way of doing this:

pawn Код:
CMD:park(playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][Vehkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][Vehkey2] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][Vehkey3]))
        {
            new videoid = GetPlayerVehicleID(playerid)
            new Float:ux, Float:uy, Float:uz, Float:angle;
            new string[128], vehicle[24];
            GetVehicleName(videoid, vehicle, sizeof(vehicle));
            GetPlayerFacingAngle(playerid, angle);
            GetPlayerPos(playerid, ux, uy, uz);
            format(file4, sizeof(file4), "realityrp/vehicles/%d.ini", videoid);
            dini_FloatSet(file4, "vehx", ux);
            dini_FloatSet(file4, "vehy", uy);
            dini_FloatSet(file4, "vehz", uz);
            dini_FloatSet(file4, "rot", angle);
            format(string, sizeof(string), "You parked your %s here! ((It will respawn here on death))", vehicle);
            SendClientMessage(playerid, COLOR_GREEN, string);
            return 1;
        }
        else return SendClientMessage(playerid, COLOR_GREY, "This is not your vehicle!");
    }
    else return SendClientMessage(playerid, COLOR_GREY, "You are not in your vehicle!");
}
Reply
#19

Fredde.. I just want to say I love you, repped.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)