Got a solution...?
#1

I have designed a system where if your health is below 5.0, it will make it so you can't move and you're stuck in an animation until you bleed out and die (or when OnPlayerDeath is called). So far, so good! Now, once OnPlayerDeath is called, it should set a PVar and then continue to the next step, where OnPlayerRequestClass is called. Okay, still going fine. Under OnPlayerRequestClass, I am trying to set the player's camera angle but it doesn't seem like it wants to do anything, it goes to the main screen when you first join a SA-MP server...

Here's my code:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    stop InjuredTimer[playerid];
    SetPVarInt(playerid, "JustDied", 1);
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    if(GetPVarInt(playerid, "JustDied") == 1)
    {
        ClearChat(playerid);
        OOCEnabled[playerid] = 0;
        SendClientMessage(playerid, COLOR_LRED, "You have been transported to the hospital and can't remember what happened to you.");
        SetPlayerCameraLookAt(playerid, -2327.4072, 1357.9125, 334.0528);
        defer HospitalTimer(playerid);
        SetPVarInt(playerid, "INHOSP", 1);
        DeletePVar(playerid, "JustDied");
        return 0;
    }
    return 0;
}

timer HospitalTimer[15000](playerid)
{
    SetSpawnInfo(playerid, -1, pStats[playerid][EP_SKIN], fHospSpawnX, fHospSpawnY, fHospSpawnZ, fHospSpawnR, -1, -1, -1, -1, -1, -1);
    SpawnPlayer(playerid);
   
    SendClientMessage(playerid, COLOR_WHITE, "You have been discharged from the hospital.");
    DeletePVar(playerid, "INHOSP");
}
Could anyone perhaps tell me why it doesn't set the player's camera pos/angle?
Reply
#2

Are you sure OnPlayerRequestClass is the most relevant callback to use? I'd use OnPlayerSpawn, so once they respawn, their camera positions are changed as necessary.
Reply
#3

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Are you sure OnPlayerRequestClass is the most relevant callback to use? I'd use OnPlayerSpawn, so once they respawn, their camera positions are changed as necessary.
I'm glad you brought that up. I use OnPlayerRequestClass because if I don't, random objects will appear where the player spawned (i.e. a cigar, or a beer bottle).
Reply
#4

Have you tried using the spectator mode in before OnPlayerSpawn?
Reply
#5

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Have you tried using the spectator mode in before OnPlayerSpawn?
You mean using TogglePlayerSpectating? If so, where would I put that function? With such short time between OnPlayerDeath and OnPlayerSpawn, isn't it pretty pointless (or could I use a timer)?

---

By the way, this is what I'm talking about:



This is the code under OnPlayerSpawn now:

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(GetPVarInt(playerid, "JustDied") == 1)
    {
        ClearChat(playerid);
        OOCEnabled[playerid] = 0;
        SendClientMessage(playerid, COLOR_LRED, "You have been transported to the hospital and can't remember what happened to you.");
        SetPlayerCameraLookAt(playerid, -2327.4072, 1357.9125, 334.0528);
        SetPlayerVirtualWorld(playerid, randomEx(30, 500));
        defer HospitalTimer(playerid);
        SetPVarInt(playerid, "INHOSP", 1);
        DeletePVar(playerid, "JustDied");
    }

    TextDrawShowForPlayer(playerid, TimeTD);
    TextDrawShowForPlayer(playerid, CompleteDate);
    TextDrawShowForPlayer(playerid, ServerVersionTD);
   
    PreloadAnimLib(playerid, "BOMBER");
    PreloadAnimLib(playerid, "RAPPING");
    PreloadAnimLib(playerid, "SHOP");
    PreloadAnimLib(playerid, "BEACH");
    PreloadAnimLib(playerid, "SMOKING");
    PreloadAnimLib(playerid, "ON_LOOKERS");
    PreloadAnimLib(playerid, "DEALER");
    PreloadAnimLib(playerid, "CRACK");
    PreloadAnimLib(playerid, "CARRY");
    PreloadAnimLib(playerid, "COP_AMBIENT");
    PreloadAnimLib(playerid, "PARK");
    PreloadAnimLib(playerid, "INT_HOUSE");
    PreloadAnimLib(playerid, "FOOD");
    PreloadAnimLib(playerid, "GANGS");
    PreloadAnimLib(playerid, "PED");
    PreloadAnimLib(playerid, "FAT");
    return 1;
}
EDIT: BLAH. I forgot to remove "return 0;" one second...

EDIT 2: Okay, the code above is accurate. However, the whole OnPlayerSpawn function isn't being called now...

EDIT 3: Now after removing the code from OnPlayerSpawn, and placing it back under OnPlayerRequestClass, OnPlayerSpawn is still not being called.
Reply
#6

Okay, this is the latest code. OnPlayerSpawn is still not being called (see above), and the camera is not being set to a different position. I really don't know what else to do!

pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(GetPVarInt(playerid, "JustDied") == 1)
    {
        ClearChat(playerid);
        OOCEnabled[playerid] = 0;
        SendClientMessage(playerid, COLOR_LRED, "You have been transported to the hospital and can't remember what happened to you.");
        TogglePlayerSpectating(playerid, true);
        SetPlayerCameraLookAt(playerid, -2327.4072, 1357.9125, 334.0528);
        defer HospitalTimer(playerid);
        SetPVarInt(playerid, "INHOSP", 1);
        DeletePVar(playerid, "JustDied");
        return 0;
    }
    return 0;
}

timer HospitalTimer[15000](playerid)
{
    TogglePlayerSpectating(playerid, false);
    SetSpawnInfo(playerid, -1, pStats[playerid][EP_SKIN], fHospSpawnX, fHospSpawnY, fHospSpawnZ, fHospSpawnR, -1, -1, -1, -1, -1, -1);
    SpawnPlayer(playerid);
    SendClientMessage(playerid, COLOR_WHITE, "You have been discharged from the hospital.");
    DeletePVar(playerid, "INHOSP");
}

public OnPlayerSpawn(playerid)
{
    print("OPS called");
    TextDrawShowForPlayer(playerid, TimeTD);
    TextDrawShowForPlayer(playerid, CompleteDate);
    TextDrawShowForPlayer(playerid, ServerVersionTD);

    PreloadAnimLib(playerid, "BOMBER");
    PreloadAnimLib(playerid, "RAPPING");
    PreloadAnimLib(playerid, "SHOP");
    PreloadAnimLib(playerid, "BEACH");
    PreloadAnimLib(playerid, "SMOKING");
    PreloadAnimLib(playerid, "ON_LOOKERS");
    PreloadAnimLib(playerid, "DEALER");
    PreloadAnimLib(playerid, "CRACK");
    PreloadAnimLib(playerid, "CARRY");
    PreloadAnimLib(playerid, "COP_AMBIENT");
    PreloadAnimLib(playerid, "PARK");
    PreloadAnimLib(playerid, "INT_HOUSE");
    PreloadAnimLib(playerid, "FOOD");
    PreloadAnimLib(playerid, "GANGS");
    PreloadAnimLib(playerid, "PED");
    PreloadAnimLib(playerid, "FAT");
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    TextDrawHideForPlayer(playerid, TimeTD);
    TextDrawHideForPlayer(playerid, CompleteDate);
    TextDrawHideForPlayer(playerid, ServerVersionTD);

    stop InjuredTimer[playerid];
    SetPVarInt(playerid, "JustDied", 1);
    return 1;
}
Reply
#7

Remove the spectation mode.

How are you respawning the player?
Reply
#8

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Remove the spectation mode.
It doesn't help, instead it shows the class selection buttons at the bottom of the screen.

Quote:
Originally Posted by Calgon
Посмотреть сообщение
How are you respawning the player?
pawn Код:
timer HospitalTimer[15000](playerid)
{
    TogglePlayerSpectating(playerid, false);
    SetSpawnInfo(playerid, -1, pStats[playerid][EP_SKIN], fHospSpawnX, fHospSpawnY, fHospSpawnZ, fHospSpawnR, -1, -1, -1, -1, -1, -1);
    SpawnPlayer(playerid);
    SendClientMessage(playerid, COLOR_WHITE, "You have been discharged from the hospital.");
    DeletePVar(playerid, "INHOSP");
}
Using SetSpawnInfo and SpawnPlayer.
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Do you call ForceClassSelection anywhere? There's no reference to it in your code and without it "OnPlayerRequestClass" will never be called after death.
Nope. I do call "TogglePlayerSpectating" upon connection, then I use SetSpawnInfo and SpawnPlayer once they login/register. Isn't that a bug that's been triggering it?
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
I'm not sure if it's a bug or not, it's just strange and I've been wrestling with that strange sequence as well recently. TogglePlayerSpectating does disable the class selection, but I'm not sure of the entire effect.
I think I can deal with it not working for now, but it bothers the hell out of me. I'm sure you'll end up finding a solution sometime.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)