[Ajuda] Public OnVehicleSpawn
#1

Sempre que eu uso o comando '/RespawnVeiculos' causa um lag no servidor causado pelo loop na
public OnVehicleSpawn alguйm pode me ajudar a resolver esse problema? Thank you


Код:
public OnVehicleSpawn(vehicleid)
{
    new string[128];
    for(new carror = 0; carror < MAX_CASAS; carror++)
    {
       format(string, sizeof(string), CASAS, carror);
         if(DOF2_FileExists(string))
	 {
            if(DOF2_GetInt(string, "Modelo") > 0)
	     {
               if(DOF2_GetInt(string, "Id") == vehicleid)
	      {
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "spoil"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "hood"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "roof"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "skirt"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "lamps"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "nitro"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "exaust"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "whells"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "stereo"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "hydraulic"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "FBUMPER"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "REAR_BUMPER"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "VENT_RIGHT"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "VENT_L"));
                  AddVehicleComponent(vehicleid, DOF2_GetInt(string, "Bullbars"));
                  if(DOF2_GetInt(string, "Tpjb") == 1)
	   	  {
                      ChangeVehiclePaintjob(vehicleid, DOF2_GetInt(string, "pjb"));
                  }
	      }   
          }      
      }
 }
Код:
if(!strcmp(cmdtext, "/respawnveiculos", true))
{
     if(!(IsPlayerAdmin(playerid))) return SendClientMessage(playerid, COR_VERMELHO, "(ERRO) Vocк nгo tem permissгo!");
     for(new car = 1; car <= 268; car++)
     {
         if(IsVehicleEmpty(car)) SetVehicleToRespawn(car);
     }
     new Nome[MAX_PLAYER_NAME];
     GetPlayerName(playerid, Nome, sizeof(Nome));
     format(string, sizeof(string), "* O Administrador %s respawnou todos os veiculos sem uso.", Nome);
     SendClientMessageToAll(-1,string);
     return 1;
}
Код:
stock IsVehicleEmpty(vehicleid)
{
        for(new i=0; i<MAX_PLAYERS; i++)
        {
                if(IsPlayerInVehicle(i, vehicleid)) return 0;
        }
        return 1;
}
Reply
#2

Sem dъvida irб lagar, porque estб abrindo vбrios arquivos em um curto perнodo de tempo.

[b] CORRETO SERIA[/green]

Salvar os dados dos veнculos em uma array.

pawn Код:
enum VEICULOS{
     MODELO,
     COR,
     ID
    // BLA BLA    
};
new E_VEICULOS[ MAX_VEHICLES ];


// Quando carregar:

E_VEHICULOS[id][ID] = CreateVehicle( ... );
E_VEHICULOS[id][ID] = COR_DO_VEICULO;


// Quando for usar para resetar:

for(new i, e = sizeof(E_VEICULOS); i ^e; ++i){
    ChangeVehiclePaintjob(E_VEICULOS[i][ID], (E_VEICULOS[i][COR]);
}
Reply
#3

Poderia criar uma funзгo para guardar todas estas informaзхes dos arquivo em variбveis, e logo, trocar a funзгo pelo valor das variбveis. Carrega tudo ao iniciar o servidor, e no decorrer, ao ir ocorrendo alteraзхes nos veнculos, apenas modifique o valor das variбveis, e no fim, ao desligar o servidor, salve-as.

Veja este exemplo:
pawn Код:
#if defined MAX_VEHICLES
#undef MAX_VEHICLES
#define MAX_VEHICLES (100)
#endif

enum CarrosInfo
{
    carID,
    modelID,
    cor_1,
    cor_2
};

new Veiculos[MAX_VEHICLES][CarrosInfo];

public OnGameModeInit()
{
    CarregarVeiculos();

    for(new i; i < MAX_VEHICLES; i++)
    {
        Veiculos[i][carID] = CreateVehicle(Veiculos[i][modelID], 0.0, 0.0, 0.0, 180, Veiculos[i][cor_1], Veiculos[i][cor_2], -1);
    }
    return 1;
}

public OnGameModeExit()
{
    SalvarVeiculos();
    return 1;
}

stock CarregarVeiculos()
{
    new destino[15];
    for(new i; i < MAX_VEHICLES; i++)
    {
        format(destino, sizeof(destino), "/Carros/%d.ini", i);
        if(!DOF2_Exists(destino)) return 1;
        Veiculos[i][modelID] = DOF2_GetInt(destino, "Modelo");
        Veiculos[i][cor_1] = DOF2_GetInt(destino, "Cor_1");
        Veiculos[i][cor_1] = DOF2_GetInt(destino, "Cor_2");
    }
    return 1;
}

stock SalvarVeiculos()
{
    new destino[15];
    for(new i; i < MAX_VEHICLES; i++)
    {
        format(destino, sizeof(destino), "/Carros/%d.ini", i);
        if(!DOF2_Exists(destino)) return 1;
        DOF2_SetInt(destino, "Modelo", Veiculos[i][modelID]);
        DOF2_SetInt(destino, "Cor_1", Veiculos[i][cor_1]);
        DOF2_SetInt(destino, "Cor_2", Veiculos[i][cor_1]);
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by Bruno13
Посмотреть сообщение
[... ]
Foi exatamente oque eu falei, porйm seu cуdigo irб carregar apenas 100 veнculos e, se tiver outro sistema que use a diretiva "MAX_VEHICLES" irб bugar.


Aconselho seguir a minha dica, utilizando "sizeof" para verificar se a matriz estб NULA/VAZIA.
Reply
#5

Quote:
Originally Posted by zSuYaNw
Посмотреть сообщение
Foi exatamente oque eu falei, porйm seu cуdigo irб carregar apenas 100 veнculos e, se tiver outro sistema que use a diretiva "MAX_VEHICLES" irб bugar.


Aconselho seguir a minha dica, utilizando "sizeof" para verificar se a matriz estб NULA/VAZIA.
Sim mas quando fui postar ninguйm havia postado...foi apenas um exemplo, nгo й para o nosso amigo acima utilizar ele

Abraзos.
Reply
#6

Obrigado, Vou fazer assim
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)