SA-MP Forums Archive
random spectate player ( must be in vehicle ) how? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: random spectate player ( must be in vehicle ) how? (/showthread.php?tid=96333)



random spectate player ( must be in vehicle ) how? - hipy - 07.09.2009

Hi i need some help

I need a spec system that can be excecuted on any moment( on playerstate change on playerdeath etc )

then you will spec a person in a vehicle( you spec vehicle but a person is driving it ) and if that player dies or what ever, the spec user must be able to auto/press a key to switch to an other random person

i already have this

Код:
new playa = GetRandomPlayer();
KillTimer(timer5[playerid]);
new vehicleid = GetPlayerVehicleID(playa);
	

TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid,vehicleid);

stock GetRandomPlayer()
{
  new yplayer[MAX_SLOTS];
  for (new y = 0; y != MAX_PLAYERS; y ++) {
    if (IsPlayerConnected(y)) {
      yplayer[0] ++;
      yplayer[yplayer[0]] = y;
    }
  }
  return yplayer[random(yplayer[0])+1];
}
Only this isnt fail proof, sometimes you dont spec( see the bridge to sf ) and sometimes you see your self hanging in the air.
Can sombody help me with this?

thanks in advance!



Re: random spectate player ( must be in vehicle ) how? - hipy - 07.09.2009

anybody?


Re: random spectate player ( must be in vehicle ) how? - Zezombia - 07.09.2009

pawn Код:
//top
new spec[MAX_PLAYERS];

//where they fist start specing players
new playa = GetRandomPlayer();

spec[playa] = playerid; // < added

KillTimer(timer5[playerid]);
new vehicleid = GetPlayerVehicleID(playa);

TogglePlayerSpectating(playerid, 1);
PlayerSpectateVehicle(playerid,vehicleid);

//on player death
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(spec[i] = playerid)
    {
        new playa = GetRandomPlayer();

        spec[playa] = playerid;

        KillTimer(timer5[playerid]);
        new vehicleid = GetPlayerVehicleID(playa);

        TogglePlayerSpectating(playerid, 1);
        PlayerSpectateVehicle(playerid,vehicleid);
    }
}
Untested.