OnPlayerSpawn not being called with SpawnPlayer
#1

When a player connects to the server they enter their password and they should spawn at their last saved position etc..
However when "SpawnPlayer(playerid)" is called it does not call "OnPlayerSpawn(playerid)" which is where the info to spawn them is located. Instead it will spawn me far north at the world boundaires and causes me to float up

Loading the player after password has been entered:
pawn Код:
public FLoginUser(playerid)
{
    new TempUsrPass = cache_get_row_int(0, 2);
    if(mysql_errno() != 0)
    {
        print("error here");
    }
    new name[MAX_PLAYER_NAME], ip[45];
    GetPlayerName(playerid,name,MAX_PLAYER_NAME);
    GetPlayerIp(playerid, ip, sizeof(ip));

    if(GetPVarInt(playerid, "PPassword") != TempUsrPass)
    {
        if(LogginAttempts[playerid] == 2)
        {
            LogginAttempts[playerid] = 0;
            KickEx(playerid);
        }
        else
        {
            LogginAttempts[playerid]++;
            new str[1024], string[256];
            format(string, sizeof(string), "{FF4000}Incorrect Password   Attempts: %d\n", LogginAttempts[playerid]);
            strcat(str, string);
            format(string, sizeof(string), "You will be kicked after 3 attempts.\n");
            strcat(str, string);
            format(string, sizeof(string), "Please type your password below to login.\n");
            strcat(str, string);
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login:", str, "Login", "Exit");
        }
    }
    if(GetPVarInt(playerid, "PPassword") == TempUsrPass )
    {
        // Player Variables
        PlayerInfo[playerid][PID] = cache_get_row_int(0, 0);
        PlayerInfo[playerid][Name] = name;
        PlayerInfo[playerid][pCash] = cache_get_row_int(0, 3);
        PlayerInfo[playerid][Score] = cache_get_row_int(0, 4);
        PlayerInfo[playerid][PosX] = cache_get_row_float(0, 5);
        PlayerInfo[playerid][PosY] = cache_get_row_float(0, 6);
        PlayerInfo[playerid][PosZ] = cache_get_row_float(0, 7);
        PlayerInfo[playerid][pAdmin] = cache_get_row_int(0, 8);
        PlayerInfo[playerid][pSkin] = cache_get_row_int(0, 9);
        PlayerInfo[playerid][pAge] = cache_get_row_int(0, 10);
        PlayerInfo[playerid][pSex] = cache_get_row_int(0, 11);
        PlayerInfo[playerid][Interior] = cache_get_row_int(0, 12);
        PlayerInfo[playerid][VirtualWorld] = cache_get_row_int(0, 13);
        PlayerInfo[playerid][CellNum] = cache_get_row_int(0, 14);
        PlayerInfo[playerid][Job] = cache_get_row_int(0, 15);
        PlayerInfo[playerid][Accent] = cache_get_row_int(0, 16);
        PlayerInfo[playerid][Faction] = cache_get_row_int(0 ,17);
        PlayerInfo[playerid][Hospital] = cache_get_row_int(0, 18);
        PlayerInfo[playerid][Insurance] = cache_get_row_int(0, 19);
        cache_get_field_content(0, "Title", PlayerInfo[playerid][Title], MySQL, 24);
        PlayerInfo[playerid][TitleEnabled] = cache_get_row_int(0, 21);
        PlayerInfo[playerid][Developer] = cache_get_row_int(0, 22);
        PlayerInfo[playerid][VIP] = cache_get_row_int(0, 23);
        PlayerInfo[playerid][Credits] = cache_get_row_int(0, 24);
        PlayerInfo[playerid][Banned] = cache_get_row_int(0, 25);
        cache_get_field_content(0, "BannedBy", PlayerInfo[playerid][BannedBy], MySQL, 24);
        cache_get_field_content(0, "Reason", PlayerInfo[playerid][Reason], MySQL, 32);
        PlayerInfo[playerid][Ip] = ip;

        // Player Variables
        SetPlayerCash(playerid, PlayerInfo[playerid][pCash]);
        SendClientMessage(playerid, COLOR_WHITE, "[Server] Account Data loaded.");
        LoggingIn[playerid] = 1;
        SetPlayerInterior(playerid, PlayerInfo[playerid][Interior]);
        SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][VirtualWorld]);
        DeletePVar(playerid, "PPassword");
        print("About to spawn player........");
        SpawnPlayer(playerid);

    }
    return 1;
}
As seen in the above code, it does print "About to spawn player........"

However the following code is never called:

pawn Код:
public OnPlayerSpawn(playerid)
{
    print("Called: OnPlayerSpawn");
    print("Called: OnPlayerSpawn - SetPlayerWorldBounds");
    SetPlayerWorldBounds(playerid, 20000.0000, -20000.0000, 20000.0000, -20000.0000);
    if(Newbie[playerid] == 1)
    {
        ShowPlayerDialog(playerid, DIALOG_AGE, DIALOG_STYLE_INPUT,"Age","Please put your age to process.","Ok","");
    }
    print("Called: OnPlayerSpawn - CheckRPName");
    CheckRPName(playerid);
    new Float:tX, Float:tY, Float:tZ, Float:Angle, Float:x, Float:y, Float:z;
    tX = 1580.7139;
    tY = -1325.6499;
    tZ = 16.7844+3.0;
    Angle = 312.5654;
    print("Called: OnPlayerSpawn - GetPlayerPos BB Check");
    GetPlayerPos(playerid, x, y, z);
    if(x == 0.0 && y == 0.0 || x == 0.0 || y == 0.0)
    {
        SetPlayerPos(playerid, tX, tY, tZ);
        SetPlayerFacingAngle(playerid, Angle);
    }
    print("Called: OnPlayerSpawn - SetPlayerColor");
    SetPlayerColor(playerid, PLAYER_COLOR);
    print("Called: OnPlayerSpawn - TextDrawShowForPlayer");
    TextDrawShowForPlayer(playerid,txtTimeDisp);
    print("Called: OnPlayerSpawn - gettime");
    gettime(hour, minute);
    print("Called: OnPlayerSpawn - SetPlayerTime");
    SetPlayerTime(playerid,hour,minute);
    print("Called: OnPlayerSpawn - OnPhone");
    OnPhone[playerid] = INVALID_PLAYER_ID;
    print("Called: OnPlayerSpawn - Checking Cell Num");
    if(PlayerInfo[playerid][CellNum] != 0 && PlayerInfo[playerid][CellNum] > 999)
    {
        CheckCellNum(playerid);
    }
    print("Called: OnPlayerSpawn - Injure Check");
    if(GetPVarInt(playerid, "Injured") == 1)
    {
        SetPlayerPos(playerid, OldX[playerid], OldY[playerid], OldZ[playerid]);
        SetPlayerFacingAngle(playerid, OldA[playerid]);
        ApplyAnimation(playerid, "PED", "KO_skid_front",4.1,0,1,1,1,0);
    }
    print("Called: OnPlayerSpawn - Set player to old pos");
    if(LoggingIn[playerid] == 1)
    {
        SetPlayerPos(playerid, PlayerInfo[playerid][PosX], PlayerInfo[playerid][PosY], PlayerInfo[playerid][PosZ]);
        LoggingIn[playerid] = 0;
    }
    print("Called: OnPlayerSpawn - Hospital Check");
    if(PlayerInfo[playerid][Hospital] == 1)
    {
        SendToHospital(playerid);
    }
    print("Called: OnPlayerSpawn - SetPlayerSkin");
    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
    return 1;
}
Not even the first print in this function is actually printed... Not sure what's going on here. No errors/warning are printed & I'm using crashdetect.
any help is much appreciated.
Reply
#2

I think this should work:
pawn Код:
SpawnPlayer(playerid);
OnPlayerSpawn(playerid);
Reply
#3

That's how I created my work around. However it will randomly call OnPlayerSpawn twice... This is really annoying, I don't understand why it does not work as printed on the box so to speak..
Reply
#4

What if you use
pawn Код:
OnPlayerSpawn(playerid);
and remove SpawnPlayer completely?
Reply
#5

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
What if you use
pawn Код:
OnPlayerSpawn(playerid);
and remove SpawnPlayer completely?
When a person logs in it bugs out. As in the Spawn and arrow buttons remain on screen (When logging in)
Reply
#6

Try skipping class selection rather than trying to spawn the player, that has always worked for me
Reply
#7

There is no class selection, It's a roleplay script.
Reply
#8

When ever I had this problem, it was because I wasn't setting the players spawn info. That needs to be set before OnPlayerSpawn can be used. You can then re-position the player to where he needs to be spawned according to his saved variables.

So if you haven't, add this under OnPlayerConnect AND class selection:
pawn Код:
SetSpawnInfo( playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0 );
Other wise idk, sorry.
Reply
#9

Tried that to no avail!
Reply
#10

Add another print after you call SpawnPlayer and see if that gets called.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)