SA-MP Forums Archive
Spectating problem - 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)
+--- Thread: Spectating problem (/showthread.php?tid=317135)



Spectating problem - Min - 10.02.2012

Hello,I made a random spectating system which those players who've been killed can spectate any players who aren't killed yet.
But there's one problem, when I've been killed by Player 1, I've to click multiple times(KEY_FIRE) to spectate other players who were still alive. Well I know it's because of this random() thingy but how can I make a system like I just have to click only once, and then I'll be able to spectate another player who're still alive, and so on..

This's my script:


pawn Код:
if (PRESSED(KEY_FIRE))
    {
    if(PlayerInfo[playerid][Latezor] == 1 && PlayerInfo[playerid][Killedzor] == 1)
    {
        for(new i; i<GetMaxPlayers(); i++)
        {
            if(IsPlayerConnected(i)) PCount++;
        }
        new Spectatethisguy = random(PCount);
        if(PlayerInfo[Spectatethisguy][Latezor] == 0 && PlayerInfo[Spectatethisguy][Killedzor] == 0)
        {
        PlayerSpectatePlayer(playerid, Spectatethisguy);
        }
    }
    }
Anyone have any idea on how to do that?
Big thanks.


Re: Spectating problem - MP2 - 10.02.2012

Search for a proper random player function.


Re: Spectating problem - Min - 10.02.2012

Ermm, is this a good one? :

pawn Код:
stock RandomPlayer()
{
    new randomplayer = random(MAX_PLAYERS);
    while(!IsPlayerConnected(randomplayer)) randomplayer = random(MAX_PLAYERS);
    return randomplayer;
}



Re: Spectating problem - MP2 - 10.02.2012

DEFINATELY NOT!
Don't even get me started on why that's a terrible idea!

http://pastebin.com/jvhMdwhJ