CreateObject
#1

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

It's obviously based on the X/Y/Z, but you need to take the facing angle into consideration:
pawn Код:
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));
}
Reply
#3

Quote:
Originally Posted by maramizo
Посмотреть сообщение
It's obviously based on the X/Y/Z, but you need to take the facing angle into consideration:
pawn Код:
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));
}
Quote:
Originally Posted by maramizo
// Created by ******


This function created by Dracoblue...
Reply
#4

guys i have different way how to create a roadblock, this is it, how to fix my problem??

pawn Код:
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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)