Detectar ъltimo jugador vivo.
#1

Planeo hacer un DM, en el cual hayan 10 participantes, se mataran entre todos para ser el ъltimo vivo en un mapa no tan grande y todo, el problema es que no estoy seguro de como detectar al ъltimo jugador vivo y que le dй la recompensa, esa es mi duda.

Si alguien pudiera ayudarme se lo agradecerнa mucho.
Reply
#2

Bueno, hay una forma simple:

Colocas a todos los jugadores que van a participar en el DM en un mismo mundo virtual (por ejemplo: 10), luego a cada uno aplicas un Timer de unos 3 segundos, aсades estas funciones:

pawn Код:
forward Float:GetDistanceBetweenPlayers(P1, P2); // Detectar la distancia entre los jugadores.
forward GetClosestPlayer(P1); // Detectar al jugador mбs cercano.
pawn Код:
public GetClosestPlayer(P1)
{
new X, Float:Dis, Float:Dis2, Player;
Player = -1;
Dis = 99999.99;
for(X = 0; X < MAX_PLAYERS; X++)
{
if(IsPlayerConnected(X))
{
if(X != P1)
{
Dis2 = GetDistanceBetweenPlayers(X, P1);
if(Dis2 < Dis && Dis2 != -1.00)
{
Dis = Dis2;
Player = X;
}
}
}
}
return Player;
}
pawn Код:
public Float:GetDistanceBetweenPlayers(P1, P2)
{
new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
if(!IsPlayerConnected(P1) || !IsPlayerConnected(P2))
{
return -1.00;
}
GetPlayerPos(P1, X1, Y1, Z1);
GetPlayerPos(P2, X2, Y2, Z2);
return floatsqroot(floatpower(floatabs(floatsub(X2, X1)), 2) + floatpower(floatabs(floatsub(Y2, Y1)), 2) + floatpower(floatabs(floatsub(Z2, Z1)), 2));
}
Y en el timer pones algo como:

pawn Код:
new Target = GetClosestPlayer(playerid);
if(IsPlayerConnected(Target))
if((GetDistanceBetweenPlayers(playerid, Target) > 2000 && (GetPlayerVirtualWorld(Target) == GetPlayerVirtualWorld(playerid))) // El valor 2000 es la distancia, lo puedes cambiar a otro si quieres.
{
SendClientMessage(playerid, -1, "Ningъn jugador cerca."); // Acб la funciуn para ganar.
}
Suerte amigo
Reply
#3

Quote:
Originally Posted by Ygzeb
Посмотреть сообщение
Bueno, hay una forma simple:

Colocas a todos los jugadores que van a participar en el DM en un mismo mundo virtual (Por ejemplo: 10), luego a cada uno aplicas un Timer de unos 3 segundos, aсades estas funciones:

pawn Код:
forward Float:GetDistanceBetweenPlayers(P1, P2);
forward GetClosestPlayer(P1);
pawn Код:
public GetClosestPlayer(P1)
{
new X, Float:Dis, Float:Dis2, Player;
Player = -1;
Dis = 99999.99;
for(X = 0; X < MAX_PLAYERS; X++)
{
if(IsPlayerConnected(X))
{
if(X != P1)
{
Dis2 = GetDistanceBetweenPlayers(X, P1);
if(Dis2 < Dis && Dis2 != -1.00)
{
Dis = Dis2;
Player = X;
}
}
}
}
return Player;
}
pawn Код:
public Float:GetDistanceBetweenPlayers(P1, P2)
{
new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
if(!IsPlayerConnected(P1) || !IsPlayerConnected(P2))
{
return -1.00;
}
GetPlayerPos(P1, X1, Y1, Z1);
GetPlayerPos(P2, X2, Y2, Z2);
return floatsqroot(floatpower(floatabs(floatsub(X2, X1)), 2) + floatpower(floatabs(floatsub(Y2, Y1)), 2) + floatpower(floatabs(floatsub(Z2, Z1)), 2));
}
Y en el timer pones algo como:

pawn Код:
new Target = GetClosestPlayer(playerid);
if(IsPlayerConnected(Target))
if((GetDistanceBetweenPlayers(playerid, Target) > 2000 && (GetPlayerVirtualWorld(Target) == GetPlayerVirtualWorld(playerid))) // El valor 2000 es la distancia, lo puedes cambiar a otro si quieres.
{
SendClientMessage(playerid, -1, "Ningъn jugador cerca."); // Acб la funciуn para ganar.
}
Suerte amigo
Almenos anda explicando todo para que sirve, la cosa no es copiar y pegar, sino aprender.
Reply
#4

Quote:
Originally Posted by xSeveNx
Посмотреть сообщение
Planeo hacer un DM, en el cual hayan 10 participantes, se mataran entre todos para ser el ъltimo vivo en un mapa no tan grande y todo, el problema es que no estoy seguro de como detectar al ъltimo jugador vivo y que le dй la recompensa, esa es mi duda.

Si alguien pudiera ayudarme se lo agradecerнa mucho.
Quisieras que cuando estйn los 10 se cierre la compentencia para asн mirar cual queda de ultimo?, їy si no hay 10 y solo hay 5 como serнa?, para evitar eso se podrнa hacer lo siguiente:

Usas el comando /entrar mision, entras con setplayerpos y hay un timer de 50 segundos, los que se maten en esos 50 segundos seguirбn spawneando allн, si antes de los 50 segundos ya hay 10 personas, entonces la misiуn arranca dandoles a todos 100 de hp y de armor y asн habrб igualdad para ver cual es el que realmente gane, Si no hay los 10 player el "timer seguirб y al llegar a los 50 segundos la competencia comenzarб asн tengas 2 players como minimo, igualmente se les darб 100 de hp y 100 de blindaje para empezar la competencia.
Una vez que quede solo uno entonces se le darб la recompensa.
Reply
#5

este ygzeb ni supo lo que copiу y pegу jajajaja DIOS primero lee y luego analiza mira el quiere que detecte el ultimo jugador con vida puedes hacer simpre:


pawn Код:
#define MAX_PARTICIPANTES 10
new VariableEvento[MAX_PARTICIPANTES];
new ContEvento;


public OnPlayerDeath(playerid, killerid, reason)
{
 
   if(playerid != INVALID_PLAYER_ID)
   {
      for(new i = 0,  i < MAX_PARTICIPANTES; i++)
      {
            if(VariableEvento[i] == playerid)
               VariableEvento[i] = -1;
       }
   ContEvento ++;
   if( ContEvento == MAX_PARTICIPANTES - 1) VerificarUltimoVivo();
   }
     
     
   return 1;
}

stock VerificarUltimoVivo()
{
   new UltimoVivo;  

   for(new i = 0,  i < MAX_PARTICIPANTES; i++)    
        if( VariableEvento[i] > -1 )
           UltimoVivo = VariableEvento[i];
//   LA ID del ultimo vivo es = UltimoVivo;
   //aqui pon la recompensa!
   return 1;
}
no te quize hacer mas para que sigas tu y aprendas pero es algo asн, OJO ponle restricciones cuando devuelva una ID pregunta si el jugador estб conectado o no! Suerte
Reply
#6

Quote:
Originally Posted by Mr.GeEk
Посмотреть сообщение
este ygzeb ni supo lo que copiу y pegу jajajaja DIOS primero lee y luego analiza mira el quiere que detecte el ultimo jugador con vida puedes hacer simpre:


pawn Код:
#define MAX_PARTICIPANTES 10
new VariableEvento[MAX_PARTICIPANTES];
new ContEvento;


public OnPlayerDeath(playerid, killerid, reason)
{
 
   if(playerid != INVALID_PLAYER_ID)
   {
      for(new i = 0,  i < MAX_PARTICIPANTES; i++)
      {
            if(VariableEvento[i] == playerid)
               VariableEvento[i] = -1;
       }
   ContEvento ++;
   if( ContEvento == MAX_PARTICIPANTES - 1) VerificarUltimoVivo();
   }
     
     
   return 1;
}

stock VerificarUltimoVivo()
{
   new UltimoVivo;  

   for(new i = 0,  i < MAX_PARTICIPANTES; i++)    
        if( VariableEvento[i] > -1 )
           UltimoVivo = VariableEvento[i];
//   LA ID del ultimo vivo es = UltimoVivo;
   //aqui pon la recompensa!
   return 1;
}
no te quize hacer mas para que sigas tu y aprendas pero es algo asн, OJO ponle restricciones cuando devuelva una ID pregunta si el jugador estб conectado o no! Suerte
Йl pide detectar al ъltimo jugador en pie... Y al ъltimo jugador en pie solo le afectarб el timer si es realmente el ъltimo jugador y no hay ningъn otro jugador vivo en ese mundo virtual. Mi cуdigo hace eso justamente, afectar al jugador solo si es el ъnico vivo en dicho mundo

їPor quй tanta agresividad por cada cosa que hago?

Cabe resaltar que mi cуdigo no estб completo, habrнa que finalizar el timer al morir o que el timer solo afecte al jugador si estб en ese mundo (tambiйn que afecte solo si el evento estб activado). Ademбs de ello, es solo un modelo y se puede mejorar mбs.
Reply
#7

Quote:
Originally Posted by Ygzeb
Посмотреть сообщение
Bueno, hay una forma simple:

Colocas a todos los jugadores que van a participar en el DM en un mismo mundo virtual (Por ejemplo: 10), luego a cada uno aplicas un Timer de unos 3 segundos, aсades estas funciones:

pawn Код:
forward Float:GetDistanceBetweenPlayers(P1, P2); // Detectar la distancia entre los jugadores.
forward GetClosestPlayer(P1); // Detectar al jugador mбs cercano.
pawn Код:
public GetClosestPlayer(P1)
{
new X, Float:Dis, Float:Dis2, Player;
Player = -1;
Dis = 99999.99;
for(X = 0; X < MAX_PLAYERS; X++)
{
if(IsPlayerConnected(X))
{
if(X != P1)
{
Dis2 = GetDistanceBetweenPlayers(X, P1);
if(Dis2 < Dis && Dis2 != -1.00)
{
Dis = Dis2;
Player = X;
}
}
}
}
return Player;
}
pawn Код:
public Float:GetDistanceBetweenPlayers(P1, P2)
{
new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
if(!IsPlayerConnected(P1) || !IsPlayerConnected(P2))
{
return -1.00;
}
GetPlayerPos(P1, X1, Y1, Z1);
GetPlayerPos(P2, X2, Y2, Z2);
return floatsqroot(floatpower(floatabs(floatsub(X2, X1)), 2) + floatpower(floatabs(floatsub(Y2, Y1)), 2) + floatpower(floatabs(floatsub(Z2, Z1)), 2));
}
Y en el timer pones algo como:

pawn Код:
new Target = GetClosestPlayer(playerid);
if(IsPlayerConnected(Target))
if((GetDistanceBetweenPlayers(playerid, Target) > 2000 && (GetPlayerVirtualWorld(Target) == GetPlayerVirtualWorld(playerid))) // El valor 2000 es la distancia, lo puedes cambiar a otro si quieres.
{
SendClientMessage(playerid, -1, "Ningъn jugador cerca."); // Acб la funciуn para ganar.
}
Suerte amigo
Tengo el problema de que al parecer no detecta nada, mato al otro y no salta el mensaje.

Si me pudieras hacer el timer te lo agradeceria.

PD: El ъltimo es la variable target o se usa playerid?
Reply
#8

Quote:
Originally Posted by xSeveNx
Посмотреть сообщение
Tengo el problema de que al parecer no detecta nada, mato al otro y no salta el mensaje.

Si me pudieras hacer el timer te lo agradeceria.

PD: El ъltimo es la variable target o se usa playerid?
Si deseas lee lo que te puse al principio, si no igual.
Reply
#9

Quote:
Originally Posted by jotajeda
Посмотреть сообщение
Si deseas lee lo que te puse al principio, si no igual.
Serнa mucho enredo hacer eso ahora mismo, prefiero primero intentar que funcione lo del ъltimo con vida y luego te digo .
Reply
#10

Quote:
Originally Posted by xSeveNx
Посмотреть сообщение
Serнa mucho enredo hacer eso ahora mismo, prefiero primero intentar que funcione lo del ъltimo con vida y luego te digo .
Ya lo tengo hecho pero bueno, como desees.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)