Actor destroying at wrong player -
JaydenJason - 14.08.2015
So along with all my variables I got this up top;
Code:
new TutorialActor[MAX_PLAYERS][3],
Now, for the tutorial I got this which creates the actor inside a binco with a special virtual world (player's virtual world is set to this as well)
Code:
//onplayerspawn i
if(!pData[playerid][pTutorialFinished]) // and some more code
TutorialActor[playerid][0] = CreateActor(211, 208.8536,-98.6901,1005.2578,179.5417); // here the actor is made
SetActorVirtualWorld(TutorialActor[playerid][0], 6969+playerid);
Once the player exits the binco from the tutorial, the actor gets destroyed(no need for an actor anymore because he isnt being seen)
Code:
DestroyActor(TutorialActor[playerid][0]);
And under OnPlayerConnect I have this
Code:
DestroyActor(TutorialActor[playerid][0]);
Along with a whole bunch of variables that are reset.
The weird thing, those are the only 2 times an actor gets destroyed (onplayerconnect and when the actor isnt visible anymore)
Yet, (tested with 3 people at same time)
Here's how it went
1st player(me) joins, gets halfway in tutorial with no bugs/mistakes/errors whatsoever.
2 minutes after: 2nd player(friend of mine) connects to have a peek at the tutorial I made, but once he connects somehow my actor is being destroyed?
1 minute after 2nd player join: 3rd player joins and actor for 2nd player disappears.
Is there anything I did wrong?
Re: Actor destroying at wrong player -
Jefff - 14.08.2015
Your variable new TutorialActor[MAX_PLAYERS][3]; is 0 on start and actors start from 0 so:
if first player connect TutorialActor[playerid][0] = CreateActor(); Actor ID 0 (all ok)
then second player is connect (his variable is 0 TutorialActor[playerid][0]) and actor ID 0 is destroyed DestroyActor(TutorialActor[playerid][0]); in OPC for Player 1 ( now actor is owned by player 2 )
if third player connect actor ID is still 0 and variable TutorialActor[playerid][0] is 0 so again you destroy friend id 2 actor
Solution:
In OnGameModeInit set array to INVALID_ACTOR_ID;
pawn Code:
new tempActorID[sizeof(TutorialActor[])] = {INVALID_ACTOR_ID, ...};
for(new i = 0; i < sizeof(TutorialActor); i++)
TutorialActor[i] = tempActorID;
and for destroy actors
pawn Code:
if(TutorialActor[playerid][0] != INVALID_ACTOR_ID)
{
DestroyActor(TutorialActor[playerid][0]);
TutorialActor[playerid][0] = INVALID_ACTOR_ID;
}
Re: Actor destroying at wrong player -
JaydenJason - 15.08.2015
That did the job, appreciated and thanks!