SetPlayerPos problem
#1

Hi, how do I set a player's X and Y positon only, not the Z one?
Because when I use SetPlayerPos(x, y, z) while skydiving, the player dies instantly,
even when I use the same z position that he is at.
Reply
#2

So you mean you want to set the players position to the lowest Z co-ordinate i.e. the ground? Well there is a plugin as well as an include for that the plugin name is MapAndreas the include name is also somewhat same try searching the forums for it. Its on you what you wanna choose plugin or include. I will prefer include since it consumes less memory and is of less KB's while the plugin is 22 MB and it consumes some near 70 MB of your memory.

Wish you luck!
Reply
#3

No, I mean when I use SetPlayerPos while falling/skydiving, the player dies like he hit the ground, but is still in mid-air.
Reply
#4

pawn Код:
new Float:pX, Float:pY, Float:pZ;
    GetPlayerPos(playerid, pX, pY, pZ);
    SetPlayerPos(playerid, /*X Position*/, /*Y Position*/, pZ);
Reply
#5

You need to remove the parachute before you SetPlayerPos.

Example:
pawn Код:
ResetPlayerWeapons(playerid);
SetPlayerPos(playerid, X, Y, Z);
And you can use:
pawn Код:
SetPlayerPosFindZ(playerid, X, Y, Z);
So the player will automatically teleport to the ground below the X and Y cord specified.
Reply
#6

Hi, wiki said that Players will die if teleported while diving with a parachute. (WEAPON ID PAGE)

I made a quick test code to teleport player with killing them using timers.

Edit it according to your needs
  • First I gave players parachute
    pawn Код:
    if (strcmp("/para", cmdtext, true, 10) == 0)
        {
            GivePlayerWeapon(playerid,46,1);
            SetPlayerPos(playerid,0,0,100000);
            return 1;
        }
  • Now to set their position to something different and to get weapons they had , I declared a Global variable Weapons
    pawn Код:
    new weapons[13][2];
    if (strcmp("/pos", cmdtext, true, 10) == 0)
    {
        for (new i = 0; i < 13; i++)
        {
              GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
        }
    }
  • Now, take all their weapons (main thing is to take parachute]
    pawn Код:
    ResetPlayerWeapons(playerid);
  • As they dont have parachute now, you can teleport them easily using SetPlayerPos.
    pawn Код:
    //Or maybe X,Y,Z;
    SetPlayerPos(playerid,1000,-500,1000);
  • Set a timer of 1 sec, which will give player their weapons (parachute included.)
    GIVING THEM WEAPON WITHOUT TIMER WILL LEAD TO DEATH
    pawn Код:
    SetTimerEx("ChangePos",500,false,"i",playerid);
    ==> TIMER FUNCTION
    pawn Код:
    forward ChangePos(playerid);
    public ChangePos(playerid)
    {
        for (new i = 0; i < 13; i++)
        {
            GivePlayerWeapon(playerid,weapons[i][0], weapons[i][1]);
        }
        return 1;
    }
Full Code :
pawn Код:
new weapons[13][2];
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/para", cmdtext, true, 10) == 0)
    {
        GivePlayerWeapon(playerid,46,1);
        SetPlayerPos(playerid,0,0,100000);
        return 1;
    }

    else if (strcmp("/pos", cmdtext, true, 10) == 0)
    {
        for (new i = 0; i < 13; i++)
        {
            GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
        }
        ResetPlayerWeapons(playerid);
        SetPlayerPos(playerid,1000,-500,1000);
        SetTimerEx("ChangePos",500,false,"i",playerid);
        return 1;
    }
    return 0;
}

forward ChangePos(playerid);
public ChangePos(playerid)
{
    for (new i = 0; i < 13; i++)
    {
        GivePlayerWeapon(playerid,weapons[i][0], weapons[i][1]);
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by Samp-Wiki
Players will die if teleported while diving with a parachute.
Parachutes are given when bailing out of aircraft. (be aware of this for Anti-Cheats)
To solve that, just use this function, it remove the player's weapon. i've made a little example, but you could make some calc's to check if he's mid air, i'am too lazy to do.

pawn Код:
stock RemovePlayerWeapon(p,weaponid)
{
    new l_arma[12],l_muni[12],l_arma2,l_muni2;
    for(new Tslots = 0; Tslots != 12;Tslots++ )
    {
        GetPlayerWeaponData(p,Tslots,l_arma2,l_muni2);
        if(l_arma2!= weaponid)GetPlayerWeaponData(p,Tslots,l_arma[Tslots],l_muni[Tslots]);
    }
    ResetPlayerWeapons(p);
    for(new Tslots = 0;Tslots != 12;Tslots++)GivePlayerWeapon(p,l_arma[Tslots],l_muni[Tslots]);
    return 1;
}
how to use that?
pawn Код:
CMD:setpos(playerid,params[])
{
    new
        Float:l_x,
        Float:l_y,
        Float:l_z,
        id;
    if(sscanf(params,"uiii",id,l_x,l_y,l_z))return SendClientMessage(playerid,-1,"/setpos [id] [X] [Y] [Z]");
    if(GetPlayerWeapons(id) == 46) RemovePlayerWeapon(id,46);
    SetPlayerPos(id,,l_x,l_y,l_z);
    return 1;
}
Reply
#8

Thanks to all of you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)