spectate change when exit vehicle..
#1

This is the code
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(Spectate[i] == vehicleid)
            {
                PlayerSpectatePlayer(i,playerid);
            }
        }
    }
If I spec example id 2, when example id 5 exit a vehicle I will start to spec id 5.. How will I fix this?
Reply
#2

Use OnPlayerStateChange instead. Store the player's ID only, not the vehicle's ID. And when they turn the spectate off, don't forget to set Spectate[id_here] to INVALID_PLAYER_ID.
pawn Код:
public OnPlayerStateChange( playerid, newstate, oldstate )
{
    if( newstate == PLAYER_STATE_ONFOOT )
    {
        for( new i = 0; i < MAX_PLAYERS; i++ )
        {
            if( !IsPlayerConnected( i ) ) continue;
            if( Spectate[ i ] == playerid ) PlayerSpectatePlayer( i, playerid );
        }
    }
    return 1;
}
Reply
#3

Thanks. I will test it.
Reply
#4

It still changes to the player that exits a vehicle
Reply
#5

When you spec a player, assign their ID to:
pawn Код:
// store the player's ID you want to spectate to id
Spectate[ playerid ] = id;
When it loops through the players, it checks:
pawn Код:
if( Spectate[ i ] == playerid ) PlayerSpectatePlayer( i, playerid );
If the playerid (the player who exited the vehicle is the same id with the valud of Spectate[ i ], then.. spectate that playerid.

The code should do that. I use it like that and it works very good.
Reply
#6

This is my /spec
pawn Код:
if (strcmp(cmd, "/spec", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if (PlayerInfo[playerid][pAdmin] >= 1 || IsPlayerAdmin(playerid))
            {
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp))
                {
                    SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /spec [playerid/PartOfName]");
                    return 1;
                }
                giveplayerid = ReturnUser(tmp);
                new Float:Health, Float:Armour;
                new World = GetPlayerVirtualWorld(playerid);
                new PlInterior = GetPlayerInterior(playerid);
                GetPlayerHealth(playerid, Health);
                GetPlayerArmour(playerid, Armour);
                if(IsPlayerConnected(giveplayerid))
                {
                    if(giveplayerid != INVALID_PLAYER_ID)
                    {
                        if(Spectate[playerid] == 255)
                        {
                            GetPlayerPos(playerid, TeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]);
                            SaveGuns(playerid);
                            PlayerInfo[playerid][pHealth] = Health;
                            PlayerInfo[playerid][pArmour] = Armour;
                        }
                        Interior[playerid] = PlInterior;
                        VirWorld[playerid] = World;
                        TogglePlayerSpectating(playerid, 1);
                        if(IsPlayerInAnyVehicle(giveplayerid))
                        {
                            PlayerSpectateVehicle(playerid, GetPlayerVehicleID(giveplayerid));
                        }
                        else
                        {
                            PlayerSpectatePlayer(playerid, giveplayerid);
                        }
                        Spectate[playerid] = giveplayerid; // I store it here
                        SafeSetPlayerInterior(playerid, GetPlayerInterior(giveplayerid));
                        SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(giveplayerid));
                        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                        format(string, sizeof(string), "[ADMIN]: %s Is Now Spectating %s (%d).", sendername, giveplayer, giveplayerid);
                        SendAdminMessage(COLOR_LIGHTRED,string);
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, "* You are now spectating this player. To Unspec him spec another id or type /endspec <playerid>");

                        new y, m, d;
                        new h,mi,s;
                        getdate(y,m,d);
                        gettime(h,mi,s);
                        format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s is speccing %s's",d,m,y,h,mi,s,sendername,giveplayer);
                        AdminLog(string);
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GRAD1, "   No Such Player");
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_GRAD1, "   You are not an admin");
            }
        }

        return 1;
    }
Reply
#7

bump
Reply
#8

bump
Reply
#9

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i)) continue;
            if(Spectate[playerid] == i) PlayerSpectatePlayer(playerid, i);
        }
    }
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerConnected(i)) continue;
            if(Spectate[playerid] == i) PlayerSpectateVehicle(playerid, GetPlayerVehicleID(i));
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)