SA-MP Forums Archive
Switching to the next 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: Switching to the next player (/showthread.php?tid=278176)



Switching to the next player - Scenario - 21.08.2011

Hello there.

I am currently attempting to form an advanced spectating system and I would like to make it so a player could press a button and then they would spectate the next connected player. How can I do this properly? I want to avoid unconnected players obviously...


Re: Switching to the next player - Machida - 21.08.2011

To avoid unconnected users you can use IsPlayerConnected(playerid) .
And about the Keys i think you should use GetPlayerKeys..https://sampwiki.blast.hk/wiki/GetPlayerKeys
And when the key is pressed, You should spectate the current player id +1, ofc if its connected.

Like (not real code) :

if GetPlayerKeys then

if IsPlayerConnected(playerid) then
// Spectated playerid +1

end if

end if

Im a newbie, but i think its something like that.
I code C++ but i started to pawn now xD


Re: Switching to the next player - Scenario - 21.08.2011

Quote:
Originally Posted by Machida
View Post
To avoid unconnected users you can use IsPlayerConnected(playerid) .
And about the Keys i think you should use GetPlayerKeys..https://sampwiki.blast.hk/wiki/GetPlayerKeys
Editing..
I understand how to do those things. Although, my problem is what do I do if the ID used in "IsPlayerConnected" isn't connected? Should I just do "check_id++"?


Re: Switching to the next player - =WoR=G4M3Ov3r - 21.08.2011

Are you using zcmd, strcmp, dini .. ? Which one are you using ?


Re: Switching to the next player - Machida - 21.08.2011

Quote:
Originally Posted by RealCop228
View Post
I understand how to do those things. Although, my problem is what do I do if the ID used in "IsPlayerConnected" isn't connected? Should I just do "check_id++"?
Yes, if its not connnected add 1, then check again, etc..


Re: Switching to the next player - Scenario - 21.08.2011

Quote:
Originally Posted by BATAD
View Post
Are you using zcmd, strcmp, dini .. ? Which one are you using ?
ZCMD


Re: Switching to the next player - Lorenc_ - 21.08.2011

pawn Code:
SpectatePlayer(playerid, whoid + 1);
Like that? Though you need to check if the player ID is connected if he isn't return 0 or just add another + 1 to check again.


Re: Switching to the next player - Deskoft - 21.08.2011

Basically, what Lorenc_ said.

pawn Code:
if(IsPlayerConnected(whoid + 1))
{
        SpectatePlayer(playerid, whoid + 1);
}else{
        SendClientMessage(playerid, 0xFF0000, "Player is not connected");
}
Is that what you need? That's basically using Lorenc_'s example, and checking if he is connected.

Edit: Also, if he is not connected, go to the next id, if it's not connected, switch to the next id... and so on.


Re: Switching to the next player - Scenario - 21.08.2011

Kind of. Although, why are you using "whoid + 1" instead of "whoid?" Why are you adding the one to the ID?

I am trying to make it so if a player isn't connected, it moves to the next ID. It should keep doing that until it finds a connected ID. Any thoughts?


Re: Switching to the next player - Lorenc_ - 21.08.2011

Ok, let say you're spectating ID 1 and you want to move to ID 2 then 3

Whoid = ID 1

pawn Code:
if((keys & KEY_FIRE))
{
    if(IsPlayerConnected(whoid + 1))
    {
            SpectatePlayer(playerid, whoid + 1);
    }else{
            SendClientMessage(playerid, 0xFF0000, "Player is not connected");
    }
}
Come on, you should understand my post and Deskoft's..


Re: Switching to the next player - Scenario - 21.08.2011

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Ok, let say you're spectating ID 1 and you want to move to ID 2 then 3

Whoid = ID 1

pawn Код:
if((keys & KEY_FIRE))
{
    if(IsPlayerConnected(whoid + 1))
    {
            SpectatePlayer(playerid, whoid + 1);
    }else{
            SendClientMessage(playerid, 0xFF0000, "Player is not connected");
    }
}
Come on, you should understand my post and Deskoft's..
Oh Jesus... I am honestly being stupid right now... I guess this is from those beers I had a couple hours ago! I don't normally drink, but I needed a beer after doing yard-work all day yesterday (it's 1:34 AM here now).

I understand this absolutely perfect now, I can't believe I didn't think this through very much! Like I said though... alcoholic beverages...

Thanks guys!


Re: Switching to the next player - Deskoft - 21.08.2011

Oh! Now I understand what you want to do!

pawn Код:
new found;
    new existingid;
    new newid;
    do
    {
        existingid++;
        if(IsPlayerConnected(existingid))
        {
            newid == existingid;
            found == 1;
        }
    }while( found == 1);
So basically, when that loop happens, newid will be the id to spectate. I didn't test it, but I guess that should work. right?


Re: Switching to the next player - Scenario - 21.08.2011

I basically need a function which will choose the next available player ID.

For example:

I am spectating player ID 43 and I want to spectate the next player, I push LMB and it should advance to the next player (i.e. ID 52). I don't want to need to push LMB 9 times in order to get to ID 52- it should automatically choose the next player and return the ID.

Does this make sense?


Re: Switching to the next player - Bakr - 21.08.2011

There is an EXACT example of what you're trying to accomplish in the Barron gamemode that comes with the SA:MP Server Package.


Re: Switching to the next player - Scenario - 21.08.2011

Quote:
Originally Posted by Bakr
Посмотреть сообщение
There is an EXACT example of what you're trying to accomplish in the Barron gamemode that comes with the SA:MP Server Package.
Honestly, I don't see a system in there that does this...


Re: Switching to the next player - Bakr - 21.08.2011

pawn Код:
new gPlayerObserving[MAX_PLAYERS]; // player observing which active player

ObserverSwitchToNextVehicle(playerid)
{
    new x=0;
    while(x!=MAX_PLAYERS) { // MAX_PLAYERS iterations
        gPlayerObserving[playerid]++;
        if(gPlayerObserving[playerid] == MAX_PLAYERS) {
            // we need to cycle back to the start
            gPlayerObserving[playerid] = 0;
        }
        // see if the target player has a vehicle,
        // if so assign this player to observe it
        if(gPlayerVehicles[gPlayerObserving[playerid]] != 0) {
            PlayerSpectateVehicle(playerid,gPlayerVehicles[gPlayerObserving[playerid]]);
            return;
        }
        x++;
    }
    // didn't find any vehicles to observe. we'll have to default to last
    PlayerSpectateVehicle(playerid,gPlayerVehicles[gPlayerObserving[playerid]]);
}

//OnPlayerKeyStateChange
if(gPlayerObserving[playerid] >= 0 && IsKeyJustDown(KEY_FIRE,newkeys,oldkeys)) {
       // They're requesting to change observer to another vehicle.
       ObserverSwitchToNextVehicle(playerid);
    }

//OnPlayerDeath
new x=0;
    while(x!=MAX_PLAYERS) {
        if(x != playerid && gPlayerObserving[x] == playerid) {
            ObserverSwitchToNextVehicle(x);
        }
        x++;
    }
You should be able to create your own system, very easily, based on the system in that script.