Portal SAMP
[Ajuda] bug no checkpoint - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] bug no checkpoint (/showthread.php?tid=4951)



bug no checkpoint - LOS_SANTOS - 12/01/2025

ola pessoal alguem sabe me dizer oq fiz de errado pois quando eu passo no primeiro checkpoint ele vai pro meio do mapa bem no meio do mapa do gta sa e nao segue as floats que coloquei alguem poderia me dizer pois ja estou quebando a cabeca e nao conesgui resolver 
Código:
#include <a_samp>
#include <zcmd>

new playerinminigame[MAX_PLAYERS];
#define spawnX 1310.000000
#define spawnY -1370.199951
#define spawnZ 13.500000
new startvar[8];
new karts[15],kartfull[15],karton,kartplaying,playerinkartrace[MAX_PLAYERS],kartrank,playerinkart[MAX_PLAYERS],currentcheckpoint[MAX_PLAYERS],krtfirst,playercarid[MAX_PLAYERS], reward;
new krttimer;
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
forward load();
forward SpawnKarts();// KartRace
forward DestroyKarts();
forward RespawnKarts();
forward StartKart();
forward KrtFinish();
forward RewardCalc(playerid,min,max);// General reward calc.
// Karts:
new Float:kartspawns[15][4] = {
{-1366.1909,906.8451,1040.5919,280.3004}, // 0
{-1366.4854,908.3992,1040.2843,280.3004}, // 1
{-1366.8508,910.3288,1039.9022,280.3004}, // 2
{-1367.2168,912.2613,1039.5195,280.3004}, // 3
{-1367.7562,915.1094,1038.9557,280.3004}, // 4
{-1368.4265,918.6667,1038.4503,280.3231}, // 5
{-1368.8036,920.6827,1038.1428,280.3231}, // 6
{-1369.1410,922.4866,1037.8677,280.3231}, // 7
{-1372.5338,921.9490,1037.9705,277.8816}, // 8
{-1372.2379,919.8677,1038.2872,277.8816}, // 9
{-1371.9086,917.5515,1038.6396,277.8816}, // 10
{-1371.6196,915.5192,1038.9486,277.8816}, // 11
{-1371.2595,912.9866,1039.3340,277.8816}, // 12
{-1371.0453,911.4792,1039.5632,277.8816}, // 13
{-1370.6086,908.9531,1040.1785,275.7079} // 14
};
// Kartrace checkpoints:
new Float:kcps[7][3] = {
{-1334.6268,1072.9838,1038.8698},//0
{-1532.7769,978.7280,1038.5687},//1
{-1332.9595,919.8433,1039.1349},//2
{-1296.7030,1050.9790,1038.5775},//3
{-1450.3383,1072.0515,1038.7230},//4
{-1474.1315,923.6363,1039.0023},//5
{-1259.3616,983.0872,1039.0122}//6
};
public OnGameModeInit()
{
    SetTimer("load",2000,0);
    return 1;
}

public OnGameModeExit()
{
    DestroyKarts();
    return 1;
}
public OnPlayerConnect(playerid)
{
    playerinminigame[playerid] = 0; // checar se o jagador ta na corrida
    playercarid[playerid] = -1; // carro atual do jogador esta
    playerinkartrace[playerid] = 0; // Kart Race
    playerinkart[playerid] = -1;
    currentcheckpoint[playerid] = 0;
    return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
    new string[256];
    playerinminigame[playerid] = 0;
    if(playerinkartrace[playerid] == 1) {
    new KartPlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, KartPlayerName, sizeof(KartPlayerName));
    format(string, sizeof(string), "%s foi descartado da corrida de kart", KartPlayerName);
    SendClientMessageToAll(0x33AA33AA, string);
    playerinkartrace[playerid] = 0;
    playerinminigame[playerid] = 0;
    kartfull[playerinkart[playerid]] = 0;
    playerinkart[playerid] = -1;
    if(kartrank <= 1)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if (IsPlayerConnected(i) && playerinkartrace[i] == 1)
            {
                playerinkartrace[i] = 0;
                playerinminigame[i] = 0;
                SetPlayerVirtualWorld(i,0);
                SetPlayerInterior(playerid, 0);
                SetPlayerPos(i, spawnX, spawnY, spawnZ);
            }
        }
        kartplaying = 0;
        kartrank = 0;
        karton = 0;
        KillTimer(krttimer);
        RespawnKarts();
        return 1;
    }
    kartrank--;
    }
    return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
    new string[256];
    if(playerinkartrace[playerid] == 1) {
    new KartPlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, KartPlayerName, sizeof(KartPlayerName));
    format(string, sizeof(string), "%s foi descartado da corrida de kart", KartPlayerName);
    SendClientMessageToAll(0x33AA33AA, string);
    playerinkartrace[playerid] = 0;
    playerinminigame[playerid] = 0;
    kartfull[playerinkart[playerid]] = 0;
    playerinkart[playerid] = -1;
    if(kartrank <= 1)
    {
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if (IsPlayerConnected(i) && playerinkartrace[i] == 1)
            {
                playerinkartrace[i] = 0;
                playerinminigame[i] = 0;
                SetPlayerVirtualWorld(i,0);
                SetPlayerInterior(playerid, 0);
                SetPlayerPos(i, spawnX, spawnY, spawnZ);
            }
        }
        kartplaying = 0;
        kartrank = 0;
        karton = 0;
        KillTimer(krttimer);
        RespawnKarts();
        return 1;
    }
    kartrank--;
    }
    return 1;
}

//comandos

CMD:kart(playerid)
{
    new string[256];
    if(kartplaying == 1)return SendClientMessage(playerid, 0xB4B5B7AA, "A corrida de kart já começou");
    if(playerinminigame[playerid] == 1)return SendClientMessage(playerid, 0xB4B5B7AA, "Você já está em um minigame");
    new pname[256];
    GetPlayerName(playerid, pname, 256);
    if(karton == 0)
    {
        karton = 1;
        playerinminigame[playerid] = 1;
        playerinkartrace[playerid] = 1;
        kartrank = 1;
        krtfirst = 1;
        currentcheckpoint[playerid] = 0;
        SetPlayerInterior(playerid,15);
        SetPlayerVirtualWorld(playerid,7);
        SetVehicleVirtualWorld(karts[0],7);
        kartfull[0] = 1;
        PutPlayerInVehicle(playerid, karts[0], 0);
        playerinkart[playerid] = 0;
        TogglePlayerControllable(playerid, 0);
        SetPlayerRaceCheckpoint(playerid,0,kcps[0][0],kcps[0][1],kcps[0][2],kcps[1][0],kcps[1][1],kcps[1][2],20);
        startvar[6] = 1;
        krttimer = SetTimer("StartKart", 60000, 0);
        format(string, sizeof(string), "%s deu início a uma corrida de kart, você tem um minuto para escrever / kartrace e juntar-se", pname);//
        SendClientMessageToAll(0x33AA33AA,string);
        return 1;
    } else if(karton == 1 && kartrank < 15) {
        playerinminigame[playerid] = 1;
        playerinkartrace[playerid] = 1;
        kartrank++;
        currentcheckpoint[playerid] = 0;
        SetPlayerInterior(playerid,15);
        for(new i=0; i<15; i++)
        {
            if(kartfull[i] == 0)
            {
                SetPlayerVirtualWorld(playerid,7);
                SetVehicleVirtualWorld(karts[i],7);
                kartfull[i] = 1;
                PutPlayerInVehicle(playerid, karts[i], 0);
                TogglePlayerControllable(playerid, 0);
                SetPlayerRaceCheckpoint(playerid,0,kcps[0][0],kcps[0][1],kcps[0][2],kcps[1][0],kcps[1][1],kcps[1][2],20);
                playerinkart[playerid] = i;
                format(string, sizeof(string), "%s juntou-se a corrida de kart", pname);//
                SendClientMessageToAll(0x33AA33AA,string);
                return 1;
            }
        }
    } else if(karton == 1 && kartrank >= 15) {
        format(string, sizeof(string), "A corrida de kart está cheia, esperar para a próxima rodada", pname);//
        SendClientMessage(playerid,0x33AA33AA,string);
        return 1;
    }
    return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == 2)
    {
        playercarid[playerid] = GetPlayerVehicleID(playerid);
    }
    if(oldstate == 2)
    {
        if(playerinkartrace[playerid])
        {
            PutPlayerInVehicle(playerid,playercarid[playerid],0);
        }
    }
    return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
    if(playerinkartrace[playerid]) {
    if(currentcheckpoint[playerid] <= 2)
    {
        currentcheckpoint[playerid]++;
        DisablePlayerRaceCheckpoint(playerid);
        SetPlayerRaceCheckpoint(playerid,0,kcps[currentcheckpoint[playerid]][0],kcps[currentcheckpoint[playerid]][1],kcps[currentcheckpoint[playerid]][2],
        kcps[currentcheckpoint[playerid]+1][0],kcps[currentcheckpoint[playerid]+1][1],kcps[currentcheckpoint[playerid]+1][2],20);
    } else if(currentcheckpoint[playerid] >= 3 && currentcheckpoint[playerid] != 7) {
        currentcheckpoint[playerid]++;
        DisablePlayerRaceCheckpoint(playerid);
        SetPlayerRaceCheckpoint(playerid,0,kcps[currentcheckpoint[playerid]-4][0],kcps[currentcheckpoint[playerid]-4][1],
        kcps[currentcheckpoint[playerid]-4][2],kcps[currentcheckpoint[playerid]-3][0],kcps[currentcheckpoint[playerid]-3][1],
        kcps[currentcheckpoint[playerid]-3][2],20);
    } else if(currentcheckpoint[playerid] == 7) {
    if(krtfirst == 1)
        {
            DisablePlayerRaceCheckpoint(playerid);
            new string[256];
            krtfirst++;
            kartrank--;
            new winnername[256];
            GetPlayerName(playerid,winnername, sizeof(winnername));
            RewardCalc(playerid,5000,10000);
            format(string, sizeof(string), "%s ganhou a corrida de kart e ganhou $%d", winnername, reward);
            SendClientMessageToAll(0x33AA33AA, string);
            GivePlayerMoney(playerid,reward);
            playerinkartrace[playerid] = 0;
            playerinminigame[playerid] = 0;
            currentcheckpoint[playerid] = 0;
            SetPlayerVirtualWorld(playerid,0);
            SetPlayerInterior(playerid, 0);
            SetPlayerPos(playerid, spawnX, spawnY, spawnZ);
            if(kartrank == 0)
            {
                KrtFinish();
            } else {
                SetTimer("KrtFinish",60000,0);
            }
        } else {
            DisablePlayerRaceCheckpoint(playerid);
            playerinkartrace[playerid] = 0;
            playerinminigame[playerid] = 0;
            currentcheckpoint[playerid] = 0;
            SetPlayerVirtualWorld(playerid,0);
            SetPlayerInterior(playerid, 0);
            SetPlayerPos(playerid, spawnX, spawnY, spawnZ);
            if(kartrank == 0)
            {
                KrtFinish();
            } else {
                SetTimer("KrtFinish",60000,0);
            }
        }
      }
    }
    return 1;
}
public SpawnKarts()
{
    for(new i=0; i<15; i++)
    {
        karts[i] = CreateVehicle(571,kartspawns[i][0],kartspawns[i][1],kartspawns[i][2],kartspawns[i][3],-1,-1,-1);
        LinkVehicleToInterior(karts[i],15);
        SetVehicleVirtualWorld(karts[i],1);
        kartfull[i] = 0;
    }
    return 1;
}

public DestroyKarts()
{
    for(new i=0; i<15; i++)
    {
        DestroyVehicle(karts[i]);
        kartfull[i] = 0;
    }
}

public RespawnKarts()
{
    for(new i=0; i<15; i++)
    {
        SetVehicleToRespawn(karts[i]);
        SetVehicleVirtualWorld(karts[i],1);
        kartfull[i] = 0;
    }
}

public StartKart()
{
    if(startvar[6] == 1) {
        if(kartrank <= 0 )//1
        {
            SendClientMessageToAll(0x33AA33AA, "corrida de Kart cancelado. Motivo: Jogadores Insuficientes (Minimo = 2)");
            kartplaying = 0;
            kartrank = 0;
            karton = 0;
            startvar[6] = 0;
            RespawnKarts();
            for(new i = 0; i <= MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                    if (playerinkartrace[i] == 1)
                    {
                        playerinkartrace[i] = 0;
                        playerinminigame[i] = 0;
                        playerinkart[i] = -1;
                        SetPlayerVirtualWorld(i,0);
                        SetPlayerInterior(i, 0);
                        SetPlayerPos(i, spawnX, spawnY, spawnZ);
                        TogglePlayerControllable(i, 1);
                    }
                }
            }
            return 1;
         }
        new string[32];
        format(string, sizeof(string), "~r~3");
        new gdelay=1000;
        kartplaying = 1;
        for(new i = 0; i <= MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if (playerinkartrace[i] == 1)
                {
                    GameTextForPlayer(i, string, gdelay, 6);
                    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
                }
            }
        }
        startvar[6] = 2;
        SetTimer("StartKart", gdelay, 0);
    } else if(startvar[6] == 2) {
        new string[32];
        format(string, sizeof(string), "~r~2");
        new hdelay=1000;
        for(new i = 0; i <= MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if (playerinkartrace[i] == 1)
                {
                    GameTextForPlayer(i, string, hdelay, 6);
                    PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
                }
            }
        }
        startvar[6] = 3;
        SetTimer("StartKart", hdelay, 0);
    } else if(startvar[6] == 3) {
        new rdelay=1000;
        new string[32];
        format(string, sizeof(string), "~g~1!");
        for(new i = 0; i <= MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if (playerinkartrace[i] == 1)
                {
                    GameTextForPlayer(i, string, rdelay, 6);
                    PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
                    TogglePlayerControllable(i, 1);
                }
            }
        }
        SetTimer("KrtFinish",300000,0);
        startvar[6] = 0;
    }
    return 1;
}

public RewardCalc(playerid,min,max)//Originally from PenLS
{
    reward = (min + (random(max-min)));
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        tempposx = (oldposx -x);
        tempposy = (oldposy -y);
        tempposz = (oldposz -z);
        if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
        {
            return 1;
        }
    }
    return 0;
}

public load()
{
    SpawnKarts();
}

public KrtFinish()
{
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if (playerinkartrace[i] == 1)
            {
                playerinkartrace[i] = 0;
                playerinminigame[i] = 0;
                SetPlayerVirtualWorld(i,0);
                SetPlayerInterior(i, 0);
                SetPlayerPos(i, spawnX, spawnY, spawnZ);
            }
        }
    }
    kartplaying = 0;
    kartrank = 0;
    karton = 0;
    RespawnKarts();
    SendClientMessageToAll(0x33AA33AA, "A corrida de kart acabou");
    return 1;
}



RE: bug no checkpoint - xbruno1000x - 13/01/2025

Não vi erro algum no seu código, então realizei testes no bare GM(GM que vem com o SAMP Server). A corrida rodou perfeitamente, não houve problema algum. Ganhei, fui premiado, tudo conforme o previsto. O que deve estar acontecendo é algum tipo de conflito entre o seu gamemode e o script. Tente rodar em filterscript e veja se o problema permanece.


RE: bug no checkpoint - André Santos - 14/01/2025

(13/01/2025 17:52)xbruno1000x Escreveu: Não vi erro algum no seu código, então realizei testes no bare GM(GM que vem com o SAMP Server). A corrida rodou perfeitamente, não houve problema algum. Ganhei, fui premiado, tudo conforme o previsto. O que deve estar acontecendo é algum tipo de conflito entre o seu gamemode e o script. Tente rodar em filterscript e veja se o problema permanece.

Verdade Bruno vi agora que foi conflitos de muitas coisas na GM então recrie do 0 tudo de novo e ficou tudo funcional , obg pela resposta , aliás posta lá no fs pra quem quiser vlw boa tarde