PDA

View Full Version : SetSpawnInfo overrides OnPlayerSpawn?


denNorske
08/04/2017, 12:30 PM
Hello!

I've had quite a few issues understanding fully how to work with "SetSpawnInfo" as I've mostly been using SetPlayerPos and SetPlayerTeam before. I implemented a new way of teleporting on my server, and along in the process I decided to adapt into SetSpawnInfo.

However, I've issues understanding a few things, I would like to clear up:

I expect OnPlayerSpawn to be called...
1. when the player has died
2. When the player get spawned with SpawnPlayer(..)
3. newstate == PLAYER_STATE_SPAWNED under "OnPlayerStateChange" should be called
4. When TogglePlayerSpectating(playerid, 0); is used.

However only the fourth case prints out any of the messages in OnPlayerSpawn..

And OnPlayerRequestSpawn is only called from within Class selection?


If I Disable all occurences of SetSpawnInfo in my script - All the cases above works flawlessy.
Why is this so, and how can I "fix" this? It complicates things alot more if i can't see if the player spawns at any time.

I realise this might be a localized issue as it's not recreateable in my other gamemode.
I'll look through and see if i can find something fishy, but it's weird that everything works when i disable all SetSpawnInfo's...

LEOTorres
08/04/2017, 01:53 PM
Can you send code which shows your OnPlayerSpawn callback and places where you use SetSpawnInfo.

Also, in terms of OnPlayerRequestSpawn, this callback is only played upon attempting to spawn within the class selection menu; it's not called prior to OnPlayerSpawn.

denNorske
08/04/2017, 02:10 PM
public OnPlayerSpawn(playerid)
{
SendClientMessage(playerid, -1, "[Debug] OnPlayerSpawn Called");
return 1;
}
^That is all i have for now in order to debug.


There are too much code to provide the entire callbacks (on for example OnPlayerRequestSpawn) but what I do is basically to check what Gamemode the player is in (Gamemodetype 0-5, which could be race, DM, TDM, etc..)

A snippet taken from OnPlayerRequestSpawn, which in most cases is the one called when someone joins. (I had the idea of perhaps onplayerrequestspawn was called instead of OnPlayerSpawn so that's why I do those checks in this example.)

if(AccInfo[playerid][JailEvade] == 0 && AccInfo[playerid][Jailed] == false &&
AccInfo[playerid][Specing] == false && AccInfo[playerid][GameModeType] == GAMEMODE_FREEROAM)
{
if(AccInfo[playerid][Cop] >= 1)
{
SetSpawnInfo(playerid, 0, AccInfo[playerid][Skin], 1461.8893,2773.8167,10.8203,270.7977, 0, 0, 0, 0, 0, 0);
if(AccInfo[playerid][CopDuty] == true)
SetPlayerSkin(playerid, AccInfo[playerid][CopSkin]);
SendLanguageMessage(playerid,green,">> Spawned at the Police HQ",">> Spawned at the Police HQ",">> Spawned at the Police HQ");
}
else if(AccInfo[playerid][pHouse] > -1 && AccInfo[playerid][indm] == 0)
{
SetSpawnInfo(playerid, 0, AccInfo[playerid][Skin], HouseInfo[AccInfo[playerid][pHouse]][hX], HouseInfo[AccInfo[playerid][pHouse]][hY],HouseInfo[AccInfo[playerid][pHouse]][hZ],270.7977, 0, 0, 0, 0, 0, 0);
SendLanguageMessage(playerid,green,">> Spawned at your house",">> Has aparecido en tu casa",">> Voc? nasceu na sua propriedade");
}
else
{
new Float:pos[4];
GetRandomSpawn(pos[0], pos[1], pos[2], pos[3]);
SetSpawnInfo(playerid, 0, AccInfo[playerid][Skin],pos[0], pos[1], pos[2], pos[3], 0, 0, 0, 0, 0, 0);
}
}

The thing is, SetSpawnInfo works. nicely. The player spawns where he's supposed to.


And when he joins a DM, a TDM, a race or so, I use SetSpawnInfo, and Spawn the player where he's supposed to go, while other times I use SetPlayerPos.


But still, SetSpawnInfo in itself shouldn't prevent OnPlayerSpawn to be called, as far as I have understood?
Note: When i comment away all instances of SetSpawnInfo, the OnPlayerSpawn gets called when someone dies/respawns. Otherwise not.


EDIT: It works in my other gamemode (old server)..
http://image.prntscr.com/image/7b8961778e4f472bbd68dff508a1f79c.png

LEOTorres
08/04/2017, 04:02 PM
I just tested it myself and SetSpawnInfo should not override OnPlayerSpawn, in fact, it's the opposite, anything you have within the OnPlayerSpawn callback should override values previously assigned within the SetSpawnInfo function. Is there a possibility that you may be using an external include that is causing conflict with OnPlayerSpawn initiating in combination with SetSpawnInfo?

Also, have you tried calling OnPlayerSpawn (playerid); manually? What happens?

denNorske
08/04/2017, 04:23 PM
I just tested it myself and SetSpawnInfo should not override OnPlayerSpawn, in fact, it's the opposite, anything you have within the OnPlayerSpawn callback should override values previously assigned within the SetSpawnInfo function. Is there a possibility that you may be using an external include that is causing conflict with OnPlayerSpawn initiating in combination with SetSpawnInfo?

Also, have you tried calling OnPlayerSpawn (playerid); manually? What happens?
Well, as I stated above i could not recreate the issue in another gamemode either.

OnPlayerSpawn calls correctly if used directly, however "SpawnPlayer(playerid)" isn't.

denNorske
08/04/2017, 08:34 PM
Update

The script works flawlessy when I increased with
#pragma dynamic

What is the reason of this and is it bad? (I am thinking about way too many recursions..)

LEOTorres
08/04/2017, 11:18 PM
Yes, either due to recursions or unnecessary cell sizes.

I personally would not recommend the usage of pragma dynamic, instead you should go through your script and conduct thorough optimization.