SA-MP Forums Archive
Spectating a random team player - 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: Spectating a random team player (/showthread.php?tid=204742)



Spectating a random team player - jameskmonger - 30.12.2010

I've got this:
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(hasDied[playerid]) {
        new rand = random(playersAliveCount);
        if(gTeam[rand] == gTeam[playerid]) {
            TogglePlayerSpectating(playerid, 1);
            PlayerSpectatePlayer(playerid, rand);
        } else {

        }
        return 0;
    }
}
But I want to make it so that if the random player's team is not the same as the local player's team, it will generate a new random player id and check again.


Re: Spectating a random team player - MadeMan - 30.12.2010

pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(hasDied[playerid])
    {
        new rand = random(playersAliveCount);
        while(gTeam[rand] != gTeam[playerid])
        {
            rand = random(playersAliveCount);
        }
        TogglePlayerSpectating(playerid, 1);
        PlayerSpectatePlayer(playerid, rand);
        return 0;
    }
}



Re: Spectating a random team player - jameskmonger - 30.12.2010

I've got this:
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerTeamFromClass(playerid, classid);
    if(hasDied[playerid])
    {
        new rand = random(playersAliveCount);
        while(gTeam[rand] != gTeam[playerid])
        {
            rand = random(playersAliveCount);
        }
        TogglePlayerSpectating(playerid, 1);
        PlayerSpectatePlayer(playerid, rand);
        return 0;
    } else {
        switch(classid) {
            case 0..2: GameTextForPlayer(playerid, "~g~Grove", 3000, 0);
            case 3..5: GameTextForPlayer(playerid, "~p~Ballas", 3000, 0);
        }
        SetPlayerPos(playerid, 2194.7080, -1156.8996, 1029.7968);
        SetPlayerInterior(playerid, 15);
        SetPlayerFacingAngle(playerid, 95.5932);
        SetPlayerCameraPos(playerid, 2191.2080, -1152.8996, 1031.2968);
        SetPlayerCameraLookAt(playerid, 2194.7080, -1156.8996, 1029.7968);
        SetPlayerVirtualWorld(playerid, playerid + 1);
        return 1;
    }
}
public OnPlayerDeath(playerid, killerid, reason)
{
    hasDied[playerid] = true;
    return 1;
}
But I still respawn after dying!


Re: Spectating a random team player - MadeMan - 30.12.2010

Use OnPlayerSpawn?


Re: Spectating a random team player - jameskmonger - 30.12.2010

I try that, and now I only see blueberry beach


Re: Spectating a random team player - MadeMan - 30.12.2010

It might be yourself you're trying to spec.

Change the code a bit
pawn Код:
while(rand == playerid || gTeam[rand] != gTeam[playerid])



Re: Spectating a random team player - jameskmonger - 30.12.2010

It now spectates them, but it shows them as falling in the air, while staying still (almost like they're airbreaking) - should i set my interior to theirs?


Re: Spectating a random team player - jameskmonger - 30.12.2010

I tried doing this:
pawn Код:
SetPlayerInterior(playerid, GetPlayerInterior(rand));
But now it doesn't even spectate them.


Re: Spectating a random team player - jameskmonger - 31.12.2010

I really need some help with this...