if(strcmp(cmd, "/getcarid", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(PlayerInfo[playerid][pAdmin] >= 4)
{
for(new c = 0; c < sizeof(CarInfo); c++)
{
new Float:x,Float:y,Float:z;
new carid = CarInfo[c][cID]; //the car ID in AddStaticVehicle
GetVehiclePos(carid, x, y, z);
if(PlayerToPoint(3, playerid, x, y, z))
{
format(string, sizeof(string), "Car ID: %d", c);
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "You are not near any Car Ownership vehicle.");
return 1;
}
}
}
else
{
SendClientMessage(playerid, COLOR_RED, "Only admins with Adm Level 4 can use this command.");
return 1;
}
}
return 1;
}
for(new c = 1; c < sizeof(CarInfo); c++)
for(new c = 2; c < sizeof(CarInfo); c++)
for(new c = 0; c < sizeof(CarInfo); c++)
{
CarInfo[c][cID] = AddStaticVehicleEx(CarInfo[c][cModel], CarInfo[c][cLocationx], CarInfo[c][cLocationy], CarInfo[c][cLocationz], CarInfo[c][cAngle], CarInfo[c][cColor1], CarInfo[c][cColor2], -1);
}
if(strcmp(cmd, "/getcarid", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(PlayerInfo[playerid][pAdmin] >= 4)
{
new Float:x,Float:y,Float:z;
for(new c = 0; c < sizeof(CarInfo); c++)
{
GetVehiclePos(CarInfo[c][cID], x, y, z);
if(PlayerToPoint(3, playerid, x, y, z))
{
format(string, sizeof(string), "Car ID: %d", CarInfo[c][cID]);
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
}
SendClientMessage(playerid, COLOR_RED, "You are not near any Car Ownership vehicle.");
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "Only admins with Adm Level 4 can use this command.");
return 1;
}
}
return 1;
}
Originally Posted by 0rb
Why don't you GetPlayerPos BEFORE the loop, instead of each loop iteration? That is very inefficient.
|
new Float:px, Float:py, Float:pz, Float:cx, Float:cy, Float:cz;
GetPlayerPos(playerid, px, py, pz);
GetVehiclePos(CarInfo[c][cID], cx, cy, cz);
for (blablabla)
if (distance(px, py, pz, cx, cy, cz) < 3.0)