14.01.2014, 22:24
hey, i made a command to create roadbocks, it works perfect but in some places in the game it doesn't create the roadblock in the right facing angle (in front of me) .....it creates it behind me, why?
CMD:rb(playerid, params[])
{
...//code
new Float:X, Float:Y;
new Float:Distance = 5.0;
GetXYInFrontOfPlayer(playerid, X, Y, Distance);
CreateObject(//ID and place)
...//code
}
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
// Created by ******
new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
if (GetPlayerVehicleID(playerid)) {
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
It's obviously based on the X/Y/Z, but you need to take the facing angle into consideration:
pawn Код:
|
Originally Posted by maramizo
// Created by ******
|
enum rInfo
{
rCreated,
Float:rX,
Float:rY,
Float:rZ,
rObject
};
new Roadblocks[MAX_ROADBLOCKS][rInfo];
stock CreateRoadblock(Object,Float:x,Float:y,Float:z,Float:a)
{
for(new i = 0; i < sizeof(Roadblocks); i++)
{
if(Roadblocks[i][rCreated] == 0)
{
Roadblocks[i][rCreated] = 1;
Roadblocks[i][rX] = x;
Roadblocks[i][rY] = y;
Roadblocks[i][rZ] = z;
Roadblocks[i][rObject] = CreateObject(Object, x, y, z, 0, 0, a);
return 1;
}
}
return 0;
}
CMD:rb(playerid, params[])
{
new rbid,Float:x,Float:y,Float:z,Float:a;
if(PlayerTeam[playerid] != TEAM_SWAT) return SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[Error:] {FFFFFF}Only S.W.A.T Members Can Use This Command.");
if(sscanf(params, "i", rbid)) return SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}[Usage:] {FFFFFF}/rb [1 - 3]");
if(rbid < 1 || rbid > 3) return SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}[Usage:] {FFFFFF}/rb [1 - 3]");
if(rbid == 1)
{
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid,a);
CreateRoadblock(1459,x,y,z,a);
}
if(rbid == 2)
{
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid,a);
CreateRoadblock(978,x,y,z,a);
}
if(rbid == 3)
{
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid,a);
CreateRoadblock(981,x,y,z,a);
}
return 1;
}