SA-MP Forums Archive
How would I make a command to teleport them forward, left, right, or back? - 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 would I make a command to teleport them forward, left, right, or back? (/showthread.php?tid=539316)



How would I make a command to teleport them forward, left, right, or back? - Dubya - 27.09.2014

So, I'm just wondering how I would be able to calculate which amount of x and y depending on their angle would actually send them forward, backwards, left, or right?


Re: How would I make a command to teleport them forward, left, right, or back? - VeggieBoy - 27.09.2014

Isn't it taking their location then adding a positive or negative valuable to it?


Re: How would I make a command to teleport them forward, left, right, or back? - Pottus - 27.09.2014

https://sampforum.blast.hk/showthread.php?tid=325872

Now you would need to modify that slightly to do what you want example.

pawn Код:
stock Float:GetPosInFrontOfPlayer(playerid, Float:distance, Float:aoffset, &Float:x, &Float:y)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    a += aoffset;
    switch(IsPlayerInAnyVehicle(playerid))
    {
        case 0: GetPlayerFacingAngle(playerid, a);
        case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}



Re: How would I make a command to teleport them forward, left, right, or back? - Dubya - 27.09.2014

Quote:
Originally Posted by VeggieBoy
Посмотреть сообщение
Isn't it taking their location then adding a positive or negative valuable to it?
Yes in a sort, but I need to be able to calculate the specific position in which would be left or right, forward or back, depending on the angle they are facing.

Quote:
Originally Posted by Pottus
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=325872

Now you would need to modify that slightly to do what you want example.

pawn Код:
stock Float:GetPosInFrontOfPlayer(playerid, Float:distance, Float:aoffset, &Float:x, &Float:y)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    a += aoffset;
    switch(IsPlayerInAnyVehicle(playerid))
    {
        case 0: GetPlayerFacingAngle(playerid, a);
        case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
This will work for forward and backwards, however I have no clue how I will be able to get it working for left or right.


Re: How would I make a command to teleport them forward, left, right, or back? - The__ - 27.09.2014

pawn Код:
COMMAND:x(playerid, params[])
{
    if(!AdminCheck(playerid,ADMINLEVEL_MODERATOR))
        return 1;
    new Float:add;
    if(sscanf(params, "f", add))
    {
        return SendClientMessage(playerid,COLOR_GREY,"USAGE: /x [Float]");
    }
    else
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        SetPlayerPos(playerid, x+add, y, z);
        return 1;
    }
}
// Y
COMMAND:y(playerid, params[])
{
    if(!AdminCheck(playerid,ADMINLEVEL_MODERATOR))
        return 1;
    new Float:add;
    if(sscanf(params, "f", add))
    {
        return SendClientMessage(playerid,COLOR_GREY,"USAGE: /y [Float]");
    }
    else
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        SetPlayerPos(playerid, x, y+add, z);
        return 1;
    }
}
// Z
COMMAND:z(playerid, params[])
{
    if(!AdminCheck(playerid,ADMINLEVEL_MODERATOR))
        return 1;
    new Float:add;
    if(sscanf(params, "f", add))
    {
        return SendClientMessage(playerid,COLOR_GREY,"USAGE: /z [Float]");
    }
    else
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        SetPlayerPos(playerid, x, y, z+add);
        return 1;
    }
}



Re: How would I make a command to teleport them forward, left, right, or back? - Pottus - 27.09.2014

Quote:
Originally Posted by Dubya
Посмотреть сообщение
Yes in a sort, but I need to be able to calculate the specific position in which would be left or right, forward or back, depending on the angle they are facing.


This will work for forward and backwards, however I have no clue how I will be able to get it working for left or right.
Duh, specify the angle offset ----> 0, 90, 180, 270


Re: How would I make a command to teleport them forward, left, right, or back? - Dubya - 27.09.2014

So?
pawn Код:
stock Float:GetPosInFrontOfPlayer(playerid, Float:distance, &Float:x, &Float:y, Float:aoffset = 0.00)
{
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    switch(IsPlayerInAnyVehicle(playerid)) {
        case 0: GetPlayerFacingAngle(playerid, a);
        case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }
    a += aoffset;
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}

YCMD:fr(playerid, params[], help) {
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerPosInFrontOfPlayer(playerid, 3.0, x, y);
    switch(IsPlayerInAnyVehicle(playerid)) {
        case 0: SetPlayerPos(playerid, x, y, z);
        case 1: SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
    }
    return 1;
}

YCMD:ba(playerid, params[], help) {
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerPosInFrontOfPlayer(playerid, -3.0, x, y);
    switch(IsPlayerInAnyVehicle(playerid)) {
        case 0: SetPlayerPos(playerid, x, y, z);
        case 1: SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
    }
    return 1;
}
YCMD:lt(playerid, params[], help) {
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerPosInFrontOfPlayer(playerid, -3.0, x, y, -90);
    switch(IsPlayerInAnyVehicle(playerid)) {
        case 0: SetPlayerPos(playerid, x, y, z);
        case 1: SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
    }
    return 1;
}
YCMD:rt(playerid, params[], help) {
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerPosInFrontOfPlayer(playerid, -3.0, x, y, 90);
    switch(IsPlayerInAnyVehicle(playerid)) {
        case 0: SetPlayerPos(playerid, x, y, z);
        case 1: SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
    }
    return 1;
}



Re: How would I make a command to teleport them forward, left, right, or back? - Pottus - 27.09.2014

That should do it try it.


Re: How would I make a command to teleport them forward, left, right, or back? - TakeiT - 27.09.2014

I simply used X+1, Y+1, it works fine.


Re: How would I make a command to teleport them forward, left, right, or back? - Dubya - 27.09.2014

@TakeiT, that wouldn't always work though because if you need to be teleport to the Right, and you're angle was like -90, it would teleport you to the left, if you needed to be telported left and your angle was -90 it'd teleport you to the right, etc.