SHOW:
|
|
- or go back to the newest paste.
| 1 | new Speedlimit[MAX_PLAYERS]; | |
| 2 | //Under OnGameModeInIt | |
| 3 | ManualVehicleEngineAndLights(); | |
| 4 | //======================================Stocks=======================================// | |
| 5 | ||
| 6 | //Vehicle speed | |
| 7 | stock GetVehicleSpeed(vehicleid, get3d) | |
| 8 | {
| |
| 9 | new Float:x, Float:y, Float:z; | |
| 10 | GetVehicleVelocity(vehicleid, x, y, z); | |
| 11 | return SpeedCheck(x, y, z, 100.0, get3d); | |
| 12 | } | |
| 13 | stock ModifyVehicleSpeed(vehicleid,mph) //Miles Per Hour | |
| 14 | {
| |
| 15 | new Float:Vx,Float:Vy,Float:Vz,Float:DV,Float:multiple; | |
| 16 | GetVehicleVelocity(vehicleid,Vx,Vy,Vz); | |
| 17 | DV = floatsqroot(Vx*Vx + Vy*Vy + Vz*Vz); | |
| 18 | if(DV > 0) //Directional velocity must be greater than 0 (display strobes if 0) | |
| 19 | {
| |
| 20 | multiple = ((mph + DV * 100) / (DV * 100)); //Multiplying DV by 100 calculates speed in MPH | |
| 21 | return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple); | |
| 22 | } | |
| 23 | return 0; | |
| 24 | } | |
| 25 | //================================================Commands=============================================// | |
| 26 | ||
| 27 | //------------------------------Vehicle commands------------------------------// | |
| 28 | CMD:speed(playerid, params[]) | |
| 29 | {
| |
| 30 | new string[128], speed; | |
| 31 | if(sscanf(params, "i", speed)) return SendClientMessage(playerid, COLOR_ERROR, "[USAGE] /speed (MPH)"); | |
| 32 | if(speed < 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR] invalid MPH speed."); | |
| 33 | Speedlimit[playerid] = speed; | |
| 34 | if(speed == 0) format(string, sizeof(string), "[VEHICLE] You have turned your speed limit off.", speed); | |
| 35 | else format(string, sizeof(string), "[VEHICLE] You have set your speed limit to %d MPH.", speed); | |
| 36 | SendClientMessage(playerid, COLOR_YELLOW, string); | |
| 37 | return 1; | |
| 38 | } | |
| 39 | ||
| 40 | CMD:engine(playerid, params[]) | |
| 41 | {
| |
| 42 | #pragma unused params | |
| 43 | new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective; | |
| 44 | vehicleid = GetPlayerVehicleID(playerid); | |
| 45 | GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective); | |
| 46 | if(!IsPlayerInAnyVehicle(playerid)) | |
| 47 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command."); | |
| 48 | if(GetPlayerVehicleSeat(playerid) != 0) | |
| 49 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command."); | |
| 50 | if(vehicleid != BC1 && vehicleid != BC2 && vehicleid != BC3 && vehicleid != BC4 && vehicleid != BC5 && vehicleid != BC6) | |
| 51 | {
| |
| 52 | if(engine == 1) | |
| 53 | {
| |
| 54 | SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective); | |
| 55 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Engine shut off."); | |
| 56 | } | |
| 57 | else | |
| 58 | {
| |
| 59 | SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective); | |
| 60 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Engine started."); | |
| 61 | } | |
| 62 | } | |
| 63 | return 1; | |
| 64 | } | |
| 65 | ||
| 66 | CMD:lights(playerid, params[]) | |
| 67 | {
| |
| 68 | #pragma unused params | |
| 69 | new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective; | |
| 70 | vehicleid = GetPlayerVehicleID(playerid); | |
| 71 | GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective); | |
| 72 | if(!IsPlayerInAnyVehicle(playerid)) | |
| 73 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command."); | |
| 74 | if(GetPlayerVehicleSeat(playerid) != 0) | |
| 75 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command."); | |
| 76 | if(lights == 1) | |
| 77 | {
| |
| 78 | SetVehicleParamsEx(vehicleid,engine,0,alarm,doors,bonnet,boot,objective); | |
| 79 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] lights turned off."); | |
| 80 | } | |
| 81 | else | |
| 82 | {
| |
| 83 | SetVehicleParamsEx(vehicleid,engine,1,alarm,doors,bonnet,boot,objective); | |
| 84 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] lights turned on."); | |
| 85 | } | |
| 86 | return 1; | |
| 87 | } | |
| 88 | ||
| 89 | CMD:bonnet(playerid, params[]) | |
| 90 | {
| |
| 91 | #pragma unused params | |
| 92 | new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective; | |
| 93 | vehicleid = GetPlayerVehicleID(playerid); | |
| 94 | GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective); | |
| 95 | if(!IsPlayerInAnyVehicle(playerid)) | |
| 96 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command."); | |
| 97 | if(GetPlayerVehicleSeat(playerid) != 0) | |
| 98 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command."); | |
| 99 | if(bonnet == 1) | |
| 100 | {
| |
| 101 | SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,0,boot,objective); | |
| 102 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Bonnet closed."); | |
| 103 | } | |
| 104 | else | |
| 105 | {
| |
| 106 | SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,1,boot,objective); | |
| 107 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Bonnet opened."); | |
| 108 | } | |
| 109 | return 1; | |
| 110 | } | |
| 111 | ||
| 112 | CMD:boot(playerid, params[]) | |
| 113 | {
| |
| 114 | #pragma unused params | |
| 115 | new vehicleid, engine,lights,alarm,doors,bonnet,boot,objective; | |
| 116 | vehicleid = GetPlayerVehicleID(playerid); | |
| 117 | GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective); | |
| 118 | if(!IsPlayerInAnyVehicle(playerid)) | |
| 119 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in a vehicle in order to use this command."); | |
| 120 | if(GetPlayerVehicleSeat(playerid) != 0) | |
| 121 | return SendClientMessage(playerid, COLOR_RED, "[ERROR] You must be in the driver seat in order to use this command."); | |
| 122 | if(boot == 1) | |
| 123 | {
| |
| 124 | SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,0,objective); | |
| 125 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Boot closed."); | |
| 126 | } | |
| 127 | else | |
| 128 | {
| |
| 129 | SetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,1,objective); | |
| 130 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Boot opened."); | |
| 131 | } | |
| 132 | return 1; | |
| 133 | } | |
| 134 | ||
| 135 | CMD:lock(playerid, params[]) | |
| 136 | {
| |
| 137 | #pragma unused params | |
| 138 | if(IsPlayerInAnyVehicle(playerid)) | |
| 139 | {
| |
| 140 | new State=GetPlayerState(playerid); | |
| 141 | if(State!=PLAYER_STATE_DRIVER) | |
| 142 | {
| |
| 143 | SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be in the driver's seat in order to use this command."); | |
| 144 | return 1; | |
| 145 | } | |
| 146 | new i; | |
| 147 | for(i=0;i<MAX_PLAYERS;i++) | |
| 148 | {
| |
| 149 | if(i != playerid) | |
| 150 | {
| |
| 151 | SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1); | |
| 152 | } | |
| 153 | } | |
| 154 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Vehicle locked."); | |
| 155 | new Float:pX, Float:pY, Float:pZ; | |
| 156 | GetPlayerPos(playerid,pX,pY,pZ); | |
| 157 | PlayerPlaySound(playerid,1056,pX,pY,pZ); | |
| 158 | } | |
| 159 | else | |
| 160 | {
| |
| 161 | SendClientMessage(playerid, COLOR_RED,"[ERROR] You must be in a vehicle in order to use this command."); | |
| 162 | } | |
| 163 | return 1; | |
| 164 | } | |
| 165 | ||
| 166 | CMD:unlock(playerid, params[]) | |
| 167 | {
| |
| 168 | #pragma unused params | |
| 169 | if(IsPlayerInAnyVehicle(playerid)) | |
| 170 | {
| |
| 171 | new State=GetPlayerState(playerid); | |
| 172 | if(State!=PLAYER_STATE_DRIVER) | |
| 173 | {
| |
| 174 | SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be in the driver's seat in order to use this command."); | |
| 175 | return 1; | |
| 176 | } | |
| 177 | new i; | |
| 178 | for(i=0;i<MAX_PLAYERS;i++) | |
| 179 | {
| |
| 180 | SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0); | |
| 181 | } | |
| 182 | SendClientMessage(playerid, COLOR_YELLOW, "[VEHICLE] Vehicle unlocked."); | |
| 183 | new Float:pX, Float:pY, Float:pZ; | |
| 184 | GetPlayerPos(playerid,pX,pY,pZ); | |
| 185 | PlayerPlaySound(playerid,1057,pX,pY,pZ); | |
| 186 | } | |
| 187 | else | |
| 188 | {
| |
| 189 | SendClientMessage(playerid, COLOR_RED,"[ERROR] You must be in a vehicle in order to use this command."); | |
| 190 | } | |
| 191 | return 1; | |
| 192 | } | |
| 193 | ///====================================================================================/// | |
| 194 | //Under ONPlayerUpdate | |
| 195 | ||
| 196 | if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && Speedlimit[playerid]) | |
| 197 | {
| |
| 198 | new a, b, c; | |
| 199 | GetPlayerKeys(playerid, a, b ,c); | |
| 200 | if(a == 8 && GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) > Speedlimit[playerid]) | |
| 201 | {
| |
| 202 | new newspeed = GetVehicleSpeed(GetPlayerVehicleID(playerid), 0) - Speedlimit[playerid]; | |
| 203 | ModifyVehicleSpeed(GetPlayerVehicleID(playerid), -newspeed); | |
| 204 | } | |
| 205 | } | |
| 206 | ||
| 207 | //Thank you |