Portal SAMP
[Ajuda] OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - 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] OnPlayerUpdate ou timer para verificar qual arma o player ta em maos (/showthread.php?tid=1077)



OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - zBL4CK - 12/04/2021

Bom Galera estou fazendo um sistema de colar armas no corpo do player de acordo com a arma que ele tem ou seja(seto uma arma nele ex: (GivePlayerWeapon(playerid, 26, 99)porem quando o player mudar de arma essa arma que ele tava em maos dou um attach nela no corpo. essa parte eu sei fazer porem eu fiquei na duvida e queria saber de vcs. Para ficar dando update toa vez que o player trocar de arma é mais otimizado usar(OnPlayerUpdate ou timer com 1s) é obvio que ambas vao torna o server pesado ainda mais quando haver varios players porem quero saber a que é mais em conta ou seja, a que menos pese


se alguem souber outra forma mais otimizada de fazer esse sistema agradeço!

o objetivo do sistema é detectar toda vez que o player trocou de arma e pegar a arma que foi trocada e dar um attach no corpo da skin.

enfim se alguém souber métodos e puder compartilhar agradeço!


RE: OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - diogo123 - 13/04/2021

na verdade, não e muito recomendado utilizar a OnPlayerUpdate, vide informações da open mp.

Citar:[font=Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif]This callback is called, on average, 30 times per second, per player; only use it when you know what it's meant for (or more importantly what it's NOT meant for). The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling.[/font]



RE: OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - zBL4CK - 13/04/2021

(13/04/2021 00:05)diogo123 Escreveu: na verdade, não e muito recomendado utilizar a OnPlayerUpdate, vide informações da open mp.

Citar:[font=Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif]This callback is called, on average, 30 times per second, per player; only use it when you know what it's meant for (or more importantly what it's NOT meant for). The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling.[/font]
Tem alguma forma mais otimizada?


RE: OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - xbruno1000x - 13/04/2021

(13/04/2021 01:32)zBL4CK Escreveu:
(13/04/2021 00:05)diogo123 Escreveu: na verdade, não e muito recomendado utilizar a OnPlayerUpdate, vide informações da open mp.

Citar:[font=Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif]This callback is called, on average, 30 times per second, per player; only use it when you know what it's meant for (or more importantly what it's NOT meant for). The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling.[/font]
Tem alguma forma mais otimizada?

Busque nas keys do samp pela tecla de mudar de arma, se houver poderá usar a public KeyStateChange e executar a função apenas quando o player clicar na tecla de mudar arma.


RE: OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - zBL4CK - 13/04/2021

(13/04/2021 01:49)xbruno1000x Escreveu:
(13/04/2021 01:32)zBL4CK Escreveu:
(13/04/2021 00:05)diogo123 Escreveu: na verdade, não e muito recomendado utilizar a OnPlayerUpdate, vide informações da open mp.

Citar:[font=Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif]This callback is called, on average, 30 times per second, per player; only use it when you know what it's meant for (or more importantly what it's NOT meant for). The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling.[/font]
Tem alguma forma mais otimizada?

Busque nas keys do samp pela tecla de mudar de arma, se houver poderá usar a public KeyStateChange e executar a função apenas quando o player clicar na tecla de mudar arma.
ta mas isso funcionará no android tb?


RE: OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - ForT - 13/04/2021

(13/04/2021 01:32)zBL4CK Escreveu:
(13/04/2021 00:05)diogo123 Escreveu: na verdade, não e muito recomendado utilizar a OnPlayerUpdate, vide informações da open mp.

Citar:[font=Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif]This callback is called, on average, 30 times per second, per player; only use it when you know what it's meant for (or more importantly what it's NOT meant for). The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling.[/font]
Tem alguma forma mais otimizada?

Você não precisa criar um timer pra isso, em OnPlayerUpdate basta usar o gettime para fazer a checagem de 1 em 1 segundo.
Código PHP:
new playerLastCheckWeapons[MAX_PLAYERS];

public 
OnPlayerUpdate(playerid)
{
    new current_unix gettime();

    if (current_unix playerLastCheckWeapons[playerid])
    {
        playerLastCheckWeapons[playerid] = current_unix 1// Segundos para a próxima checagem.

        // Checar as armas do jogador aqui:
        GetPlayerWeaponData(playerid...
    }

    return 1;




RE: OnPlayerUpdate ou timer para verificar qual arma o player ta em maos - zBL4CK - 13/04/2021

(13/04/2021 02:34)ForT Escreveu:
(13/04/2021 01:32)zBL4CK Escreveu:
(13/04/2021 00:05)diogo123 Escreveu: na verdade, não e muito recomendado utilizar a OnPlayerUpdate, vide informações da open mp.

Citar:[font=Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif]This callback is called, on average, 30 times per second, per player; only use it when you know what it's meant for (or more importantly what it's NOT meant for). The frequency with which this callback is called for each player varies, depending on what the player is doing. Driving or shooting will trigger a lot more updates than idling.[/font]
Tem alguma forma mais otimizada?

Você não precisa criar um timer pra isso, em OnPlayerUpdate basta usar o gettime para fazer a checagem de 1 em 1 segundo.
Código PHP:
new playerLastCheckWeapons[MAX_PLAYERS];

public 
OnPlayerUpdate(playerid)
{
    new current_unix gettime();

    if (current_unix playerLastCheckWeapons[playerid])
    {
        playerLastCheckWeapons[playerid] = current_unix 1// Segundos para a próxima checagem.

        // Checar as armas do jogador aqui:
        GetPlayerWeaponData(playerid...
    }

    return 1;

Vlww