Returning to Position after Death [0.3 Bug] ?
#1

Hi, i started testing my Server with the new RC-8. I used nearly the same Script for it as i used in 0.2, where everything just worked fine.
I justed changed the Lock System of the Cars as described in the sticked topic.
I found no problems with the version, except the Returning to your old Position after you crashed before. The Code , as i already said, worked in 0.2, its realy simple, like:
Код:
// -- OnPlayerDisconnect
	if(reason == 0)
	{
		GetPlayerPos(...);
		AnyVariable = true;
		// Save Variables to Database (works fine, see below)
	}
	
	// -- Login
	
	// Loading Variables from Database (works fine, tested it, loads the right Coord and the Variable)
	
	// -- OnPlayerSpawn
	
	if(AnyVariable)
	{
	  SendClientMessage(...); // The Message Shows
	  SetPlayerPos(...);
	  return 1;
	}
	// Normal Spawn here
So it loads and saves but doesnt work properly. I just spawn at the Position of my SetSpawnInfo which i use in /login to spawn the Player.
So my /login looks like this
Код:
SetSpawnInfo(playerid, pInfo[playerid][pTeam], pInfo[playerid][pSkin1], buInfo[gSpawn][buEntrancex], buInfo[gSpawn][buEntrancey], buInfo[gSpawn][buEntrancez], 1.0, -1, -1, -1, -1, -1, -1);
TogglePlayerSpectating(playerid,0);
SpawnPlayer(playerid);
I just always Spawn at the SetSpawnInfoPos, although i set the Pos in OnPlayerSpawn. But OnPlayerSpawn gets called, because i see the "Crash" Message. I already tried changing the SetPlayerSpawn part to
Код:
if(pInfo[playerid][pCrashed]) SetSpawnInfo(playerid, pInfo[playerid][pTeam], pInfo[playerid][pSkin1], pInfo[playerid][p_X], pInfo[playerid][p_Y], pInfo[playerid][p_Z], 1.0, -1, -1, -1, -1, -1, -1);
	else SetSpawnInfo(playerid, pInfo[playerid][pTeam], pInfo[playerid][pSkin1], buInfo[gSpawn][buEntrancex], buInfo[gSpawn][buEntrancey], buInfo[gSpawn][buEntrancez], 1.0, -1, -1, -1, -1, -1, -1);
Doesnt work neither. So i doint know whats wrong, because it worked fine with 0.2. Was SetSpawnInfo changed or something other related to this? Or does anybody else has this Problem?

Reply
#2

Ummmm, no. OnPlayerDisconnect is after the player disconnects, so... you can't get the players position.
Reply
#3

well, i have had this bit of code on my test gm and whenever i quit it says "Player left at x:0.0 y:0.0 z:0.0" btw, its from the wiki
Reply
#4

Maybe your code is wrong then. You can do a 'IsPlayerConnected' check and it'll pass.

I know that if you use SetPlayerPos under OnPlayerSpawn, it won't work properly. What you have to do is under OnPlayerStateChane, if GetPlayerState==PLAYER_STATE_SPAWNED. If your SetPlayerPos is placed there, it will execute without failure.
Reply
#5

Quote:
Originally Posted by яυαяαι
well, i have had this bit of code on my test gm and whenever i quit it says "Player left at x:0.0 y:0.0 z:0.0" btw, its from the wiki
Well then you did something wrong, i have the same system and it just works.
Reply
#6

Thanks for the answears, i now tested every part you mentioned, to make sure he loads and saves the right coordinates. My Test Code looked like:
Код:
// Login of Player

// Loading Stuff
SetSpawnInfo(...); // See above
SpawnPlayer(playerid);

// OnPlayerDisconnect
if(reason == 0)
{
	pInfo[playerid][pCrashed] = true;
	GetPlayerPos(...)
	pInfo[playerid][p_X] = x;
	// ...
	// Save Stuff
}

// OnPlayerSpawn
if(pInfo[playerid][pCrashed])
{
	// Some other Stuff
  if(pInfo[playerid][pCrashed] == 1)
	{
	  new
	    string[60];
		format(string, sizeof(string), "RIGHT U SHOULD REED THIS MESSAGE: Returning to Pos: %f %f %f", pInfo[playerid][p_X], pInfo[playerid][p_Y], pInfo[playerid][p_Z]);
		SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	  SetPlayerVirtualWorld(playerid, 0);
	  SetPlayerInterior(playerid, 0);
	  SetPlayerPos(playerid, pInfo[playerid][p_X], pInfo[playerid][p_Y], pInfo[playerid][p_Z]);
	  pInfo[playerid][pCrashed] = 0; // Reset
	  return 1;
	}
	SendClientMessage(playerid, COLOR_LIGHTBLUE, "WRONG, YOU CANT READ THIS MESSAGE IF YOU JUST CRASHED");
	// Normal Spawn (where i spawn everytime) goes here
}

// PLAYER_STATE_SPAWNED under OnPlayerStateChange

SendClientMessage(playerid, COLOR_LIGHTBLUE, "PLAYER_STATE_SPAWNED WAS CALLED");
So now i joined the Server, teleportet me to a Pos (noticed the Coords) and stopped the process of GTA while ingame (-> Crash). After that i joined again to see which of these messages appear ingame, it looked like
Quote:

Connected to ...
PLAYER_STATE_SPAWNED WAS CALLED
RIGHT U SHOULD REED THIS MESSAGE: Returning to Pos: [THE RIGHT KOORDS HERE]
WRONG, YOU CANT READ THIS MESSAGE IF YOU JUST CRASHED

So the problem should be clear but im not sure how the fix it. OnPlayerSpawn gets called TWO times. The fist time i spawn at the right Coords, but the Second time i spawn at the normal Coors, because the Crashvariable gets reset after the first one.

But this problem only happens when i spawn for the first time right after Login. When i die ingame, theres just one message. So i think it has to do with my Login Stuff, where i used (see above) SetSpawnInfo and SpawnPlayer

Anybody else has this problem? Hope you can help me out of it, in 0.2 it worked with exactly this Code. Well i think it would work if i put my crash Code under PLAYER_STATE_SPAWED, but this wont be a solution for the Problem, just another fix...

If you need more info or Code about this, just ask
Reply
#7

Hm sorry for this Double Post, but the "Edit" Function doesnt work for me. Theres just green "Loading" at the top of the screen, but nothing happens.
I just want to ask if you have to user SpawnPlayer and SetSpawn Info to spawn the player after he typed "/login". Im asking, because i looked around in some Login/Register System FS and they dont user SpawnPlayer. For some strange reason the Player only spawns - after he typed "/login" - if i use both SetSpawnInfo and SpawnPlayer.Otherwise im just frozen in my Login Screen. So is there any other was or what am i doing wrong?
I think my Bug is related to SetSpawnInfo and SpawnPlaye, but im not sure
Reply
#8

Again sry, but i couldn't edit again
I just want to tell you, that i solved my problem. As i said it WAS related to my SpawnPlayer and my SetSpawnInfo. So i tried to get rid of these in my /login Command. I searched for quite a while and after some long time i finally found a related Post of someone else.
At the end i changed my "return 0;" to a "return 1;" in my OnPlayerRequestClass and removed the SpawnPlayer and SetSpawnInfo part and it worked. Now its only called once as it should and im returning to my Position again.

I have one more questeion concerning the OnPlayerRequestClass part. I would like to set the camera pos OnPlayerRequestClass. In 0.2x i just used.
Код:
// OnPlayerRequestClass
SetCameraPos(...);
SetCameraLookAt(...);
BUT in 0.3 i needed to insert TogglePlayerSpectating(playerid, 1); in OnPlayerRequestClass to remove the "Spawn GUI" (with the two arrows and the "Spawn" Button). For some reason now my SetCameraPos... isnt working anymore.
So anybody knows how to change the camera in OnPlayerRequestClass?

And i would like to report another issue with 0.3: If i user TogglePlayerSpectating(playerid, 1); in OnPlayerConnect and trying to show a "Login" Dialog Box in OnPlayerRequestClass it wont show. Is this a know Bug? Or is this intentional?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)