[Ajuda] ID de Veнculo
#1

Quero saber como pegar o ID de um veнculo, nгo o MODELO, mas sim o ID mesmo.
Tipo, chegou em uma parte que bagunзou a minha cabeзa.

PHP код:
PegarKMRodado(vInfo[v][IdVeiculo_Arquivo]); 
Estб dando esse warning nessa linha:

Код:
(2106) : warning 215: expression has no effect
Ele tб pedindo pra retornar o ID do VEНCULO. Mas como q eu faзo, sabendo que o

PHP код:
GetPlayerVehicleID 
Sгo para veнculos que jб tem players dentro?

E se nгo tiver players dentro dele, como fica?
Reply
#2

Envia a funзгo PegarKMRodado.
Reply
#3

Й uma include que achei no fуrum, da uma olhada encima do cуdigo.

PHP код:
///////////////////////////////////////////////////////////////////////////////////
//
//                 |*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|
//                 |*|      eDistance System     |*|
//                 |*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|*|
//
//               =====================================
//                            INTRODUЗГO
//               =====================================
//
//               Essa include permite a vocк verificar
//               quanto um veнculo percorreu em Metros,
//               Quilфmetros ou Milhas.
//
//               =====================================
//                             NATIVES
//               =====================================
//
//               native GetMeters(vehicleid);
//               native PegarKMRodado(vehicleid);
//               native GetMiles(vehicleid);
//               native E_SetVehiclePos(vehicleid, float:X, float:Y, float:Z);
//
//               =====================================
//                      EXEMPLOS (MODO DE USO)
//               =====================================
//
//                    *-- | METROS RODADOS | --*
//               format(string, sizeof(string), "Esse veнculo percorreu %d Metros Rodados.", GetMeters(GetPlayerVehicleID(playerid)));
//               SendClientMessage(playerid, -1, string);
//
//                    *-- | QUILФMETROS RODADOS | --*
//               format(string, sizeof(string), "Esse veнculo percorreu %s Quilфmetros Rodados.", PegarKMRodado(GetPlayerVehicleID(playerid)));
//               SendClientMessage(playerid, -1, string);
//
//                    *-- | MILHAS RODADOS | --*
//               format(string, sizeof(string), "Esse veнculo percorreu %s Milhas Rodados.", GetMiles(GetPlayerVehicleID(playerid)));
//               SendClientMessage(playerid, -1, string);
//
//               =====================================
//                             CRЙDITOS
//               =====================================
//
//                  * Include Criada por EditPawn *
//        * BlueX e Paulor por me ajudar com algumas funзхes *
//        * Lordz pelo tutorial de ligar Funзхes e Callbacks *
//
//               =====================================
//                     BUGS, DЪVIDAS E SUGESTХES
//               =====================================
//
//         Acesse: http://forum.sa-mp.com/forumdisplay.php?f=56
//
//
///////////////////////////////////////////////////////////////////////////////////

/* ----- INCLUDE ----- */
#include    a_samp

/* ----- DEFINES ----- */
#define   GetMeters(%0)              E@_R[%0]
#define   PegarKMRodado(%0)         (E@_R[%0] * 0.001)
#define   GetMiles(%0)              (E@_R[%0] * 0.000621)
#define   ResetMetersTraveled(%0)    E@_R[%0] = 0;
#define   Paste                      "KMRodados/Veнculo %d.ini" //Pasta para salvar a distвncia que cada veнculo percorreu
#define   SaveDistance               0 // (0 - Desabilitar | 1 - Abilitar) O salvamento da distancia percorrida

/* ----- VARS ----- */
new    E@_R[MAX_VEHICLES] = 0,
       
Float:v@_P[3],
       
E@_Timer[MAX_PLAYERS];
       
#if SaveDistance == 1
    
new    File:E@_Arq;
    static 
E@_S[32],
           
E@_Ss[24];
#endif

/* ----- FORWARDS ----- */
forward E@_OnPlayerDisconnect(playerid, reason);
forward E@_OnPlayerStateChange(playerid, newstate, oldstate);
forward E@_At(playerid);
forward E@_OnPlayerExitVehicle(playerid, vehicleid);
forward E@_OnGameModeExit();
forward E@_OnGameModeInit();

/* ----- CALLBACKS ----- */
public OnGameModeInit() {
    
#if SaveDistance == 1
        
for(new x; x < MAX_VEHICLES; ++x) {
            
format(E@_S, sizeof(E@_S), Paste, x);
            if(
fexist(E@_S)) {
                
E@_Arq = fopen(E@_S, io_read);
                
fread(E@_Arq, E@_Ss);
                
E@_R[x] = strval(E@_Ss);
                
fclose(E@_Arq);
            }
        }
    
#endif
    
return CallLocalFunction("E@_OnGameModeInit", "");
}

#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#endif
#define OnGameModeInit E@_OnGameModeInit

public OnGameModeExit() {
    
#if SaveDistance == 1
        
for(new x; x < MAX_VEHICLES; ++x) {
            if(
E@_R[x] > 0) {
                
format(E@_S, sizeof(E@_S), Paste, x);
                
format(E@_Ss, sizeof(E@_Ss), "%d", E@_R[x]);
                
E@_Arq = fopen(E@_S, io_write);
                
fwrite(E@_Arq, E@_Ss);
                
fclose(E@_Arq);
            }
        }
    
#endif
    
return CallLocalFunction("E@_OnGameModeExit", "");
}

#if defined _ALS_OnGameModeExit
    #undef OnGameModeExit
#endif
#define OnGameModeExit E@_OnGameModeExit

public OnPlayerDisconnect(playerid, reason) {
    
KillTimer(E@_Timer[playerid]);
    return 
CallLocalFunction("E@_OnPlayerDisconnect", "id", playerid, reason);
}

#if defined _ALS_OnPlayerDisconnect
    #undef OnPlayerDisconnect
#else
    #define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect E@_OnPlayerDisconnect

public OnPlayerExitVehicle(playerid, vehicleid) {
    
KillTimer(E@_Timer[playerid]);
    return 
CallLocalFunction("E@_OnPlayerExitVehicle", "id", playerid, vehicleid);
}

#if defined _ALS_OnPlayerExitVehicle
    #undef OnPlayerExitVehicle
#endif
#define OnPlayerExitVehicle E@_OnPlayerExitVehicle

public E@_At(playerid) {
    if(
GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]) <= 100) {
        
E@_R[GetPlayerVehicleID(playerid)] += floatround(GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]));
    }
    
GetVehiclePos(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]);
/*
    OBS: Caso queira fazer teste, apenas abilite essa parte e irб aparecer todas as formas de distвncia que o veнculo estб rodando.

    new E@_Str[129];
    format(E@_Str, sizeof(E@_Str), "(%d) Metros - (%0.3f) Quilфmetros - (%0.3f) Milhas", GetMeters(GetPlayerVehicleID(playerid)), PegarKMRodado(GetPlayerVehicleID(playerid)), GetMiles(GetPlayerVehicleID(playerid)));
    SendClientMessage(playerid, -1, E@_Str);
*/
}

public 
OnPlayerStateChange(playerid, newstate, oldstate) {
    if(
oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) {
        
GetVehiclePos(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]);
        
E@_Timer[playerid] = SetTimerEx("E@_At", 1000, true, "i", playerid);
    }
    else if(
oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT) KillTimer(E@_Timer[playerid]);
    return 
CallLocalFunction("E@_OnPlayerStateChange", "idd", playerid, newstate, oldstate);
}

#if defined _ALS_OnPlayerStateChange
    #undef OnPlayerStateChange
#else
    #define _ALS_OnPlayerStateChange
#endif
#define OnPlayerStateChange E@_OnPlayerStateChange

/* ----- STOCK ----- */
stock E_SetVehiclePos(vehicleid, float:X, float:Y, float:Z) {
    
SetVehiclePos(vehicleid, X, Y, Z);
    
V@_P[0] = X, V@_P[1] = Y, V@_P[2] = Z;
} 
Ah, e outra coisa nada haver com isso, na verdade, uma dъvida:
Eu estou salvando o Id dos veнculos pelo ARQUIVO, tipo, se jб possui Veiculo1, vai pro 2..
Tem algum problema? Ou eu tenho que identificar o Id exato do veнculo? Nгo tem como eu ser mais direto que isso.
Reply
#4

PHP код:
PegarKMRodado(vInfo[1][IdVeiculo_Arquivo]); 

Veja se desta forma vocк consegue.
Se conseguir, vocк deverб fazer um loop.
Reply
#5

Quote:
Originally Posted by ipsLuan
Посмотреть сообщение
PHP код:
PegarKMRodado(vInfo[1][IdVeiculo_Arquivo]); 

Veja se desta forma vocк consegue.
Se conseguir, vocк deverб fazer um loop.
PHP код:
C:\Users\USER\Desktop\GAMEMODES DE SAMP\samp037_svr_R2-1-1_win32\gamemodes\GM.pwn(2109) : warning 213: tag mismatch
C
:\Users\USER\Desktop\GAMEMODES DE SAMP\samp037_svr_R2-1-1_win32\gamemodes\GM.pwn(2109) : warning 215: expression has no effect 
Esse PegarKMRodado, eu jб testei em outro local e pega perfeitamente, fiz esse comando ontem:

PHP код:
CMD:velocidade(playerid, params[])
{
    new
        
br1[100],
        
veiculo = GetPlayerVehicleID(playerid)
    ;
    
format(br1, 100, "KM Rodado: %0.3f", PegarKMRodado(veiculo));
    
SendClientMessage(playerid, -1, br1);
    return 
1;
} 
Reply
#6

PHP код:
for(new id = 1; id < MAX_VEHICLES; id++)
{
    
PegarKMRodado(id);
    
printf("PegarKMRodado - id: %d", id);
} 
Reply
#7

PHP код:
C:\Users\USER\Desktop\GAMEMODES DE SAMP\samp037_svr_R2-1-1_win32\gamemodes\GM.pwn(2111) : warning 215: expression has no effect 
Da uma olhada no CУDIGO DE SALVAMENTO DOS VEНCULOS.

PHP код:
forward SalvarVeiculo();
public 
SalvarVeiculo()
{
    for(new 
v; v < MAX_VEICULOS; v++)
    {
        
format(vFile, sizeof(vFile), "Veiculos/veiculo%d.ini", v);
        
        
        
GetVehicleModel(vInfo[v][ModeloVeiculo]);
        
        
GetVehiclePos(vInfo[v][IdVeiculo_Arquivo], vInfo[v][PosVeiculoX], vInfo[v][PosVeiculoY], vInfo[v][PosVeiculoZ]);
        
GetVehicleZAngle(vInfo[v][IdVeiculo_Arquivo], vInfo[v][PosVeiculoR]);
        
        
GetVehicleColor(vInfo[v][IdVeiculo_Arquivo], vInfo[v][vCor1], vInfo[v][vCor2]);
        
        for(new 
id = 1; id < MAX_VEHICLES; id++)
        {
            
PegarKMRodado(id);
            
printf("PegarKMRodado - id: %d", id);
        }
        
        
DOF2_SetInt(vFile, "IdVeiculo_Arquivo", vInfo[v][IdVeiculo_Arquivo]);
         
DOF2_SetInt(vFile, "ModeloVeiculo", vInfo[v][ModeloVeiculo]);
        
DOF2_SetFloat(vFile, "PosVeiculoX", vInfo[v][PosVeiculoX]);
        
DOF2_SetFloat(vFile, "PosVeiculoY", vInfo[v][PosVeiculoY]);
        
DOF2_SetFloat(vFile, "PosVeiculoZ", vInfo[v][PosVeiculoZ]);
        
DOF2_SetFloat(vFile, "PosVeiculoR", vInfo[v][PosVeiculoR]);
        
DOF2_SetInt(vFile, "vCor1", vInfo[v][vCor1]);
        
DOF2_SetInt(vFile, "vCor2", vInfo[v][vCor2]);
        
DOF2_SetInt(vFile, "RespawnVeiculo", vInfo[v][RespawnVeiculo]);
        
DOF2_SetInt(vFile, "GasolinaVeiculo", vInfo[v][GasolinaVeiculo]);
        
DOF2_SetInt(vFile, "DieselVeiculo", vInfo[v][DieselVeiculo]);
        
DOF2_SetInt(vFile, "EtanolVeiculo", vInfo[v][EtanolVeiculo]);
        
DOF2_SetInt(vFile, "EtanolVeiculo", vInfo[v][EtanolVeiculo]);
        
DOF2_SetInt(vFile, "BlindagemVeiculo", vInfo[v][BlindagemVeiculo]);
        
DOF2_SetFloat(vFile, "KM_Rodado_Veiculo", vInfo[v][KM_Rodado_Veiculo]);
        
DOF2_SaveFile();
    }
    
SetTimer("SalvarVeiculo", 1000, false);
    return 
1;
} 
Reply
#8

Coloque o loop а parte.
E tente assim:

PHP код:
new veiculo;

for(new 
id = 1; id < MAX_VEHICLES; id++)
{
    
veiculo = GetPlayerVehicleID(id);
    
PegarKMRodado(veiculo);
    
printf("PegarKMRodado - id: %d", veiculo);
} 


Nгo estou em casa e nгo posso testar.
Reply
#9

PHP код:
        for(new id = 1; id < MAX_VEHICLES; id++)
        {
            new 
veiculo = GetPlayerVehicleID(id);
            
PegarKMRodado(veiculo);
            
printf("PegarKMRodado - id: %d", veiculo);
        } 
Continua mesmo Warning:

Код:
C:\Users\USER\Desktop\GAMEMODES DE SAMP\samp037_svr_R2-1-1_win32\gamemodes\GM.pwn(2113) : warning 215: expression has no effect
Isso que quero entender, o GetPlayerVehicleID й para jogadores, e nгo global, Nгo tem sentido colocar o ID do veнculo no lugar do Parвmetro: playerid.
Reply
#10

A funзгo PegarKMRodado й uma macro.
PHP код:
#define   PegarKMRodado(%0)         (E@_R[%0] * 0.001) 
Logo PegarKMRodado(VALOR) quando for compilado serб interpretado como (E@_R[VALOR] * 0.001). Ou seja, й a mesma coisa que o seu cуdigo estiver assim:
PHP код:
for(new id = 1; id < MAX_VEHICLES; id++) 
{ 
        new 
veiculo = GetPlayerVehicleID(id); 
        (
E@_R[veiculo] * 0.001)
        
printf("PegarKMRodado - id: %d", veiculo); 
} 
й uma multiplicaзгo, ela nгo estб tendo efeito pq apesar do cуdigo estб realizando a operaзгo de multiplicaзгo, o valor estб se perdendo pq nгo estб sendo usado em nenhum lugar ou nгo estб sendo armazenado.

Uso correto da mesma:
PHP код:
for(new id = 1; id < MAX_VEHICLES; id++) 
{ 
        new 
veiculo = GetPlayerVehicleID(id); 
        
printf("PegarKMRodado - id: %d || Km/h percorrido: %d", veiculo, PegarKMRodado(veiculo)); 
}
// ou
for(new id = 1; id < MAX_VEHICLES; id++) 
{ 
        new 
veiculo = GetPlayerVehicleID(id);
        new 
percorrido = PegarKMRodado(veiculo);
        
printf("PegarKMRodado - id: %d || Km/h percorrido: %d", veiculo, percorrido); 
} 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)