Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ###########################################
- Car lock and unlock by tony tony
- ############################################
- */
- #include <a_samp>
- #define COLOR_YELLOW 0xFFFF00AA
- new locked[MAX_PLAYERS][MAX_VEHICLES];
- new vehid[MAX_PLAYERS];
- new unlocktimer;
- forward unlock(playerid,vehicleid);
- public OnPlayerDisconnect(playerid)
- {
- new i2;
- for(i2=0;i2<MAX_VEHICLES;i2++)
- {
- if (locked[playerid][i2] == 1)
- {
- new i;
- for(i=0;i<MAX_PLAYERS;i++)
- {
- SetVehicleParamsForPlayer(i2,i, 0, 0);
- }
- }
- locked[playerid][i2] = 0;
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp(cmdtext, "/lock", true)==0)
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- new State=GetPlayerState(playerid);
- if(State!=PLAYER_STATE_DRIVER)
- {
- SendClientMessage(playerid,0xFFFF00AA,"You can only lock the doors as the driver.");
- return 1;
- }
- new i;
- for(i=0;i<MAX_PLAYERS;i++)
- {
- if(i != playerid)
- {
- SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
- }
- }
- SendClientMessage(playerid, 0xFFFF00AA, "Vehicle locked!");
- new Float:pX, Float:pY, Float:pZ;
- GetPlayerPos(playerid,pX,pY,pZ);
- PlayerPlaySound(playerid,1056,pX,pY,pZ);
- locked[playerid][GetPlayerVehicleID(playerid)] = 1;
- }
- else
- {
- SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
- }
- return 1;
- }
- if (strcmp(cmdtext, "/unlock", true)==0)
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- new State=GetPlayerState(playerid);
- if(State!=PLAYER_STATE_DRIVER)
- {
- SendClientMessage(playerid,0xFFFF00AA,"You can only lock the doors as the driver.");
- return 1;
- }
- new i;
- for(i=0;i<MAX_PLAYERS;i++)
- {
- SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
- }
- SendClientMessage(playerid, 0xFFFF00AA, "Vehicle unlocked!");
- new Float:pX, Float:pY, Float:pZ;
- GetPlayerPos(playerid,pX,pY,pZ);
- PlayerPlaySound(playerid,1057,pX,pY,pZ);
- locked[playerid][GetPlayerVehicleID(playerid)] = 0;
- }
- else
- {
- SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
- }
- return 1;
- }
- return 0;
- }
- public OnPlayerEnterVehicle(playerid,vehicleid)
- {
- vehid[playerid] = vehicleid;
- return 1;
- }
- public OnPlayerStateChange(playerid,newstate,oldstate)
- {
- if(oldstate == PLAYER_STATE_DRIVER)
- {
- if (locked[playerid][vehid[playerid]] == 1)
- {
- unlocktimer = SetTimerEx("unlock",300000,false,"ii",playerid,vehid[playerid]);
- SendClientMessage(playerid,COLOR_YELLOW,"This vehicle will be automatic unlocked in 5 minutes.");
- locked[playerid][vehid[playerid]] = 2;
- }
- }
- if (newstate == PLAYER_STATE_DRIVER)
- {
- if (locked[playerid][vehid[playerid]] == 2)
- {
- KillTimer(unlocktimer);
- locked[playerid][vehid[playerid]] = 1;
- new Float:pX, Float:pY, Float:pZ;
- GetPlayerPos(playerid,pX,pY,pZ);
- PlayerPlaySound(playerid,1056,pX,pY,pZ);
- SendClientMessage(playerid,COLOR_YELLOW,"This vehicle is locked.");
- }
- }
- return 1;
- }
- public unlock(playerid,vehicleid)
- {
- new i;
- for(i=0;i<MAX_PLAYERS;i++)
- {
- SetVehicleParamsForPlayer(vehicleid,i, 0, 0);
- }
- locked[playerid][vehicleid] = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement