[help] PlayerSpectatePlayer
#1

When somebody dies, and if(killerid!=INVALID_PLAYER_ID), he shall spectate his killer.
if(killerid==INVALID_PLAYER_ID) he shall spectate anyone.
How can I do this?
Reply
#2

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
        if (IsPlayerInAnyVehicle(killerid)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(killerid));
        else PlayerSpectatePlayer(playerid, killerid);
    }
    return 1;
}
Maybe? Untested btw
Reply
#3

Well, thanks, but what's if(killerid==INVALID_PLAYER_ID)?
Reply
#4

It wont spec anyone, what do you want to happen if its invalid id?
Reply
#5

He shall spectate anyone(alive of course ).
Reply
#6

pawn Код:
// at the bottom of your script
stock GetRandomID()
{
  new randn = random(MAX_PLAYERS);
   
  if(IsPlayerConnected(randn)) return randn;
   
  else
  {
     return GetRandomID();
  }
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
        if (IsPlayerInAnyVehicle(killerid)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(killerid));
        else PlayerSpectatePlayer(playerid, killerid);
    }
    else
    {
        if (IsPlayerInAnyVehicle(GetRandomID())) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(GetRandomID()));
        else PlayerSpectatePlayer(playerid, killeridGetRandomID());
    }
    return 1;
}
I think that will work
Reply
#7

that won't check if player is alive. how can one spectate a player that is spectaing something? do another check with a global var like gSpectating[MAX_PLAYERS]
Reply
#8

You can check if player is on foot using GetPlayerState.
Reply
#9

good idea, saves memory for the server. Umm, is there a state for spectation, too?
Reply
#10

Quote:
Originally Posted by Thanatos
that won't check if player is alive. how can one spectate a player that is spectaing something? do another check with a global var like gSpectating[MAX_PLAYERS]
So like this?

pawn Код:
//at the top
new gSpectating[MAX_PLAYERS];

// at the bottom of your script
stock GetRandomID()
{
  new randn = random(MAX_PLAYERS);
   
  if(IsPlayerConnected(randn))
  {
     if(gSpectating[playerid] == 0)
     {
        return randn;
     }
  }
  else
  {
     return GetRandomID();
  }
}

public OnPlayerDeath(playerid, killerid, reason)
{
  gSpectating = 1;
  if(killerid != INVALID_PLAYER_ID)
  {
     if (IsPlayerInAnyVehicle(killerid)) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(killerid));
     else PlayerSpectatePlayer(playerid, killerid);
  }
  else
  {
     if (IsPlayerInAnyVehicle(GetRandomID())) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(GetRandomID()));
     else PlayerSpectatePlayer(playerid, killeridGetRandomID());
  }
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)