How would I make a command to teleport them forward, left, right, or back?
#1

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?
Reply
#2

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

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));
}
Reply
#4

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.
Reply
#5

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;
    }
}
Reply
#6

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
Reply
#7

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;
}
Reply
#8

That should do it try it.
Reply
#9

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

@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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)