What if the command the user entered is just of 3 characters, just /fb, then the cmdtext[3] would crash, with an array index out of bounds exception. It's better to use sscanf for these purposes. NEVER TRUST USER INPUT.
|
I put the command in another GM and it works however i am forced to put the id car for the destroy and i want for something that would allow me to detroy the vehicle at the same time as i close the crusher. If is possible
Again tanks for your help +1 for you |
CMD:adestroycar(playerid, params[])
{
new TargetID,destroyveh,str1[128];
if(sscanf(params, "u", TargetID)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /adestroycar [id]");
if(TargetID == INVALID_PLAYER_ID || !IsPlayerConnected(TargetID)) return SendClientMessage(playerid, COLOR_RED, "That Player Is Not Connected");
if(GetPlayerState(TargetID) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED, "Player Is Not In A Vehicle.");
else
{
format(str1,sizeof(str1),"%s (%d)'s Vehicle Has Been Destroyed.",pname(TargetID),TargetID);
SendClientMessage(playerid,COLOR_HOTPINK,str1);
destroyveh = GetPlayerVehicleID(TargetID);
DestroyVehicle(destroyveh);
}
return 1;
}
if(strcmp(cmdtext,"/fb", true, 3) == 0 && cmdtext[3] <= ' ') { if(IsPlayerInRangeOfPoint(playerid, 15.0, 1634.8997, -1818.1466, 15.1864)) { MoveObject(broyeur12, 1636.9797, -1818.1466, 15.1864, 1.5, 0.00000, 0.00000, 0.00000); MoveObject(broyeur13, 1637.2100, -1818.3542, 15.1864, 1.5, 0.00000, 0.00000, 0.00000); SetTimer("ouverture", 3000, false); GameTextForPlayer(playerid, "Broyeur en marche!", 3500, 3); GetPlayerName(playerid, sendername, sizeof(sendername)); new text[100]; format(text, sizeof(text), "*%s active le broyeur а l'aide de sa tйlйcommande.", sendername); } if(cmdtext[3] == EOS || cmdtext[4] == EOS) { return SendClientMessage(playerid, -1, "/fb <car id>"); } if(DestroyVehicle(strval(cmdtext[4])) == 0) { return SendClientMessage(playerid, -1, "id du vehicule invalide!"); } return SendClientMessage(playerid, -1, "Vehicule detruit!"); }