View Single Post
Old 03/02/2017, 01:43 PM   #1302
Gettopro
Big Clucker
 
Join Date: Oct 2011
Posts: 178
Reputation: 4
Default Re: Оптимизация кода

Quote:
Originally Posted by jakebat View Post
Возможно ли оптимизировать?
PHP Code:
    else if(playertextid == TDautosalon[playerid][15])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 175;}else{colorcarz[playerid][1] = 175;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
         else if(
playertextid == TDautosalon[playerid][16])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 1;}else{colorcarz[playerid][1] = 1;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][17])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 155;}else{colorcarz[playerid][1] = 155;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][18])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 111;}else{colorcarz[playerid][1] = 111;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][19])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 162;}else{colorcarz[playerid][1] = 162;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][20])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 0;}else{colorcarz[playerid][1] = 0;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][21])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 194;}else{colorcarz[playerid][1] = 194;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][22])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 187;}else{colorcarz[playerid][1] = 187;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][23])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 174;}else{colorcarz[playerid][1] = 174;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][24])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 136;}else{colorcarz[playerid][1] = 136;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][25])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 006;}else{colorcarz[playerid][1] = 006;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          }
        else if(
playertextid == TDautosalon[playerid][26])
         {
         if(
GetPVarInt(playerid,"color") != 1) {colorcarz[playerid][0] = 128;}else{colorcarz[playerid][1] = 128;}
         
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
        return 
true;
          } 
Писал с телефона, возможны небольшие неточности по коду:
PHP Code:
new const tstMsv[12] = {175,1,155,111,162,0,194,187,174,136,006,128};
for(new 
i;sizeof(tstMsv);i++){
    if(
playertextid != TDautosalon[playerid][i+15]) continue;
    
colorcarz[playerid][(GetPVarInt(playerid,"color") != 1)?0:1] = tstMsv[i];
    
ChangeVehicleColor(carsex[playerid], colorcarz[playerid][0], colorcarz[playerid][1]);
    return 
true;

Gettopro is offline   Reply With Quote