new playersvehicle[MAX_PLAYERS], locked[MAX_VEHICLES char], one[MAX_PLAYERS];
one[playerid] = 0; playersvehicle[playerid] = -1; locked[playersvehicle[playerid]] = 0;
CMD:lock(playerid,params[]) { if(UserStats[playerid][Logged] == false) return SendClientMessage(playerid, COLOR_RED, "Must be logged in!"); if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must be in vehicle!"); if(locked[GetPlayerVehicleID(playerid)] == 1) return SendClientMessage(playerid, COLOR_RED, "This vehicle is already locked!"); if(one[playerid] == 1) return SendClientMessage(playerid, COLOR_RED, "You already have one locked vehicle, use /getcar and /unlock!"); if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED, "You must be driver to use this command!"); locked[GetPlayerVehicleID(playerid)] = 1; one[playerid] = 1; playersvehicle[playerid] = GetPlayerVehicleID(playerid); SendClientMessage(playerid, COLOR_GREEN, "^ Locked!"); return 1; }
CMD:unlock(playerid,params[]) { if(UserStats[playerid][Logged] == false) return SendClientMessage(playerid, COLOR_RED, "You must be logged in!"); if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "You must be in vehicle"); if(aizslegts[GetPlayerVehicleID(playerid)] == 0) return SendClientMessage(playerid, COLOR_RED, "This vehicle is already unlocked!"); if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED, "You must be driver to use this command!"); locked[GetPlayerVehicleID(playerid)] = 0; one[playerid] = 0; playersvehicle[playerid] = -1; SendClientMessage(playerid, COLOR_GREEN, "^ Unlocked!"); return 1; }
Under OnPlayerDisconnect:
Код:
one[playerid] = 0; playersvehicle[playerid] = -1; locked[playersvehicle[playerid]] = 0; |
// OnPlayerDisconnect: if (playersvehicle[playerid] != -1) // if there is a vehicle stored { if (locked{playersvehicle[playerid]} == 1) // and it's locked | notice how { } are used for char-arrays { locked{playersvehicle[playerid]} = 0; // it is now unlocked for whoever try to enter it, assuming you only need the variable to check in OnPlayerEnterVehicle/OnPlayerStateChange } playersvehicle[playerid] = -1; }
// command /lock if(locked{GetPlayerVehicleID(playerid)} == 1) return SendClientMessage(playerid, COLOR_RED, "This vehicle is already locked!"); ... locked{GetPlayerVehicleID(playerid)} = 1;
// command /unlock if(locked{GetPlayerVehicleID(playerid)} == 0) return SendClientMessage(playerid, COLOR_RED, "This vehicle is already unlocked!"); ... locked{GetPlayerVehicleID(playerid)} = 0;