Detectar 2+ players online -
GabrielGoncalves - 13.08.2015
Bom, preciso saber, como faзo pra detectar quando o servidor tiver 2 players ou mais online para dar inicio a partida.
No caso, sei lб, quando tiver dois players ou mais online, ai dб um comando tipo "/comecar" automaticamente.
Assim, quando tiver menos, nгo irб acontecer nada. Apenas iram para uma posiзгo.
Re: Detectar 2 players online -
99fe3rnando - 13.08.2015
Desculpe se eu esqueci de alguma coisa estou morrendo de sono ^^
PHP код:
#include <a_samp>
new PlayersOnEvent;
new PlayerInEvent[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
PlayersOnEvent += 1;
if(PlayersOnEvent >= 2)
{
SendClientMessageToAll(-1, "Evento Iniciado !");
for(new i=0; i<MAX_PLAYERS; i++)
{
SetPlayerPos(i, 0.0, 0.0, 3.0);
PlayerInEvent[playerid] = 1;
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
PlayersOnEvent -= 1;
CloseEvent();
PlayerInEvent[playerid] = 0;
return 1;
}
stock CloseEvent()
{
if(PlayersOnEvent == 1)
{
SendClientMessageToAll(-1, "Evento fechado player saiu !");
for(new i=0; i<MAX_PLAYERS; i++)
{
if(PlayerInEvent[i] == 1)
{
SetPlayerPos(i, 0.0, 0.0, 3.0);
PlayerInEvent[i] = 0;
}
}
}
return 1;
}
e aqui um com comandos /comecarev /terminarev
PHP код:
#include <a_samp>
new PlayersOnEvent;
new PlayerInEvent[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
PlayersOnEvent += 1;
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
PlayersOnEvent -= 1;
PlayerInEvent[playerid] = 0;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/comecarev", cmdtext, true, 10) == 0)
{
if(PlayersOnEvent >= 2)
{
SendClientMessageToAll(-1, "Evento Iniciado");
PlayerInEvent[playerid] = 1;
for(new i=0; i<MAX_PLAYERS; i++)
{
SetPlayerPos(i, 0.0, 0.0, 3.0);
}
}
else
{
SendClientMessageToAll(-1, "Nгo existem players suficientes para iniciar!");
}
return 1;
}
if (strcmp("/terminarev", cmdtext, true, 11) == 0)
{
if(PlayersOnEvent == 1)
{
SendClientMessageToAll(-1, "Evento fechado!");
for(new i=0; i<MAX_PLAYERS; i++)
{
if(PlayerInEvent[i] == 1)
{
SetPlayerPos(i, 0.0, 0.0, 3.0);
PlayerInEvent[i] = 0;
}
}
}
return 1;
}
return 0;
}
Re: Detectar 2 players online -
ipsLuan - 13.08.2015
Loop.
Re: Detectar 2 players online -
GabrielGoncalves - 13.08.2015
Outra pergunta, fiz um timer aqui, pra ir diminuindo, pra iniciar a partida, mais nгo funciona.
PHP код:
stock Comecar(playerid)
{
static str1[128];
pInfo[playerid][pRestartTime]++;
format(str1, sizeof(str1), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~Carregando... %d", 15 - pInfo[playerid][pRestartTime]);
GameTextForPlayer(playerid, str1, 1000, 3);
if (pInfo[playerid][pRestartTime] >= 15)
{
pInfo[playerid][pRestartTime] = 0;
//Aqui vai ter as paradas de quando o jogo iniciar
}
return 1;
}
Ele nгo vai diminuindo, tipo, 15, 14, 13. Ele trava no 14, ai vocк precisa dar o comando novamente pra ir pro 13.
Re: Detectar 2 players online -
ipsLuan - 13.08.2015
PHP код:
SetTimer("Iniciar", 1000, true);
stock Iniciar()
{
new
Tempo_Inicial = 15,
static str1[128]
;
format(str1, sizeof(str1), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~w~Carregando... %d", Tempo_Inicial);
GameTextForAll(str1, 1000, 3);
Tempo_Inicial--;
if(Tempo_Inicial <= 0)
{
GameTextForAll("Comeзem!", 1000);
Tempo_Inicial = 0;
KillTimer(Tempo_Inicial);
}
return 1;
}
Re: Detectar 2 players online -
GabrielGoncalves - 13.08.2015
Nгo funciono, ele nгo sai do 15 agora.
Re: Detectar 2 players online -
ipsLuan - 13.08.2015
Vocк adicionou o SetTimer que te mandei?
Re: Detectar 2 players online -
GabrielGoncalves - 13.08.2015
Sim, tб tudo certinho.
Re: Detectar 2 players online -
ipsLuan - 13.08.2015
#edit
Fiz uns testes aqui e consegui, mas quando coloco o timer nгo vai, deve ser por que estou com pressa. Estou indo pro colйgio, assim que eu voltar, (re)faзo o comando e te envio o cуdigo.
PHP код:
//Inicio do GameMode
new Tempo_Inicial = 15;
stock Iniciar()
{
printf("%d", Tempo_Inicial);
Tempo_Inicial--;
printf("%d", Tempo_Inicial);
Tempo_Inicial--;
printf("%d", Tempo_Inicial);
Tempo_Inicial--;
printf("%d", Tempo_Inicial);
Tempo_Inicial--;
printf("%d", Tempo_Inicial);
Tempo_Inicial--;
printf("%d", Tempo_Inicial);
Tempo_Inicial--;
}
Re: Detectar 2 players online -
GabrielGoncalves - 13.08.2015
Beleza cara, valeu pela ajuda.
Valeu tambйm Fernando, funcionou aqui.