how to use GetAttachedObjectPos
#1

I have the stock, but i don't know how to use it.
i want to attach object to my player and edit him (with EditAttachedObject)
then get the new position of the attached object (after the Edit of the object)

i need example please
Reply
#2

pawn Код:
public OnPlayerEditAttachedObject(playerid, response, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ)
{
    if(response)
    {
        if(fScaleX < 0.1) fScaleX = 0.1;
        if(fScaleX > 1.5) fScaleX = 1.5;
        if(fScaleY < 0.1) fScaleY = 0.1;
        if(fScaleY > 1.5) fScaleY = 1.5;
        if(fScaleZ < 0.1) fScaleZ = 0.1;
        if(fScaleZ > 1.5) fScaleZ = 1.5;
        if(fOffsetX < -100) fOffsetX = 0;
        if(fOffsetX > 100) fOffsetX = 100;
        if(fOffsetY < -100) fOffsetY = 0;
        if(fOffsetY > 100) fOffsetY = 100;
        if(fOffsetZ < -100) fOffsetZ = 0;
        if(fOffsetZ > 100) fOffsetZ = 100;

        SendClientMessage(playerid, COLOR_WHITE, "Toy position saved.");

        PlayerToyInfo[playerid][slotselection[playerid]][ptPosX] = fOffsetX;
        PlayerToyInfo[playerid][slotselection[playerid]][ptPosY] = fOffsetY;
        PlayerToyInfo[playerid][slotselection[playerid]][ptPosZ] = fOffsetZ;
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotX] = fRotX;
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotY] = fRotY;
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotZ] = fRotZ;
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleX] = fScaleX;
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleY] = fScaleY;
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleZ] = fScaleZ;

        RemovePlayerAttachedObject(playerid, slotselection[playerid]);
        SetPlayerAttachedObject(playerid, slotselection[playerid], PlayerToyInfo[playerid][slotselection[playerid]][ptModelID],
        PlayerToyInfo[playerid][slotselection[playerid]][ptBone], PlayerToyInfo[playerid][slotselection[playerid]][ptPosX],
        PlayerToyInfo[playerid][slotselection[playerid]][ptPosY], PlayerToyInfo[playerid][slotselection[playerid]][ptPosZ],
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotX], PlayerToyInfo[playerid][slotselection[playerid]][ptRotY],
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotZ], PlayerToyInfo[playerid][slotselection[playerid]][ptScaleX],
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleY], PlayerToyInfo[playerid][slotselection[playerid]][ptScaleZ]);
    }  else  {
        SendClientMessage(playerid, COLOR_GREY, "Toy position not saved.");
        RemovePlayerAttachedObject(playerid, slotselection[playerid]);
    }
    return 1;
}
If this what you mean..
Reply
#3

Quote:
Originally Posted by Max5
Посмотреть сообщение
pawn Код:
public OnPlayerEditAttachedObject(playerid, response, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ)
{
    if(response)
    {
        if(fScaleX < 0.1) fScaleX = 0.1;
        if(fScaleX > 1.5) fScaleX = 1.5;
        if(fScaleY < 0.1) fScaleY = 0.1;
        if(fScaleY > 1.5) fScaleY = 1.5;
        if(fScaleZ < 0.1) fScaleZ = 0.1;
        if(fScaleZ > 1.5) fScaleZ = 1.5;
        if(fOffsetX < -100) fOffsetX = 0;
        if(fOffsetX > 100) fOffsetX = 100;
        if(fOffsetY < -100) fOffsetY = 0;
        if(fOffsetY > 100) fOffsetY = 100;
        if(fOffsetZ < -100) fOffsetZ = 0;
        if(fOffsetZ > 100) fOffsetZ = 100;

        SendClientMessage(playerid, COLOR_WHITE, "Toy position saved.");

        PlayerToyInfo[playerid][slotselection[playerid]][ptPosX] = fOffsetX;
        PlayerToyInfo[playerid][slotselection[playerid]][ptPosY] = fOffsetY;
        PlayerToyInfo[playerid][slotselection[playerid]][ptPosZ] = fOffsetZ;
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotX] = fRotX;
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotY] = fRotY;
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotZ] = fRotZ;
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleX] = fScaleX;
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleY] = fScaleY;
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleZ] = fScaleZ;

        RemovePlayerAttachedObject(playerid, slotselection[playerid]);
        SetPlayerAttachedObject(playerid, slotselection[playerid], PlayerToyInfo[playerid][slotselection[playerid]][ptModelID],
        PlayerToyInfo[playerid][slotselection[playerid]][ptBone], PlayerToyInfo[playerid][slotselection[playerid]][ptPosX],
        PlayerToyInfo[playerid][slotselection[playerid]][ptPosY], PlayerToyInfo[playerid][slotselection[playerid]][ptPosZ],
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotX], PlayerToyInfo[playerid][slotselection[playerid]][ptRotY],
        PlayerToyInfo[playerid][slotselection[playerid]][ptRotZ], PlayerToyInfo[playerid][slotselection[playerid]][ptScaleX],
        PlayerToyInfo[playerid][slotselection[playerid]][ptScaleY], PlayerToyInfo[playerid][slotselection[playerid]][ptScaleZ]);
    }  else  {
        SendClientMessage(playerid, COLOR_GREY, "Toy position not saved.");
        RemovePlayerAttachedObject(playerid, slotselection[playerid]);
    }
    return 1;
}
If this what you mean..
Umm.. nope
I meant I want to get the X Y Z of the attached object
for example:
when i'll use the command "/GetPos"
its will SendClientMessage with the position (X,Y,Z) of the attached object
Reply
#4

GetObjectPos would work for getting the object's position even if it's attached to anything. If you're looking for the attached offset, store it an array while attaching it.
Reply
#5

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
GetObjectPos would work for getting the object's position even if it's attached to anything. If you're looking for the attached offset, store it an array while attaching it.
can i get example please?
Reply
#6

https://sampwiki.blast.hk/wiki/GetPlayerObjectPos
Reply
#7

Quote:
Originally Posted by Max5
Посмотреть сообщение
pawn Код:
CMD:pos(playerid,params[]){
GetPlayerObjectPos(playerid, 1, fX, fY, fZ);
format(String,sizeof(String),"%f %f %f",fX,fY,fZ);
SendClientMessage(playerid,C_RED,String);
return 1;}
its shows all the times 0.00000 0.00000 0.00000
..... its not working... and this is the object:
pawn Код:
SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.101, -1, 0, 5.50, 84.60, 83.7, 1, 1, 1);
and this is my code to edit
pawn Код:
CMD:edit(playerid,params[]){
EditAttachedObject(playerid,1); return 1;}
Reply
#8

BUMP
Reply
#9

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
GetObjectPos would work for getting the object's position even if it's attached to anything. If you're looking for the attached offset, store it an array while attaching it.
Quote:
Originally Posted by Max5
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=298199 - although I'm not sure if it has been fixed yet or not, but it seems to be bugged.

@op: There is no accurate way to get a player attached object, I suggest storing all server values in an array/enum and retrieve information from that.

https://sampwiki.blast.hk/wiki/OnPlayerEditAttachedObject

pawn Код:
enum attached_object_data
{
ao_model,
ao_bone,
Float:ao_x,
Float:ao_y,
Float:ao_z,
Float:ao_rx,
Float:ao_ry,
Float:ao_rz,
Float:ao_sx,
Float:ao_sy,
Float:ao_sz
}
 
new ao[MAX_PLAYERS][MAX_PLAYER_ATTACHED_OBJECTS][attached_object_data];
 
// The data should be stored in the above array when attached objects are attached.
 
public OnPlayerEditAttachedObject(playerid, response, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ)
{
    if(response)
    {
        SendClientMessage(playerid, COLOR_GREEN, "Attached object edition saved.");
 
        ao[playerid][index][ao_x] = fOffsetX;
        ao[playerid][index][ao_y] = fOffsetY;
        ao[playerid][index][ao_z] = fOffsetZ;
        ao[playerid][index][ao_rx] = fRotX;
        ao[playerid][index][ao_ry] = fRotY;
        ao[playerid][index][ao_rz] = fRotZ;
        ao[playerid][index][ao_sx] = fScaleX;
        ao[playerid][index][ao_sy] = fScaleY;
        ao[playerid][index][ao_sz] = fScaleZ;
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "Attached object edition not saved.");
 
        new i = index;
        SetPlayerAttachedObject(playerid, index, modelid, boneid, ao[playerid][i][ao_x], ao[playerid][i][ao_y], ao[playerid][i][ao_z], ao[playerid][i][ao_rx], ao[playerid][i][ao_ry], ao[playerid][i][ao_rz], ao[playerid][i][ao_sx], ao[playerid][i][ao_sy], ao[playerid][i][ao_sz]);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)