05.03.2011, 16:29
hey im new to scripting and i want something that when i do /cc [id] [id] inside the game it changes your vehicles car colour could someone please help me with how i can do this?
if(strcmp(cmd, "/cc", true)== 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
new vid = GetPlayerVehicleID(playerid);
if(strval(result) && strval(result[2]) >126 || strval(result) && strval(result[2]) <0) return SendClientMessage(playerid, COLOR_RED, "Invalid color id!");
ChangeVehicleColor(vid, strval(result), strval(result[2]));
}
else
{
SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle!");
}
return 1;
}
CMD:cc(playerid, params[])
{
new ColorID, ColorID2, vehicleid, str[75];
if(sscanf(params, "dd", ColorID,ColorID2)) return SendClientMessage(playerid, COLOR, "USAGE: /carcolor [1/126] [1/126]");
else if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR, "You are not in a vehicle!");
else if(ColorID < 0 && ColorID > 126) return SendClientMessage(playerid, COLOR, "CarColor cannot be above 126 or below 0!");
else if(ColorID2 < 0 && ColorID2 > 126) return SendClientMessage(playerid, COLOR, "CarColor2 cannot be above 126 or below 0!");
else
{
vehicleid = GetPlayerVehicleID(playerid);
ChangeVehicleColor(vehicleid, ColorID, ColorID2);
format(str, sizeof(str),">> CarColor 1 changed to %d and CarColor 2 changed to %d <<",ColorID, ColorID2);
SendClientMessage(playerid, COLOR, str);
}
return 1;
}
Better do it with ZCMD and SSCANF2
pawn Код:
|
new idx = 0;