Lock vehicle
#1

How can i lock last vehicle?

Well, I want player can lock their vehicle when they are outside. So, I want to get player last vehicle for locking and unlocking.
Reply
#2

We don't know anything from your vehicle system (enums...) so we can't really help you until you provide some codes.
Reply
#3

I don't have anything yet. I want to know how can i do this?
Reply
#4

Save their current vehicle ID in a variable when they enter a vehicle, use it to look it when he's outside..
pretty easy

tell me if you need codes.
Reply
#5

Yes i need codes.
Reply
#6

pawn Код:
new CurrentVehicle[MAX_PLAYERS] = { -1, ... };
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        CurrentVehicle[playerid] = GetPlayerVehicleID(playerid);
    }
    return 1;
}

//When you want to lock the car use CurrentVehicle[playerid] as the vehicle id, make sure it isn't -1 though
CMD:lock(playerid, params[])
{
    if(CurrentVehicle[playerid] != -1)
    {
        for(new i, j = GetPlayerPoolSize(); i <= j; i++) // note that we assign the return value to a new variable (j) to avoid calling the function with each iteration
        {
            if(i != playerid) SetVehicleParamsForPlayer(CurrentVehicle[playerid],i,0,1);
        }
    }
    return 1;
}
Reply
#7

undefined symbol "GetPlayerPoolSize"
Reply
#8

You're not using samp 0.3z R2, update your server or use MAX_PLAYERS or foreach instead.
pawn Код:
new CurrentVehicle[MAX_PLAYERS] = { -1, ... };
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER) CurrentVehicle[playerid] = GetPlayerVehicleID(playerid);

    return 1;
}

//When you want to lock the car use CurrentVehicle[playerid] as the vehicle id, make sure it isn't -1 though
CMD:lock(playerid, params[])
{
    if(CurrentVehicle[playerid] != -1)
    {
        for(new i, j = MAX_PLAYERS; i <= j; i++) // note that we assign the return value to a new variable (j) to avoid calling the function with each iteration
        {
            if(IsPlayerConnected(i) && i != playerid) SetVehicleParamsForPlayer(CurrentVehicle[playerid],i,0,1);
        }
    }
    return 1;
}
Reply
#9

Well, It says locked but i can still enter without unlock? and i m using samp 0.3z R2 now.
Reply
#10

yeah, it's locked for everybody except you, do you wanna lock if for everybody ?

if so, just remove "if(i != playerid)"
or try this
pawn Код:
new CurrentVehicle[MAX_PLAYERS] = { -1, ... };
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER) CurrentVehicle[playerid] = GetPlayerVehicleID(playerid);

    return 1;
}

CMD:lock(playerid, params[])
{
    new vehicleid = CurrentVehicle[playerid];
    if(vehicleid != -1)
    {
        new doors, engine, lights, alarm, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, engine, lights, alarm, VEHICLE_PARAMS_OFF, bonnet, boot, objective);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)