Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Ultimate Vehicle Control=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Credits: Babica=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Do Not Remove Credits Please=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Includes=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #include <a_samp>
- #include <zcmd>
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Defines=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- #define FILTERSCRIPT
- #if defined FILTERSCRIPT
- #define PRESSED(%0) \
- (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- #define BLINK_RATE 400
- #define PFLASH_RATE 300
- #define LIGHT_KEY KEY_SUBMISSION
- #define COLOR_PURPLE 0xC2A2DAAA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_LIGHTRED 0xFF6347AA
- #define COLOR_ROSUAPRINS 0xE80000FF
- #define COLOR_BLUE 0x2641FEAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_2RED 0xFF0606FF
- #define SCM SendClientMessage
- new engine,lights,alarm,doors,bonnet,boot,objective;
- new BlinkTime[MAX_PLAYERS];
- new EngineStatus[MAX_PLAYERS];
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnFilterScriptInit=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" Vehicle Control By Mr.Babica");
- print("--------------------------------------\n");
- return 1;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnFilterScriptExit=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- public OnFilterScriptExit()
- {
- return 1;
- }
- #else
- main()
- {
- print("\n----------------------------------");
- print(" Vehicle Control By Babica");
- print("----------------------------------\n");
- }
- #endif
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerConnect=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- public OnPlayerConnect(playerid)
- {
- EngineStatus[playerid] = 0;
- return 1;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerEnterVehicle=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- if(!ispassenger)
- {
- GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
- EngineStatus[playerid] = 0;
- }
- return 1;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerStateChange=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER)
- {
- new panels,tires;
- new carid = GetPlayerVehicleID(playerid);
- GetVehicleDamageStatus(carid, panels, doors, lights, tires);
- lights = encode_lights(1, 1, 1, 1);
- SetPVarInt(playerid, "vMainOn", 0);
- UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
- }
- else if(newstate == PLAYER_STATE_ONFOOT)
- {
- KillTimer(BlinkTime[playerid]);
- SetPVarInt(playerid, "CopFlash", 0);
- }
- return 1;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerKeyStateChange=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(PRESSED(LIGHT_KEY))
- {
- if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
- {
- if(GetPVarInt(playerid, "CopFlash") == 0)
- {
- new panels,tires;
- new carid = GetPlayerVehicleID(playerid);
- GetVehicleDamageStatus(carid, panels, doors, lights, tires);
- switch(GetPVarInt(playerid, "vMainOn"))
- {
- case 0:{
- lights = encode_lights(0, 0, 0, 0);
- SetPVarInt(playerid, "vMainOn", 1);
- }
- case 1:{
- lights = encode_lights(1, 1, 1, 1);
- SetPVarInt(playerid, "vMainOn", 0);
- }
- }
- UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
- }
- }
- }
- if(PRESSED(KEY_CROUCH))
- {
- if(IsPublicService(GetPlayerVehicleID(playerid)) && GetPlayerVehicleSeat(playerid) == 0)
- {
- switch(GetPVarInt(playerid, "CopFlash"))
- {
- case 0:{
- KillTimer(BlinkTime[playerid]);
- BlinkTime[playerid] = SetTimerEx("vBlinker", PFLASH_RATE, 1, "i", playerid);
- SetPVarInt(playerid, "CopFlash", 1);
- }
- case 1:{
- KillTimer(BlinkTime[playerid]);
- new panels,tires;
- new carid = GetPlayerVehicleID(playerid);
- GetVehicleDamageStatus(carid, panels, doors, lights, tires);
- lights = encode_lights(1, 1, 1, 1);
- UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
- SetPVarInt(playerid, "CopFlash", 0);
- }
- }
- }
- }
- new vehicleid = GetPlayerVehicleID(playerid);
- GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- if(PRESSED(KEY_ANALOG_UP))
- {
- if(GetPVarInt(playerid, "Bonnet") == 0)
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,true,boot,objective);
- SetPVarInt(playerid, "Bonnet", 1);
- }
- else if(GetPVarInt(playerid, "Bonnet") == 1)
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,false,boot,objective);
- SetPVarInt(playerid, "Bonnet", 0);
- }
- }
- if(PRESSED(KEY_ANALOG_DOWN))
- {
- if(GetPVarInt(playerid, "Boot") == 0)
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,true,objective);
- SetPVarInt(playerid, "Boot", 1);
- }
- else if(GetPVarInt(playerid, "Boot") == 1)
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,false,objective);
- SetPVarInt(playerid, "Boot", 0);
- }
- }
- if (PRESSED(KEY_NO))
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- new veh = GetPlayerVehicleID(playerid);
- if(veh != INVALID_VEHICLE_ID)
- {
- if(EngineStatus[playerid] == 0 && (GetPlayerState(playerid)==PLAYER_STATE_DRIVER))
- {
- new string[256];
- new sendername[MAX_PLAYER_NAME];
- GetPlayerName(playerid, sendername, sizeof(sendername));
- GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
- SetVehicleParamsEx(veh,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
- EngineStatus[playerid] = 1;
- SendClientMessage(playerid, 0xFFFFFFAA, "{FFFFFF}You have {2F991A}turn off {FFFFFF} engine!");
- format(string, sizeof(string), "* %s turn on engine.", sendername);
- ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
- }
- else if(EngineStatus[playerid] == 1 && (GetPlayerState(playerid)==PLAYER_STATE_DRIVER))
- {
- new string[256];
- new sendername[MAX_PLAYER_NAME];
- GetPlayerName(playerid, sendername, sizeof(sendername));
- GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
- SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
- EngineStatus[playerid] = 0;
- SendClientMessage(playerid, 0xFFFFFFAA, "{FFFFFF}You have {E31919}turn on {FFFFFF} engine!");
- format(string, sizeof(string), "* %s turn off engine.", sendername);
- ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
- }
- }
- }
- }
- return 1;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=ProxDetector=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
- public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
- {
- if(IsPlayerConnected(playerid))
- {
- new Float:posx, Float:posy, Float:posz;
- new Float:oldposx, Float:oldposy, Float:oldposz;
- new Float:tempposx, Float:tempposy, Float:tempposz;
- GetPlayerPos(playerid, oldposx, oldposy, oldposz);
- //radi = 2.0; //Trigger Radius
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(IsPlayerConnected(i))
- {
- GetPlayerPos(i, posx, posy, posz);
- tempposx = (oldposx -posx);
- tempposy = (oldposy -posy);
- tempposz = (oldposz -posz);
- //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
- if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
- {
- SendClientMessage(i, col1, string);
- }
- else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
- {
- SendClientMessage(i, col2, string);
- }
- else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
- {
- SendClientMessage(i, col3, string);
- }
- else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
- {
- SendClientMessage(i, col4, string);
- }
- else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
- {
- SendClientMessage(i, col5, string);
- }
- }
- }
- }//not connected
- return 1;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=vBlinker=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- forward vBlinker(playerid);
- public vBlinker(playerid)
- {
- if(IsPlayerInAnyVehicle(playerid) && GetPVarInt(playerid, "CopFlash") != 1)
- {
- new Key;
- new ud, lr, panels,tires;
- new carid = GetPlayerVehicleID(playerid);
- GetPlayerKeys(playerid, Key, ud, lr);
- GetVehicleDamageStatus(carid, panels, doors, lights, tires);
- if(lr > 0)
- {
- if(GetPVarInt(playerid, "vBLeft") == 1)
- {
- KillTimer(BlinkTime[playerid]);
- switch(GetPVarInt(playerid, "vMainOn")){
- case 0:{
- lights = encode_lights(1, 1, 1, 1);
- }
- case 1:{
- lights = encode_lights(0, 0, 0, 0);
- }
- }
- UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
- SetPVarInt(playerid, "vBLeft", 0);
- return 1;
- }
- }
- else if(lr < 0)
- {
- if(GetPVarInt(playerid, "vBRight") == 1)
- {
- KillTimer(BlinkTime[playerid]);
- switch(GetPVarInt(playerid, "vMainOn")){
- case 0:{
- lights = encode_lights(1, 1, 1, 1);
- }
- case 1:{
- lights = encode_lights(0, 0, 0, 0);
- }
- }
- UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
- SetPVarInt(playerid, "vBRight", 0);
- return 1;
- }
- }
- if(GetPVarInt(playerid, "vBRight") == 1)
- {
- switch(GetPVarInt(playerid, "vMainOn")){
- case 0:{
- switch(GetPVarInt(playerid, "vBlinkOn")){
- case 0:{
- lights = encode_lights(1, 1, 0, 0);
- SetPVarInt(playerid, "vBlinkOn", 1);
- }
- case 1:{
- lights = encode_lights(1, 1, 1, 1);
- SetPVarInt(playerid, "vBlinkOn", 0);
- }
- }
- }
- case 1:{
- switch(GetPVarInt(playerid, "vBlinkOn")){
- case 0:{
- lights = encode_lights(0, 0, 1, 1);
- SetPVarInt(playerid, "vBlinkOn", 1);
- }
- case 1:{
- lights = encode_lights(0, 0, 0, 0);
- SetPVarInt(playerid, "vBlinkOn", 0);
- }
- }
- }
- }
- }
- if(GetPVarInt(playerid, "vBLeft") == 1)
- {
- switch(GetPVarInt(playerid, "vMainOn")){
- case 0:{
- switch(GetPVarInt(playerid, "vBlinkOn")){
- case 0:{
- lights = encode_lights(0, 0, 1, 1);
- SetPVarInt(playerid, "vBlinkOn", 1);
- }
- case 1:{
- lights = encode_lights(1, 1, 1, 1);
- SetPVarInt(playerid, "vBlinkOn", 0);
- }
- }
- }
- case 1:{
- switch(GetPVarInt(playerid, "vBlinkOn")){
- case 0:{
- lights = encode_lights(1, 1, 0, 0);
- SetPVarInt(playerid, "vBlinkOn", 1);
- }
- case 1:{
- lights = encode_lights(0, 0, 0, 0);
- SetPVarInt(playerid, "vBlinkOn", 0);
- }
- }
- }
- }
- }
- UpdateVehicleDamageStatus(carid, panels, doors, lights, tires);
- }
- else if(GetPVarInt(playerid, "CopFlash") == 1)
- {
- new d[4];
- new carid = GetPlayerVehicleID(playerid);
- GetVehicleDamageStatus(carid, d[0], d[1], d[2], d[3]);
- switch(GetPVarInt(playerid, "vBlinkOn"))
- {
- case 0:{
- d[2] = encode_lights(1, 1, 0, 0);
- SetPVarInt(playerid, "vBlinkOn", 1);
- }
- case 1:{
- d[2] = encode_lights(0, 0, 1, 1);
- SetPVarInt(playerid, "vBlinkOn", 0);
- }
- }
- UpdateVehicleDamageStatus(carid, d[0], d[1], d[2], d[3]);
- return 1;
- }
- return 1;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=OnPlayerCommandText=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/vehiclecontrol", cmdtext, true, 15) == 0)
- {
- SCM(playerid, COLOR_YELLOW, "__________________________________________Vehicle Control_____________________________________________");
- SCM(playerid,COLOR_LIGHTRED,"");
- SCM(playerid, COLOR_ROSUAPRINS,"Key N: Start/Stop engine");
- SCM(playerid, COLOR_BLUE,"Key num 8: Open/Close hood");
- SCM(playerid, COLOR_GREEN,"Key num 2: Open/Close trunk");
- SCM(playerid, COLOR_2RED,"Key 2: Turn on/off lights");
- SCM(playerid, COLOR_YELLOW, "");
- SCM(playerid, COLOR_YELLOW, "__________________________________________Vehicle Control_____________________________________________");
- return 1;
- }
- return 0;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=Encode Lights=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- encode_lights(light1, light2, light3, light4)
- {
- return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=IsPublicService=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- IsPublicService(carid)
- {
- new PS[11] = { 416, 427, 490, 528, 407, 544, 596, 598, 597, 599, 601 };
- for(new i = 0; i < sizeof(PS); i++)
- {
- if(GetVehicleModel(carid) == PS[i]) return 1;
- }
- return 0;
- }
- //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=The End.Do Not Remove Credits Please=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Advertisement
Add Comment
Please, Sign In to add comment