27.09.2010, 16:38
@Rzzr
Do not called GetVehicleModelIDFromName(vehicle) * 3 times and GetPlayerVehicleID(playerid) * 4 times
and
I thought of:
Do not called GetVehicleModelIDFromName(vehicle) * 3 times and GetPlayerVehicleID(playerid) * 4 times
and
pawn Код:
GetVehicleModelIDFromName(vname[])
{
for(new i = 0; i < 211; i++)
{
if ( strfind(aVehicleNames[i], vname, true) != -1 )
return i + 400;
}
return -1; // replace -1 with INVALID_VEHICLE_ID
}
pawn Код:
//replace
else if(GetVehicleModelIDFromName(vehicle) < 400 || GetVehicleModelIDFromName(vehicle) > 611) SendClientMessage(playerid, 0xAA3333AA, "ERROR: Invalid vehicleid");
//whit:
else if(GetVehicleModelIDFromName(vehicle) == INVALID_VEHICLE_ID) SendClientMessage(playerid, 0xAA3333AA, "ERROR: Invalid vehicleid");
pawn Код:
command(cvm, playerid, params[])
{
if(GetPlayerVehicleSeat(playerid) != 0) return SendClientMessage(playerid, 0xAA3333AA, "ERROR: You must be in a vehicle!");
//------
new
vehicle[128];
if(sscanf(params, "s[128]", vehicle)) return SendClientMessage(playerid, 0xAA3333AA, "USAGE: /cvm <vehicle>");
//------
new
Get_Vehicle_Model_ID = GetVehicleModelIDFromName(vehicle);
if(Get_Vehicle_Model_ID == INVALID_VEHICLE_ID) SendClientMessage(playerid, 0xAA3333AA, "ERROR: Invalid vehicleid");
else
{
new
Float: VelocityX,
Float: VelocityY,
Float: VelocityZ,
Float: VehAngle,
Float: PlayerX,
Float: PlayerY,
Float: PlayerZ,
newveh,
Get_VehicleID = GetPlayerVehicleID(playerid);
GetVehicleVelocity(Get_VehicleID, VelocityX, VelocityY, VelocityZ);
GetVehicleZAngle(Get_VehicleID, VehAngle);
GetVehiclePos(Get_VehicleID, PlayerX, PlayerY, PlayerZ);
DestroyVehicle(Get_VehicleID);
newveh = CreateVehicle(Get_Vehicle_Model_ID, PlayerX, PlayerY, PlayerZ, VehAngle, -1, -1, 10);
PutPlayerInVehicle(playerid, newveh, 0);
SetVehicleVelocity(newveh, VelocityX*1.1, VelocityY*1.1, VelocityZ*1.1);
LinkVehicleToInterior(newveh, GetPlayerInterior(playerid));
SetVehicleVirtualWorld(newveh, GetPlayerVirtualWorld(playerid));
}
return 1;
}