Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new Speedlimit[MAX_PLAYERS];
- #define SpeedCheck(%0,%1,%2,%3,%4) floatround(floatsqroot(%4?(%0*%0+%1*%1+%2*%2):(%0*%0+%1*%1) ) *%3*1.6)
- //Under OnGameModeInIt
- ManualVehicleEngineAndLights();
- //======================================Stocks=======================================//
- //Vehicle speed
- stock GetVehicleSpeed(vehicleid, get3d)
- {
- new Float:x, Float:y, Float:z;
- GetVehicleVelocity(vehicleid, x, y, z);
- return SpeedCheck(x, y, z, 100.0, get3d);
- }
- stock ModifyVehicleSpeed(vehicleid,mph) //Miles Per Hour
- {
- new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple;
- GetVehicleVelocity(vehicleid,Vx,Vy,Vz);
- DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz);
- if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0)
- {
- multiple = ((mph + DV * 100) / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH
- return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple);
- }
- return 0;
- }
- //================================================Commands=============================================//
- //------------------------------Vehicle commands------------------------------//
- CMD:speed(playerid, params[])
- {
- new string[128], speed;
- if(sscanf(params, "i", speed)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE] /speed (MPH)");
- if(speed < 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR] invalid MPH speed.");
- Speedlimit[playerid] = speed;
- if(speed == 0) format(string, sizeof(string), "[VEHICLE] You have turned your speed limit off.", speed);
- else format(string, sizeof(string), "[VEHICLE] You have set your speed limit to %d MPH.", speed);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- return 1;
- }
- CMD:engine(playerid, params[])
- {
- #pragma unused params
- new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
- vehicleid = GetPlayerVehicleID(playerid);
- GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- if(!IsPlayerInAnyVehicle(playerid))
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
- if(GetPlayerVehicleSeat(playerid) != 0)
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
- if(engine == 1)
- {
- SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Engine shut off.");
- }
- else
- {
- SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Engine started.");
- }
- return 1;
- }
- CMD:lights(playerid, params[])
- {
- #pragma unused params
- new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
- vehicleid = GetPlayerVehicleID(playerid);
- GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- if(!IsPlayerInAnyVehicle(playerid))
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
- if(GetPlayerVehicleSeat(playerid) != 0)
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
- if(lights == 1)
- {
- SetVehicleParamsEx(vehicleid,engine,0,alarm,doors,bonnet,boot,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] lights turned off.");
- }
- else
- {
- SetVehicleParamsEx(vehicleid,engine,1,alarm,doors,bonnet,boot,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] lights turned on.");
- }
- return 1;
- }
- CMD:bonnet(playerid, params[])
- {
- #pragma unused params
- new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
- vehicleid = GetPlayerVehicleID(playerid);
- GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- if(!IsPlayerInAnyVehicle(playerid))
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
- if(GetPlayerVehicleSeat(playerid) != 0)
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
- if(bonnet == 1)
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,0,boot,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Bonnet closed.");
- }
- else
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,1,boot,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Bonnet opened.");
- }
- return 1;
- }
- CMD:boot(playerid, params[])
- {
- #pragma unused params
- new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective;
- vehicleid = GetPlayerVehicleID(playerid);
- GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
- if(!IsPlayerInAnyVehicle(playerid))
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command.");
- if(GetPlayerVehicleSeat(playerid) != 0)
- return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command.");
- if(boot == 1)
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,0,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Boot closed.");
- }
- else
- {
- SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,1,objective);
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Boot opened.");
- }
- return 1;
- }
- CMD:lock(playerid, params[])
- {
- #pragma unused params
- if(IsPlayerInAnyVehicle(playerid))
- {
- new State=GetPlayerState(playerid);
- if(State!=PLAYER_STATE_DRIVER)
- {
- SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be in the driver's seat in order to use this command.");
- return 1;
- }
- new i;
- for(i=0;i<MAX_PLAYERS;i++)
- {
- if(i != playerid)
- {
- SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
- }
- }
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Vehicle locked.");
- new Float:pX, Float:pY, Float:pZ;
- GetPlayerPos(playerid,pX,pY,pZ);
- PlayerPlaySound(playerid,1056,pX,pY,pZ);
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED,"[ERROR] You must be in a vehicle in order to use this command.");
- }
- return 1;
- }
- CMD:unlock(playerid, params[])
- {
- #pragma unused params
- if(IsPlayerInAnyVehicle(playerid))
- {
- new State=GetPlayerState(playerid);
- if(State!=PLAYER_STATE_DRIVER)
- {
- SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be in the driver's seat in order to use this command.");
- return 1;
- }
- new i;
- for(i=0;i<MAX_PLAYERS;i++)
- {
- SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
- }
- SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Vehicle unlocked.");
- new Float:pX, Float:pY, Float:pZ;
- GetPlayerPos(playerid,pX,pY,pZ);
- PlayerPlaySound(playerid,1057,pX,pY,pZ);
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED,"[ERROR] You must be in a vehicle in order to use this command.");
- }
- return 1;
- }
- ///====================================================================================///
- //Under ONPlayerUpdate
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid])
- {
- new a, b, c;
- GetPlayerKeys(playerid, a, b ,c);
- if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid])
- {
- new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid];
- ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed);
- }
- }
- //Thank you
Advertisement
Add Comment
Please, Sign In to add comment