Help with car locks
#1

My question here is how to reapply this function below when "OnVehicleStreamIn " is called. Otherwise this doesn't work.

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext,"/lock",true)) 
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(i == playerid) continue;
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
        }
        return 1;
    }
    return 0;
}
I've tried this

Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
	SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
}
and doesn't work, I'm a begginer here so any suggestion will be appreciated.
Reply
#2

What doesn't work about it? Is the vehicle locked or not locked? Give us some more details

I'm guessing the best way of making a locking system though would be to create a variable in which you store if a vehicle is locked or not. For example:

pawn Код:
new vLocked[MAX_VEHICLES] = -1;
You might want to make your own define for how many vehicles you have to optimize things.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext,"/lock",true))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(i == playerid) continue;
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
        }
        vLocked[GetPlayerVehicleID(playerid)] = playerid;
        return 1;
    }
    return 0;
}
pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(vLocked[vehicleid] != forplayerid && vLocked[vehicleid] != -1) SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
    return 1;
}
Note: I use -1 because I store the playerid so we know not to lock it for the person who locked it in the first place
Reply
#3

I try that and when I lock a car, all the cars get lock! and just me can open them xD really weird
Reply
#4

i thinks its because he set the vlocked outside of the checks.

pawn Код:
if(!strcmp(cmdtext,"/lock",true))
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(i == playerid) continue;
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
            vLocked[GetPlayerVehicleID(playerid)] = playerid;
        }
        return 1;
    }
Reply
#5

Nope doesn't work still the same problem all the cars are lock and only the player with the id 0 can drive them :S any help here?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)