SA-MP Forums Archive
CreateObject - 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: CreateObject (/showthread.php?tid=487734)



CreateObject - AnonScripter - 14.01.2014

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?


Re: CreateObject - maramizo - 14.01.2014

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));
}



Respuesta: Re: CreateObject - Swedky - 15.01.2014

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



Re: CreateObject - AnonScripter - 15.01.2014

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;
}