25.04.2010, 11:32
Quote:
Originally Posted by _❼_
The old one, I thought I'd start off with the original one, thought it might be easier to learn/implement?
|
The pawn version has no bounds checking, so to avoid an overflow you will need to make all the strings big enough.
pawn Код:
new car[128], vIsName, colour1[128], colour2[128]
Quote:
/v nrg 0000000000000000001 |
Using the plugin would be best, although if you must use the pawn version you could use something like:
pawn Код:
CMD:v(playerid, params[])
{
if(PlayerInfo[playerid][Level] < 3 && !IsPlayerAdmin(playerid)) return 0;
if(isnull(params)) {
SendClientMessage(playerid, 0xFF0000FF, "USAGE: /v [ModelID/Name] (Colour 1) (Colour 2)");
return 1;
}
new vname[128], colour1 = -1, colour2 = -1;
sscanf(params, "sii", vname, colour1, colour2);
new modelid = strval(vname);
if(modelid > 611 || modelid < 400) {
modelid = GetVehicleModelIDFromName(vname);
if(modelid == INVALID_MODEL_ID) { // whatever GetVehicleModelIDFromName returns when no model is found
SendClientMessage(playerid, 0xFF0000FF, "Invalid Vehicle Model");
return 1;
}
}
new Float:px, Float:py, Float:pz, Float:prot;
if(IsPlayerInAnyVehicle(playerid)) {
GetVehiclePos(GetPlayerVehicleID(playerid), px, py, pz);
GetVehicleZAngle(GetPlayerVehicleID(playerid), prot);
} else {
GetPlayerPos(playerid, px, py, pz);
GetPlayerFacingAngle(playerid, prot);
}
new vid = CreateVehicle(modelid, px + 4*floatcos(prot + 90.0, degrees), py + 4*floatsin(prot + 90.0, degrees), pz, prot + 90, colour1, colour2, -1);
if(vid == INVALID_VEHICLE_ID) {
SendClientMessage(playerid, 0xFF0000FF, "Vehicle limit reached");
return 1;
}
if(vid >= sizeof(DynamicV)) {
SendClientMessage(playerid, 0xFF0000FF, "Unable to create vehicle");
DestroyVehicle(vid);
return 1;
}
LinkVehicleToInterior(vid, GetPlayerInterior(playerid));
SetVehicleVirtualWorld(vid, GetPlayerVirtualWorld(playerid));
DynamicV[vid] = 1;
new string[128];
format(string, sizeof(string), "%s successfully spawned. To destroy it, use /dc", GetVehicleName(vid));
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}