OnPlayerDeath loop
#1

Hi,

I need to detect who is speccing a player when they die..
Example: ID 3, 10 and 1 are speccing ID 6. ID 6 dies and it respawns ID 3, 10 and 1.
The first way i thought of doing this was loops, and i cant think of any other way.
My friend however says i dont need to use loops, so what would be the best way to do this?
Reply
#2

You could just check status of player being spectated in OnPlayerUpdate; Updating interiors, virtual worlds and spectate types of the spectator(s).
Reply
#3

Quote:
Originally Posted by coole210
Посмотреть сообщение
You could just check status of player being spectated in OnPlayerUpdate; Updating interiors, virtual worlds and spectate types of the spectator(s).
It's not what i need :P
Reply
#4

Quote:
Originally Posted by iTorran
Посмотреть сообщение
I need to detect who is speccing a player when they die..
If u want to detect a player on speccing, u may just use the "/spectate" command on admins so it tells "That player is spectating player %s with ID %d"

And if u dont want that spectator dies, u should check is the spectated person alive or not, if not then set spectate off. Maybe there is simple system, but it should work.
Reply
#5

Mhm, no-one really answering my main question but ty :P
Reply
#6

on your spec command do spec[playerid] = giveplayerid;

and do

on specoff have spec[playerid] = -1;
also on playerconnect
then

Код:
for(new i = 0; i != MAX_PLAYERS; i++)
{
    if(spec[i] == playerid)
    {
        //dowhatyouwanthere
    }
}
Reply
#7

I already have the code. I just want to know if there is any other way than loops.
Reply
#8

imagine you got this array
pawn Код:
new ObservedByID[MAX_PLAYERS][MAX_PLAYERS];
each second dimension will carry max 500 players spectating the player in the first dimension:
pawn Код:
ObservedByID[Babul][0]+=1;//raise the amount of players watching me
and then set the playerid of the player watching into cell 1 (cell 0 stores the amount for the max cell-entry)
pawn Код:
ObservedByID[Babul][ObservedByID[Babul][0]]=iTorran;
//thats the same as
ObservedByID[Babul][1]=iTorran;
//...since the script needs to cycle through all [Babul] entries (1 in cell 0), it will access cell [1], thats where YOUR id is stored.
now the little issue when one player stops spectating, so his playerid gets removed from, lets say, cell [3], will result this array being changed:
pawn Код:
ObservedByID[Babul]={5 (playerids watching), 10,11,12,13,14}
playerids 10 to 14 are watching me, and playerid 12 stops now, this causes a gap in the array:
pawn Код:
ObservedByID[Babul]={5 (playerids watching), 10,11,<>,13,14}
since you know the max amount of players speccing, stored in cell 0, (its 4 players now indeed), you can use the missing playerid 12 cell [3] to store the last playerid 14, which changes the array to
pawn Код:
ObservedByID[Babul]={4 (playerids watching), 10,11,14,13,<>}
where the last cell [5] is not accessed anymore.
what YOU will need to care for, are the links to the cell[] from the WATCHING players:
if you are the playerid12 who stops speccing, then how the script should know that your id got stored in cell 3?
pawn Код:
new WatchingID[MAX_PLAYERS];
...since a player can spectate ONE player only, while he can (be? get?) watched by more players...
i hope you know how to do the rest? ^^
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)