Returning to where you died
#1

Hi,

I was thinking how can i make it so that if you die you return to that spot?
I currently have this but it doesn't work any suggestions?
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    new Float:qu[3];
    GetPlayerPos(playerid, qu[0], qu[1], qu[2]);
    SetPlayerPos(playerid, qu[0] ,qu[1] ,qu[2]);
    return 1;
}
Thanks,
Yoran
Reply
#2

I have not tested this, but it should work.

Add this on top of the script, but below the includes

pawn Код:
new Float:DeathPosX[MAX_PLAYERS];
new Float:DeathPosY[MAX_PLAYERS];
new Float:DeathPosZ[MAX_PLAYERS];
new Died[MAX_PLAYERS];
Add this in the callback OnPlayerConnect

pawn Код:
Died[playerid] = 0;
Add this in the callback OnPlayerDeath

pawn Код:
GetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
Died[playerid] = 1;
And finally, add this in the callback OnPlayerSpawn

pawn Код:
if(Died[playerid] == 1)
{
    SetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
    Died[playerid] = 0;
}
Reply
#3

Quote:
Originally Posted by Vlad64
Посмотреть сообщение
I have not tested this, but it should work.

Add this on top of the script, but below the includes

pawn Код:
new Float:DeathPosX[MAX_PLAYERS];
new Float:DeathPosY[MAX_PLAYERS];
new Float:DeathPosZ[MAX_PLAYERS];
new Died[MAX_PLAYERS];
Add this in the callback OnPlayerConnect

pawn Код:
Died[playerid] = 0;
Fast response! Thanks! Ill test out the code and ill reply if it worked!

Add this in the callback OnPlayerDeath

pawn Код:
GetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
Died[playerid] = 1;
And finally, add this in the callback OnPlayerSpawn

pawn Код:
if(Died[playerid] == 1)
{
    SetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
    Died[playerid] = 0;
}
Thanks! Ill test out the code and see if it worked then ill reply here!
Reply
#4

Just tested it out but if i kill someone he does not spawn at the positon he died.
Any suggestions?

Thanks,
Yoran
Reply
#5

Quote:
Originally Posted by yoran765
Посмотреть сообщение
Just tested it out but if i kill someone he does not spawn at the positon he died.
Any suggestions?

Thanks,
Yoran
Are you lying? I tested it out using my laptop and one of my computers... Works perfectly... Make sure that you put everything in the correct place. Also make sure that you put the new's below includes and above #if defined FILTERSCRIPT. Otherwise it won't work.
Reply
#6

Alright this is my whole OnPlayerDeath
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    GetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
    Died[playerid] = 1;
    if(PlayerInfo[killerid][jail] || PlayerInfo[playerid][jail]) return 1;
    if(gPlayerUsingLoopingAnim[playerid])
    {
        gPlayerUsingLoopingAnim[playerid] = 0;
        TextDrawHideForPlayer(playerid,txtAnimHelper);
    }
    File::SaveAccount(playerid);
    if(reason == 38 && GetAdminLevel(killerid) && !IsPlayerInAnyVehicle(killerid) && !PlayerTemp[killerid][isevent])
    {
        new Float:pP[4];
        GetPlayerPos(playerid,pP[0], pP[1], pP[2]);
        SetTimerEx("SetPlayerPosExEx", 2000, false, "dfffddd", playerid, pP[0], pP[1], pP[2], GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), INVALID_VEHICLE_ID);
        return 1;
    }
    if(killerid != INVALID_PLAYER_ID && killerid != 54 && killerid != 255)
    {
        if(PlayerTemp[playerid][onpaint])
        {
            PlayerLoop(i)
            {
                if(!PlayerTemp[i][onpaint]) continue;
                SendClientMSG(i, COLOR_YELLOW, " [PB]: %s has killed %s with a %s (Distance: %dm)", RPName(killerid), RPName(playerid), aWeaponNames[reason], GetDistanceBetweenPlayers(playerid, killerid));
                OnPlayerKillSpree(killerid);
            }
            return 1;
        }
        if(PlayerTemp[killerid][isevent])
        {
            PlayerLoop(i)
            {
                if(!PlayerTemp[i][isevent]) continue;
                SendClientMSG(i, COLOR_YELLOW, "..: [EVENT]: %s has killed %s with a %s (Distance: %dm):..", RPName(killerid), RPName(playerid), aWeaponNames[reason], GetDistanceBetweenPlayers(playerid, killerid));
                OnPlayerKillSpree(killerid);
            }
            PlayerTemp[playerid][isevent] = 0;
            return 1;
        }
        if(killerid != INVALID_PLAYER_ID && PlayerInfo[killerid][playerteam] != HITMAN) SendDeathMessage(killerid,playerid,reason);
        {
            CheckWar();
            new winpoints;
            {
                switch(PlayerInfo[playerid][ranklvl])
                {
                    case 0: winpoints = 5;
                    case 1: winpoints = 2;
                    case 2: winpoints = 1;
                    default: winpoints = 1;
                }
            }
            if(PlayerInfo[killerid][playerteam] == dini_Int(warfile,"faction1") && PlayerInfo[playerid][playerteam] == dini_Int(warfile,"faction2"))
            {
                dini_IntSet(warfile, "faction1points", dini_Int(warfile,"faction1points") + winpoints);
            }
            else if(PlayerInfo[killerid][playerteam] == dini_Int(warfile,"faction2") && PlayerInfo[playerid][playerteam] == dini_Int(warfile,"faction1"))
            {
                dini_IntSet(warfile, "faction2points", dini_Int(warfile,"faction2points") + winpoints);
            }
        }
        //SetPlayerWantedLevel(playerid, 0);
        TextDrawHideForPlayer(playerid, PlayerTemp[playerid][Status]);
        TextDrawHideForPlayer(playerid, TextDraw__News);
        TextDrawHideForPlayer(playerid, IMtxt);
        new
            string[ MAX_STRING ], wname[ 40 ], ragione[ 40 ];
        GetWeaponName(reason, wname, sizeof(wname));
        format( string, sizeof(string), "5..: [DEATH] %s[%d] has been killed by %s[%d] (%s) :..",PlayerName(playerid),playerid, PlayerName(killerid), killerid,wname);
        iEcho( string );
        format( string, sizeof(string), "[KILL] %s has killed %s with a %s", PlayerName(killerid), PlayerName(playerid), wname);
        AppendTo(deathlog, string);
        GetWeaponName(reason,ragione,40);

        if(IsPlayerDriver(killerid) && PlayerInfo[killerid][playerteam]!=EMS && PlayerInfo[killerid][playerteam]!=SASF && PlayerInfo[killerid][playerteam]!=FBI && PlayerInfo[killerid][playerteam]!=COPS && PlayerInfo[killerid][power]==0)
        {
            PlayerTemp[killerid][imprisoned] = 1;
            Jail(killerid,600,777,"Drive-by");
            format(iStr,sizeof(iStr),"{FFFFFF}[ {FF0000}ADMIN{FFFFFF} ] {FF6347}* SERVER has jailed %s for 10 minutes. Reason: Drive-by *",RPName(killerid));
            SendMessageToAll(COLOR_RED,iStr);
        }
        if(killerid != INVALID_PLAYER_ID && IsPlayerInPaintball(killerid))
        {
            if(PlayerTemp[playerid][pbteam] == 1) PBTeams[PlayerTemp[playerid][onpaint]][redscore]++;
            else PBTeams[PlayerTemp[playerid][onpaint]][bluescore]++;
            UpdatePBScore(PlayerTemp[playerid][onpaint], PBTeams[PlayerTemp[playerid][onpaint]][redscore], PBTeams[PlayerTemp[playerid][onpaint]][bluescore]);
            return 1;
        }
        if(killerid != INVALID_PLAYER_ID) PlayerInfo[killerid][kills]++;
        PlayerInfo[playerid][deaths]++;
        if(!strlen(ragione)) ragione="Fists";
        new deathmsg[MAX_STRING]; format(deathmsg,sizeof(deathmsg),"Info: You have paid $%d for the medical bills, have a nice day!",dini_Int(globalstats, "medicals"));
        SendClientMessage(playerid,COLOR_ORANGE,deathmsg);
        if(killerid != INVALID_PLAYER_ID && PlayerInfo[killerid][playerteam]==HITMAN && PlayerInfo[playerid][head]>0)
        {
            if(strcmp(ragione,"Knife",true)==0)
            {
                new total;
                total=PlayerInfo[playerid][head]+((PlayerInfo[playerid][head]*15)/100);
                dini_IntSet(globalstats,"HitmanBank",dini_Int(globalstats,"HitmanBank")+total/2);
                GivePlayerMoneyEx(killerid, total/2);
                format(string,sizeof(string),"[HEAD] You earned $%d from %s head, plus 15-percent of his head because of knifekill.",PlayerInfo[playerid][head]/2,PlayerName(playerid));
                SendClientMessage(killerid,COLOR_YELLOW, string);
                PlayerInfo[playerid][head]=0;
            }
            else
            {
                GivePlayerMoneyEx(killerid, PlayerInfo[playerid][head]/2);
                dini_IntSet(globalstats,"HitmanBank",dini_Int(globalstats,"HitmanBank")+PlayerInfo[playerid][head]/2);
                format(string,sizeof(string),"[HEAD] You earned $%d from %s head.",PlayerInfo[playerid][head]/2,PlayerName(playerid));
                SendClientMessage(killerid,COLOR_YELLOW, string);
                PlayerInfo[playerid][head]=0;
            }
        }
        if(PlayerInfo[playerid][playerlvl] >= 3)
        {
            if(killerid != INVALID_PLAYER_ID && PlayerInfo[killerid][playerteam]==COPS || PlayerInfo[killerid][playerteam]==FBI || PlayerInfo[killerid][playerteam]==SASF)
            { //cop contro ti
                GivePlayerMoneyEx(playerid,-10000);
                SendClientMessage(playerid, COLOR_HELPEROOC, "=======================================================================================");
                SendClientMessage(playerid, COLOR_HELPEROOC, " ");
                SendClientMessage(playerid,COLOR_WHITE,"EVADING: -10.000$ for resistance to the federal law.");
                SendClientMessage(playerid,COLOR_WHITE, "NOTE: If you think, that the law has abused their powers, take a screen shot and post it on the forums.");
                SendClientMessage(playerid, COLOR_HELPEROOC, " ");
                SendClientMessage(playerid, COLOR_HELPEROOC, "=======================================================================================");

                dini_IntSet(globalstats,"GovernmentBank",dini_Int(globalstats,"GovernmentBank")+5000);

                new stringa[ 128 ];
                format(stringa, sizeof(stringa), "Severely wounded by PD/SASF %s %s for resisting arrest", PlayerInfo[killerid][rankname], PlayerName(killerid));
//              PoliceDB(playerid, stringa);
            }
        }
    }
    else
    {
        if(PlayerInfo[playerid][power])
        {
            PlayerLoop(i)
            {
                SendDeathMessage(killerid, playerid, reason);
            }
            return 1;
        }
        new string[ 128 ];
        format(string,sizeof(string), ".:: Suicide: %s has suicided ::.", RPName(playerid));
        if(GetPVarInt(playerid, "SkinSelect") == 0) SendClientMessageToAll(COLOR_RED, string);
        format( string, sizeof(string), "5..: [DEATH] %s[%d] has suicided :..",PlayerName(playerid),playerid);
        iEcho( string );
        format( string, sizeof(string), "[KILL] %s has killed himself", PlayerName(playerid));
        AppendTo(deathlog, string);
    }
    return 1;
}
Not sure if this helps but im not getting it to work
But basiclly in my script if you die you spawn inside a HQ or a House. Not sure if thats conflicting anything
Reply
#7

Hmm... I don't know what to say. This is how the lines should be placed inside the gamemode.

pawn Код:
#include <a_samp>

new Float:DeathPosX[MAX_PLAYERS]; //This
new Float:DeathPosY[MAX_PLAYERS]; //This
new Float:DeathPosZ[MAX_PLAYERS]; //This
new Died[MAX_PLAYERS]; //This

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif

public OnPlayerConnect(playerid)
{
    Died[playerid] = 0; //This
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(Died[playerid] == 1) //This
    { //This
        SetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]); //This
        Died[playerid] = 0; //This
    } //This
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    GetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]); //This
    Died[playerid] = 1; //This
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)