TogglePlayerSpectating + SetPlayerPos -
TheXIII - 22.11.2010
So basicly when I do this under OnPlayerSpawn:
pawn Код:
TogglePlayerSpectating(playerid, false);
SetPlayerPos(playerid, enumarray[pid][X], enumarray[pid][Y], enumarray[pid][Z]);
printf("OnSpawn X: %f, Y: %f, Z: %f",enumarray[pid][X], enumarray[pid][Y], enumarray[pid][Z]);
It calls
OnPlayerSpawn twice, and spawns the player on the coords stated in
AddPlayerClass, instead of
SetPlayerPos. The weird thing is, that the
enumarray[pid][*] values are changed as well, here's the console output.
LoadPlayer is the coordinates loaded from the SQL,
OnSpawn is the code above, which is under
OnPlayerSpawn callback:
Код:
[23:20:07] LoadPlayer X: 1495.380004, Y: -700.083007, Z: 94.750000
[23:20:07] OnSpawn X: 1495.380004, Y: -700.083007, Z: 94.750000
[23:20:07] OnSpawn X: 816.750671, Y: -1361.655273, Z: -0.507799 // Coords from AddPlayerClass, also under OnPlayerDeath, the enumarray[pid][*] is changed to these coords
So.. yeah. The problem is, that it doesn't spawn the coords from SQL, or LoadPlayer. But instead spawns player "twice". I use the TogglePlayerSpectating, to get rid of the "Spawn Buttons" on player connect.
Any workarounds?
Re: TogglePlayerSpectating + SetPlayerPos -
TheXIII - 22.11.2010
First of all, real sorry about the double post. But in case someone cares - here's what I learnt, and how I '
fixed' it:
It seems that it wasn't
TogglePlayerSpectating that reset the players position, but just called
OnPlayerSpawn twice. And OnPlayerSpawn callback did the reset to
AddPlayerClass position. The workaround I found is simply delaying the actual player spawn-setup by 200ms with a timer. Here's the code:
pawn Код:
public OnPlayerSpawn(playerid)
{
if( !PLAYER[Spec] )Spawning(playerid);
else PlayerSpec(playerid, false);
return 1;
}
public PlayerSpec(playerid, toggle)
{
PLAYER[Spec] = toggle;
TogglePlayerSpectating(playerid, toggle);
return 1;
}
Delay:Spawning[200, i](playerid)
{
SetPlayerSkin(playerid, PLAYER[Skin]);
SetPlayerInterior(playerid, PLAYER[Interior]);
SetPlayerVirtualWorld(playerid, PLAYER[VW]);
SetPlayerPos(playerid, PLAYER[X], PLAYER[Y], PLAYER[Z]);
SetPlayerFacingAngle(playerid, PLAYER[Angle]);
SetPlayerHealth(playerid, PLAYER[HP]);
SetPlayerArmour(playerid, PLAYER[Armor]);
SetCameraBehindPlayer(playerid);
}
And just in case someone's wondering:
pawn Код:
#define PLAYER PlayerData[playerid]
Only took me what... 2 hours of messing around with different ideas?
Finally resorted on the one I actually didn't want to use, but at least it works.
Re: TogglePlayerSpectating + SetPlayerPos -
bigcomfycouch - 22.11.2010
TogglePlayerSpectating respawns you, which is why OnPlayerSpawn was called twice.
Re: TogglePlayerSpectating + SetPlayerPos -
TheXIII - 22.11.2010
Quote:
Originally Posted by bigcomfycouch
TogglePlayerSpectating respawns you, which is why OnPlayerSpawn was called twice.
|
Well, yeah.. but, why would it set PLAYER[X/Y/Z] to a different value is what I didn't really get. Only callback that set these values is OnPlayerDeath, and this callback didn't get called.. If it simply would have spawned twice, but with correct coordinates, it wouldn't be a problem at all. In fact I wouldn't even have notice it.
Re: TogglePlayerSpectating + SetPlayerPos -
ReVo_ - 19.08.2012
SetSpawnInfo?