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