//---------------/b------------------------- //------------------------------------------ CMD:b(playerid, params[]) { new veh; if(sscanf(params, "d", veh)) SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]"); veh = GetPlayerVehicleID(playerid); SetVehicleSpeed(veh, params); SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!"); return 1; } stock SetVehicleSpeed(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)); //Multiplying DV by 100 calculates speed in MPH return SetVehicleVelocity(vehicleid,Vx*multiple,Vy*multiple,Vz*multiple); } return 0; }
SetVehicleSpeed(veh, strval(params));
CMD:b(playerid, params[]) { if(!strlen(params)) return SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]"); SetVehicleSpeed(GetPlayerVehicleID(playerid), strval(params)); SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!"); return 1; }
Exactly, there's other problems with this code too, the use of sscanf is not needed at all. Also you're creating the veh variable before it's even confirmed it will be used, which is a bad coding habit to get into. In fact, in this case the creation of the variable is not needed either, since it's only ever going to be used once.
Example: Code:
CMD:b(playerid, params[]) { if(!strlen(params)) SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]"); SetVehicleSpeed(GetPlayerVehicleID(playerid), strval(params)); SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!"); return 1; } |
CMD:b(playerid, params[]) { if(isnull(params)) { SendClientMessage(playerid, LIGHTBLUE2, "USAGE: b [speed]"); return 1; } SetVehicleSpeed(GetPlayerVehicleID(playerid), strval(params)); SendClientMessage(playerid, orange, "YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!"); return 1; }