SA-MP Forums Archive
How to teleport a player in his death position? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to teleport a player in his death position? (/showthread.php?tid=519427)



How to teleport a player in his death position? - KurtAngle - 14.06.2014

Hi! I need a small help.
I need an example of script that when a player dies, at the spawn he got a message that says "Would you like come back in your death position? [Yes] [No]
If he click Yes, he go where he died, if he click No, he stay where it was just spawned.
Thanks early who can help me!


Re: How to teleport a player in his death position? - GeekSiMo - 14.06.2014

pawn Код:
new SFloatX[MAX_PLAYERS];
new SFloatY[MAX_PLAYERS];
new SFloatZ[MAX_PLAYERS];
OnPlayerDeath
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
    SFloatX[playerid] = X
    SFloatY[playerid] = Y
    SFloatZ[playerid] = Z
}
OnPlayerSpawn
{
    SetPlayerPos(playerid, SFloatZ[playerid], SFloatY[playerid], SFloatZ[playerid]);
}
Try This !!


Re: How to teleport a player in his death position? - KurtAngle - 14.06.2014

Yes, but I need that when a player Spawn, he appear a DialogBox that ask if he want go back in death position or not
P.S pawno return me warning and errors: tag mismatch in:
SFloatX[playerid] = X
SFloatY[playerid] = Y
SFloatZ[playerid] = Z


Re: How to teleport a player in his death position? - Rittik - 14.06.2014

Here you go.
pawn Код:
new FloatX[MAX_PLAYERS];
new FloatY[MAX_PLAYERS];
new FloatZ[MAX_PLAYERS];
OnPlayerDeath
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    FloatX[playerid] = x;
    FloatY[playerid] = y;
    FloatZ[playerid] = z;
    return 1;
}
OnPlayerSpawn
{
    SetPlayerPos(playerid, FloatX[playerid], FloatY[playerid], FloatZ[playerid]);
    FloatX[playerid]=0.0; FloatY[playerid]=0.0; FloatZ[playerid]=0.0;
    return 1;
}



Re: How to teleport a player in his death position? - GeekSiMo - 14.06.2014

You Must Add A Dialog !!


Re: How to teleport a player in his death position? - Lynn - 14.06.2014

Quote:
Originally Posted by GeekSiMo
Посмотреть сообщение
pawn Код:
new SFloatX[MAX_PLAYERS];
new SFloatY[MAX_PLAYERS];
new SFloatZ[MAX_PLAYERS];
OnPlayerDeath
{
    new Float:X, Float:Y, Float:Z; // Not needed.
    GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
    SFloatX[playerid] = X // Not Needed
    SFloatY[playerid] = Y // Not Needed
    SFloatZ[playerid] = Z // Not Needed
}
OnPlayerSpawn
{
    SetPlayerPos(playerid, SFloatZ[playerid], SFloatY[playerid], SFloatZ[playerid]);
}
Try This !!
pawn Код:
/* Top of Script */
#define DIALOG_SPAWN (1000)

enum Dead_Info
{
    Float:pX,
    Float:pY,
    Float:pZ,
    VW,
    Int,
    Float:F_Angle
};
new dInfo[MAX_PLAYERS][Dead_Info];

public OnPlayerDeath(playerid, killerid, reason)
{
    GetPlayerPos(playerid, dInfo[playerid][pX], dInfo[playerid][pY], dInfo[playerid][pZ]);
    GetPlayerInterior(playerid, dInfo[playerid][Int]);
    GetPlayerVirtualWorld(playerid, dInfo[playerid][VW]);
    SetPVarInt(playerid, #Death, 1);
    return 1;
}
public OnPlayerSpawn(playerid)
{
    if(GetPVarInt(playerid, #Death) == 1)
    {
        ShowPlayerDialog(playerid, DIALOG_SPAWN, DIALOG_TYPE_MSGBOX, "Death Message", "Would you like to spawn where you died?", "Yes", "No");
        DeletePVar(playerid, #Death);
    }
    return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_SPAWN) {
        if(response) {
            SetPlayerPos(playerid, dInfo[playerid][pX], dInfo[playerid][pY], dInfo[playerid][pZ]);
            SetPlayerInterior(playerid, dInfo[playerid][Int]);
            SetPlayerVirtualWorld(playerid, dInfo[playerid][VW]);
            SetPlayerFacingAngle(playerid, dInfo[playerid][F_Angle]);
        }  
    }
    return 1;
}



Re: How to teleport a player in his death position? - Rittik - 14.06.2014

At the top of you script define this.
pawn Код:
#define POS 200
pawn Код:
new FloatX[MAX_PLAYERS];
new FloatY[MAX_PLAYERS];
new FloatZ[MAX_PLAYERS];
OnPlayerDeath
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    FloatX[playerid] = x;
    FloatY[playerid] = y;
    FloatZ[playerid] = z;
    return 1;
}
OnPlayerSpawn
{
    ShowPlayerDialog(playerid,POS,DIALOG_STYLE_MSGBOX,"Previous Position","Do you want to get back to the position where you died ?","Yes","No");
    return 1;
}
Under OnDialogResponse

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == POS)
    {
        if(response) // If they clicked 'Yes' or pressed enter
        {
            SetPlayerPos(playerid, FloatX[playerid], FloatY[playerid], FloatZ[playerid]);
    FloatX[playerid]=0.0; FloatY[playerid]=0.0; FloatZ[playerid]=0.0;
        }
       
        return 1;
    }
 
    return 0; // You Must return 0 here..
}



Re: How to teleport a player in his death position? - SyntaxQ - 14.06.2014

pawn Код:
#define DIALOG_SELECT_SPAWN 333

enum posInfo
{
    Float:pX,
    Float:pY,
    Float:pZ,
    Float:pA
};
new pos_info[MAX_PLAYERS][posInfo];

new IsSpawnAfterDeath[MAX_PLAYERS];

public OnPlayerDeath(playerid, killerid, reason)
{
    GetPlayerPos(playerid, pos_info[playerid][pX], pos_info[playerid][pY], pos_info[playerid][pZ]);
    GetPlayerFacingAngle(playerid, pos_info[playerid][pA]);
    IsSpawnAfterDeath[playerid] = 1;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if (IsSpawnAfterDeath[playerid] == 1)
    {
        ShowPlayerDialog(playerid, DIALOG_SELECT_SPAWN, DIALOG_STYLE_MSGBOX, "Select your spawn", "Would you like to go back where you died?", "Yes", "No");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if (dialogid == DIALOG_SELECT_SPAWN)
    {
        if (response)
        {
            SetPlayerPos(playerid, pos_info[playerid][pX], pos_info[playerid][pY], pos_info[playerid][pZ]);
            SetPlayerFacingAngle(playerid, pos_info[playerid][pA]);
        }
        else
        {
            SendClientMessage(playerid, -1, "You have selected not to go back where you died.");
            return 1;
        }
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    IsSpawnAfterDeath[playerid] = 0;
    return 1;
}



Re: How to teleport a player in his death position? - KurtAngle - 14.06.2014

Thanks @SyntaxQ it works!!! And thanks to all for the help!