Save a player's position and take them there on spawn
#1

Hi. I'm working on some modifications to -Sneaky-'s duel script. After the winner is decided, it should teleport both players back to where they originally were when they accepted/challenged the duel. It does teleport the winner back, however the loser just respawns at one of the random spawn locations set in the gamemode.

Here is where I get the player's data:

pawn Код:
SetupPlayerForDuel(playerid)
{
    playerWorld[playerid] = GetPlayerVirtualWorld(playerid);
    playerInt[playerid] = GetPlayerInterior(playerid);
   
    GetPlayerArmour(playerid, playerArmour[playerid]);
    GetPlayerHealth(playerid, playerHP[playerid]);
   
    GetPlayerFacingAngle(playerid, playerAngle[playerid]);
    GetPlayerPos(playerid, playerX[playerid], playerY[playerid], playerZ[playerid]);
   
    playerColour[playerid] = GetPlayerColor(playerid);
   
    for(new w; w < 13; w++) GetPlayerWeaponData(playerid, w, guns[w][playerid], ammo[w][playerid]);
   
    ResetPlayerWeapons(playerid);
   
    SetPlayerVirtualWorld(playerid, 107);
   
    SetPlayerHealth(playerid, 100);
    SetPlayerArmour(playerid, 100);
   
    GivePlayerWeapon(playerid, 26, 500);
    GivePlayerWeapon(playerid, 32, 500);
   
    wasInDuel[playerid] = 1;
   
    SetPlayerColor(playerid, COLOR_RED);
   
    return 1;
}
And here is where I send them back to where they were:

pawn Код:
StopDuelForPlayer(playerid)
{
    SetPlayerVirtualWorld(playerid, playerWorld[playerid]);
    SetPlayerInterior(playerid, playerInt[playerid]);

    SetPlayerArmour(playerid, playerArmour[playerid]);
    SetPlayerHealth(playerid, playerHP[playerid]);

    SetPlayerFacingAngle(playerid, playerAngle[playerid]);
    SetPlayerPos(playerid, playerX[playerid], playerY[playerid], playerZ[playerid]);
   
    ResetPlayerWeapons(playerid);

    for(new w = 0; w <= 12; w++) GivePlayerWeapon(playerid, weapons[w][0][playerid], weapons[w][1][playerid]);

    wasInDuel[playerid] = 0;

    SetPlayerColor(playerid, playerColour[playerid]);
    return 1;
}
Now OnPlayerSpawn I try to take the player that lost/died back to where they were before they participated in the duel:

pawn Код:
if(wasInDuel[playerid] == 1) StopDuelForPlayer(playerid);
else SetPlayerRandomSpawn(playerid);
It seems to ignore the first part and just continue to the randomspawn function. I've debugged to check that wasInDuel[playerid] does in fact = 1 for that player, and it does so I'm not sure what the issue is.

In OnPlayerDeath I have it so the player that won goes back to where they were and it works:

pawn Код:
if(g_IsPlayerDueling[playerid] == 1 && g_IsPlayerDueling[killerid] == 1)
    {
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        GetPlayerName(killerid, zName, MAX_PLAYER_NAME);
        {
            format(sString, sizeof(sString),"DUEL UPDATE: %s has won the duel against %s!", zName, pName);
            SendClientMessageToAll(COLOR_ORANGE, sString);

            g_GotInvitedToDuel[playerid] = 0; g_HasInvitedToDuel[playerid] = 0; g_IsPlayerDueling[playerid]  = 0;
            g_GotInvitedToDuel[killerid] = 0; g_HasInvitedToDuel[killerid] = 0; g_IsPlayerDueling[killerid]  = 0;
            g_DuelInProgress = 0;
            StopDuelForPlayer(killerid);
            return 1;
       }
    }
Any help would be greatly appreciated. Thanks
Reply
#2

thing is that you store coordinates in variables pX pY and pZ but get them from playerX, playerY, playerZ
Reply
#3

Sorry, I copied my code wrong as I changed which variables I used. Let me edit my post. They're all using playerX, Y, Z in my actual script.
Reply
#4

Bump. Anybody got any ideas?
Reply
#5

Bump. Anybody?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)