Problem sa TDom

Započeo cofilinko, Septembar 22, 2024, 21:40:31 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 1 gost pregledaju ovu temu.

Imam jedan jedini usebox textdraw koji mi se sakrije kada se spawnujem. Nakon 2-3 sekunde mi se pojavi kao da se nije sakrio.
https://imgur.com/a/h1jZctk
Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.

Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.

Pregledao sam sve preostale TDove, sklonio TextDrawUseBox tamo gde nisu potrebni. Kad otvorim TDove preko TDEditora nemam taj problem.
Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.

postavi nam ovdje kod od onoga što se nalazi u publicu OnPlayerSpawn ili dio kada se igrać loguje na server.
Ne možemo nagađati

Napravio sam druge TDove i nema vise problem sa tim.
Jedini problem sad je taj sto se preview model u brzinometru ne update-uje kada udjem u vozilo.
public PlayerTimer(playerid){
if(IsPlayerInAnyVehicle(playerid)){
if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER){

new veh = GetPlayerVehicleID(playerid);
new sspeed[12];
format(sspeed, sizeof(sspeed), "%dkm/h", GetSpeed(playerid));
    PlayerTextDrawSetString(playerid, Speedometer[3][playerid], sspeed);

  new moda[30];
    GetVehicleName(veh, moda, sizeof(moda));
            PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda);
    PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
    PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], 0, 0);
}
}
}
Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.

Citat: cofilinko poslato Septembar 23, 2024, 13:04:12 POSLE PODNENapravio sam druge TDove i nema vise problem sa tim.
Jedini problem sad je taj sto se preview model u brzinometru ne update-uje kada udjem u vozilo.
public PlayerTimer(playerid){
if(IsPlayerInAnyVehicle(playerid)){
if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER){

new veh = GetPlayerVehicleID(playerid);
new sspeed[12];
format(sspeed, sizeof(sspeed), "%dkm/h", GetSpeed(playerid));
    PlayerTextDrawSetString(playerid, Speedometer[3][playerid], sspeed);

  new moda[30];
    GetVehicleName(veh, moda, sizeof(moda));
            PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda);
    PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
    PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], 0, 0);
}
}
}

a pod koji dio si stavio da ti pokrece tajmer ?
Ne treba ti ova provjera if(IsPlayerInAnyVehicle(playerid))ako si već stavio if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)uvjek kada nešto update-uješ preko tajmera vezano za textdraw, onda moraš ponovo da pokazes taj td.

public PlayerTimer(playerid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new veh = GetPlayerVehicleID(playerid), sspeed[12], moda[30];
format(sspeed, sizeof(sspeed), "%dkm/h", GetSpeed(playerid));
PlayerTextDrawSetString(playerid, Speedometer[3][playerid], sspeed);
PlayerTextDrawShow(playerid, Speedometer[3][playerid]);

GetVehicleName(veh, moda, sizeof(moda));
PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda);
PlayerTextDrawShow(playerid, Speedometer[0][playerid]);
     
PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], 0, 0);
PlayerTextDrawShow(playerid, Speedometer[2][playerid]);
}
return 1;
}

Pokusavao sam i da ga opet pokazem, i da ga unistim pa opet napravim ali nista.
Takodje, imam TD koji menja ime u zavisnosti od vozila, on radi bez ikakvog problema a ne pokazujem ga ponovo.
Timer se nalazi u "OnPlayerConnect" funkciji jer mi u tom timeru nece biti samo za vozila update-ovanje vec za novac, jail, vreme renta i slicno..
public OnPlayerConnect(playerid)
{
    CreatePlayerLower(playerid); CreatePlayerSpeedo(playerid);
    ResetVariables(playerid);
    SetPlayerCameraPos(playerid,1501.115478,-2291.721679,44.586883);
    SetPlayerCameraLookAt(playerid,1560.105346,-2309.231933,13.546875);
    ClearChatForPlayer(playerid);
    UpdatePlayer[playerid] = SetTimerEx("PlayerTimer", 1000, true, "i", playerid);
    return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if (oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER){
        for(new i = 0; i < 4; i++) { TextDrawShowForPlayer(playerid, Speedo[i]); }
for(new i = 0; i < 6; i++) { PlayerTextDrawShow(playerid, Speedometer[i][playerid]); }
    }
    return 1;
}
public PlayerTimer(playerid){
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
        new veh = GetPlayerVehicleID(playerid);
new sspeed[12];
format(sspeed, sizeof(sspeed), "%dkm/h", GetSpeed(playerid));
PlayerTextDrawSetString(playerid, Speedometer[3][playerid], sspeed); // Radi bez ponovnog pokazivanja TDa
new moda[30];
GetVehicleName(veh, moda, sizeof(moda));
  PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda); // radi bez ponovnog pokazivanja TDa
PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], 0, 0);
    }
}
Poslednja Izmena: Septembar 23, 2024, 13:29:26 POSLE PODNE od cofilinko
Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.

Pošalji mi citav textdraw vezan za vozilo
Speedometer[2][playerid]

Speedometer[2][playerid] = CreatePlayerTextDraw(playerid, 525.666748, 352.592529, "LD_SPAC:white");
PlayerTextDrawLetterSize(playerid, Speedometer[2][playerid], 0.023000, 4.521629);
PlayerTextDrawTextSize(playerid, Speedometer[2][playerid], 104.333374, 77.985244);
PlayerTextDrawAlignment(playerid, Speedometer[2][playerid], 1);
PlayerTextDrawColor(playerid, Speedometer[2][playerid], -1);
PlayerTextDrawUseBox(playerid, Speedometer[2][playerid], true);
PlayerTextDrawBoxColor(playerid, Speedometer[2][playerid], 0);
PlayerTextDrawSetShadow(playerid, Speedometer[2][playerid], 0);
PlayerTextDrawSetOutline(playerid, Speedometer[2][playerid], 0);
PlayerTextDrawFont(playerid, Speedometer[2][playerid], 5);
PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], 411);
PlayerTextDrawBackgroundColor(playerid, Speedometer[2][playerid], 0);
PlayerTextDrawSetPreviewRot(playerid, Speedometer[2][playerid], 0.0, 0.0, -20.0, 1.0);
Dodao sam komandu da proverim modelid vozila u kojem sam, prikazuje pravilan modelid.
Poslednja Izmena: Septembar 23, 2024, 13:34:40 POSLE PODNE od cofilinko
Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.

Zaboravio sam mozda najbitniju stvar. To se desava samo kada rentam vozilo i prebaci me u njega. Dodao sam iste linije koda kad iznajmi vozilo(da mu se sve promeni, ime, model) ali i dalje nista. Takodje, u funkciji "OnPlayerStateChange" sam stavio da sakrije TD a na timeru da ga pokaze i tako radi ali me uzasno zivcira to sto ga na svaku sekundu updatea i treperi.

UPDATE
Reseno, problem je ocigledno pravilo oldstate i newstate pa sam odradio ovako. Ako neko ima savet da odradim "lepse" neka napise primer, hvala.
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new veh = GetPlayerVehicleID(playerid);
if (oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER){
        for(new i = 0; i < 4; i++) { TextDrawShowForPlayer(playerid, Speedo[i]); }
for(new i = 0; i < 6; i++) { PlayerTextDrawShow(playerid, Speedometer[i][playerid]); }
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
for(new i = 0; i < 4; i++) { TextDrawShowForPlayer(playerid, Speedo[i]); }
for(new i = 0; i < 6; i++) { PlayerTextDrawShow(playerid, Speedometer[i][playerid]); }
    new moda[30];
GetVehicleName(veh, moda, sizeof(moda));
PlayerTextDrawShow(playerid, Speedometer[2][playerid]);
  PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda);
PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], -1, -1);
}
return 1;
}
Poslednja Izmena: Septembar 23, 2024, 13:52:35 POSLE PODNE od cofilinko
Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.

Citat: cofilinko poslato Septembar 23, 2024, 13:46:50 POSLE PODNEZaboravio sam mozda najbitniju stvar. To se desava samo kada rentam vozilo i prebaci me u njega. Dodao sam iste linije koda kad iznajmi vozilo(da mu se sve promeni, ime, model) ali i dalje nista. Takodje, u funkciji "OnPlayerStateChange" sam stavio da sakrije TD a na timeru da ga pokaze i tako radi ali me uzasno zivcira to sto ga na svaku sekundu updatea i treperi.

UPDATE
Reseno, problem je ocigledno pravilo oldstate i newstate pa sam odradio ovako. Ako neko ima savet da odradim "lepse" neka napise primer, hvala.
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new veh = GetPlayerVehicleID(playerid);
if (oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER){
        for(new i = 0; i < 4; i++) { TextDrawShowForPlayer(playerid, Speedo[i]); }
for(new i = 0; i < 6; i++) { PlayerTextDrawShow(playerid, Speedometer[i][playerid]); }
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER){
for(new i = 0; i < 4; i++) { TextDrawShowForPlayer(playerid, Speedo[i]); }
for(new i = 0; i < 6; i++) { PlayerTextDrawShow(playerid, Speedometer[i][playerid]); }
    new moda[30];
GetVehicleName(veh, moda, sizeof(moda));
PlayerTextDrawShow(playerid, Speedometer[2][playerid]);
  PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda);
PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], -1, -1);
}
return 1;
}


public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new veh = GetPlayerVehicleID(playerid);
   
    // Provjera samo kad igrač postane vozač
    if (newstate == PLAYER_STATE_DRIVER)
    {
        // Postavljanje imena vozila i modela u TextDraw
        new moda[30];
        GetVehicleName(veh, moda, sizeof(moda));
        PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda);
        PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
        PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], -1, -1);

        // Prikazivanje Speedo TextDraw-a
        for (new i = 0; i < 4; i++) {
            TextDrawShowForPlayer(playerid, Speedo[i]);
        }

        // Prikazivanje Speedometer PlayerTextDraw-a
        for (new i = 0; i < 6; i++) {
            PlayerTextDrawShow(playerid, Speedometer[i][playerid]);
        }
    }

    // Uklanjanje TextDraw-a ako igrač napusti vozilo
    if (newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
    {
        for (new i = 0; i < 4; i++) {
            TextDrawHideForPlayer(playerid, Speedo[i]);
        }

        for (new i = 0; i < 6; i++) {
            PlayerTextDrawHide(playerid, Speedometer[i][playerid]);
        }
    }

    return 1;
}

Ovakav bi kod trebao da bude, krace i bolje od ovoga ne može
Poslednja Izmena: Septembar 23, 2024, 14:34:21 POSLE PODNE od K ROSE

Citat: K ROSE poslato Septembar 23, 2024, 14:32:35 POSLE PODNEpublic OnPlayerStateChange(playerid, newstate, oldstate)
{
    new veh = GetPlayerVehicleID(playerid);
   
    // Provjera samo kad igrač postane vozač
    if (newstate == PLAYER_STATE_DRIVER)
    {
        // Postavljanje imena vozila i modela u TextDraw
        new moda[30];
        GetVehicleName(veh, moda, sizeof(moda));
        PlayerTextDrawSetString(playerid, Speedometer[0][playerid], moda);
        PlayerTextDrawSetPreviewModel(playerid, Speedometer[2][playerid], GetVehicleModel(veh));
        PlayerTextDrawSetPreviewVehCol(playerid, Speedometer[2][playerid], -1, -1);

        // Prikazivanje Speedo TextDraw-a
        for (new i = 0; i < 4; i++) {
            TextDrawShowForPlayer(playerid, Speedo);
        }

        // Prikazivanje Speedometer PlayerTextDraw-a
        for (new i = 0; i < 6; i++) {
            PlayerTextDrawShow(playerid, Speedometer[playerid]);
        }
    }

    // Uklanjanje TextDraw-a ako igrač napusti vozilo
    if (newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER)
    {
        for (new i = 0; i < 4; i++) {
            TextDrawHideForPlayer(playerid, Speedo);
        }

        for (new i = 0; i < 6; i++) {
            PlayerTextDrawHide(playerid, Speedometer[playerid]);
        }
    }

    return 1;
}
Radi kao sat, hvala ti
Aj napuni pun i vozi odavde,
na autoput u najveci krug,
da najbolje razmislim ko mi je drug.