27.09.2014, 15:16
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?
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));
}
Isn't it taking their location then adding a positive or negative valuable to it?
|
https://sampforum.blast.hk/showthread.php?tid=325872
Now you would need to modify that slightly to do what you want example. 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;
}
}
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. |
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;
}