SetSpawnInfo overrides OnPlayerSpawn?
#1

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...
Reply
#2

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.
Reply
#3

PHP код:
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.)
PHP код:
if(AccInfo[playerid][JailEvade] == && AccInfo[playerid][Jailed] == false &&
         
AccInfo[playerid][Specing] == false && AccInfo[playerid][GameModeType] == GAMEMODE_FREEROAM)
    {
        if(
AccInfo[playerid][Cop] >= 1)
        {
            
SetSpawnInfo(playerid0AccInfo[playerid][Skin], 1461.8893,2773.8167,10.8203,270.7977000000);
            if(
AccInfo[playerid][CopDuty] == true)
                
SetPlayerSkin(playeridAccInfo[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] > -&& AccInfo[playerid][indm] == 0
        {
            
SetSpawnInfo(playerid0AccInfo[playerid][Skin], HouseInfo[AccInfo[playerid][pHouse]][hX], HouseInfo[AccInfo[playerid][pHouse]][hY],HouseInfo[AccInfo[playerid][pHouse]][hZ],270.7977000000);
            
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(playerid0AccInfo[playerid][Skin],pos[0], pos[1], pos[2], pos[3], 000000);
        }
    } 
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)..
Reply
#4

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?
Reply
#5

Quote:
Originally Posted by LEOTorres
Посмотреть сообщение
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.
Reply
#6

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..)
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)