SA-MP Forums Archive
[PEDIDO] Funзгo 1 hp por segundo - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [PEDIDO] Funзгo 1 hp por segundo (/showthread.php?tid=289490)



[PEDIDO] Funзгo 1 hp por segundo - Mattos - 11.10.2011

Olб pessoal eu tenho a seguinte linha no meu GM:

pawn Код:
if (DistanciaPontos(1607.537353, 1817.338500, ppx, ppy) < 3)    return SetPlayerHealth(playerid, 100.000000);
Sу que eu nao queria que o cara ganhasse logo de cara 100 de vida... Os outros players reclamam de nao poder matб-lo...

Entгo eu queria saber como fazer com que quando um jogador fizasse dentro destes pontos ele recebesse 1 hp a cada 1 segundo sendo que nao pode ultrapassar 100 de hp...
Eu pensei em fazer uma public e tals mas nao sei como fazer o timer pra ele dar 1 hp por segundo...


Re: [PEDIDO] Funзгo 1 hp por segundo - cotonete - 11.10.2011

faзa algo como:

Код:
forward ganharhp();
public ganharhp()
{
    // como vamos tratar todo mundo, vamos usar um loop
    for(new i = 0; i < MAX_PLAYERS; ++i)
    {
       if (DistanciaPontos(1607.537353, 1817.338500, ppx, ppy) < 3) 
{
          new Float:pHealth;
          GetPlayerHealth(i,pHealth);
          if(pHealth < 100)
                 SetPlayerHealth(i, pHealth+1);       
}
    return 1;
} 

// ModeInit
SetTimer("ganharhp", 1000, true);



Re: [PEDIDO] Funзгo 1 hp por segundo - Pharrel - 11.10.2011

pawn Код:
new TimerGiveHP[MAX_PLAYERS];//topo do GM

//onplayerconect
TimerGiveHP[playerid] = SetTimerEx("HealthXXX", 1000, true, "i", playerid);

//onplayerdisconect
KillTimer(TimerGiveHP[playerid]);

//fora de funзхes
forward HealthXXX(playerid);
public HealthXXX(playerid)
{
    if(DistanciaPontos(1607.537353, 1817.338500, ppx, ppy) < 3)
    {
        new Float:hp;
        GetPlayerHealth(playerid, hp);
        if(hp <= 100)
            SetPlayerHealth(playerid, hp++);// c n funcionar acom hp++ tenta hp+1
    }
    return 1;
}



Re: [PEDIDO] Funзгo 1 hp por segundo - Mattos - 11.10.2011

Pharrel isso nao vai lagar o sv...? um timer no connect... pq ae o timer vai ficar com o player atй ele deslogar...


Re: [PEDIDO] Funзгo 1 hp por segundo - Pharrel - 11.10.2011

o timer no ongamemodeinit й um timer que fica atй vc desligar o servidor, ou seja, enquanto o servidor estiver online o timer vai tar contando e fazendo o loop desnecessбrio ou seja, no caso do codigo acima do meu...

o game mode inicia... o timer inicia e a cada 1 segundo ele faz um loop de 500 players e o timer sу desativa qdo o sv fecha

no caso do meu... o player conecta o timer inicia e checa sу pros players online e qdo ele desloga o timer desliga


Re: [PEDIDO] Funзгo 1 hp por segundo - Vai_Besta - 11.10.2011

Assim?
pawn Код:
if (DistanciaPontos(1607.537353, 1817.338500, ppx, ppy) < 3)
{
    new Float:vida[MAX_PLAYERS];
    GetPlayerHealth(playerid, vida[playerid]);
    if(vida[playerid] <= 100)  SetPlayerHealth(playerid, vida[playerid]+1);
    return 1;
}



Re: [PEDIDO] Funзгo 1 hp por segundo - Mattos - 11.10.2011

Besta assim sу vai subir 1 de vida... e ae o cara iria entrar e sair do ponto pra ir ganhando vida...


Re: [PEDIDO] Funзгo 1 hp por segundo - Vai_Besta - 11.10.2011

Entao crie uma timer para checar se ele esta dentro do ponto


Re: [PEDIDO] Funзгo 1 hp por segundo - DreeH - 11.10.2011

PHP код:
if (DistanciaPontos(1607.5373531817.338500ppxppy) < 3)
{
    
SetTimerEx("GanharVida"1000true"i"playerid);
}
// FIM DO GM
forward GanharVida(playerid);
public 
GanharVida(playerid)
{
    new
        
FloatVida[MAX_PLAYERS char]
    ;
    
GetPlayerHealth(playeridVida[playerid]);
    if(
Vida[playerid] < 100)
        return 
SetPlayerHealth(playeridVida[playerid]++);
    return 
Vida;

\/


Re: [PEDIDO] Funзгo 1 hp por segundo - Pharrel - 11.10.2011

n funcionou o q eu fiz mateus?