Portal SAMP
[Ajuda] me tira uma duvida - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] me tira uma duvida (/showthread.php?tid=4932)



me tira uma duvida - André Santos - 02/12/2024

qual a funcao do samp de quando colocamos um objeto em um player o objeto gruda e se move junto com o player ? 

porq eu fiz um codigo e ao anex o objeto  em que o player escolhe o objeto gruda no player mas o player mesmo se movendo o objeto fica grudado nele fixo sem se mover eu usei o attachobjecttoplayer se tem outros eu nao conheco me ajudem nao e a questao do codigo e sim anexar o objeto ao jogador e o objeto grudar no player e se mover conforme o player se mexe e nao do jeito que fiz que ao player se mover  o objeto gruda e fixa fixo sem movimento desculpe sou horrivel explicando esse foi o codigo que ate um script daqui me ajudou 
eu so mudei uma coisa foi isso AttachObjectToPlayer(playerid, objetos[playerid] assim o objeto nao tava grudando entao inverti para assim AttachObjectToPlayer(objetos[playerid],playerid ai o objeto agora gruda mas nao acompanha o movimento do player ele so acompanha o player ficando fixo sem movimento , mais uma vez obg pela ajuda e desculpa qualqur aborrecimento que eu possa esta causando 

Código:
#include <a_samp>
#include <mSelection>
#include <zcmd>

new objectList = mS_INVALID_LISTID;  // ID da lista de seleção de objetos
new objetos[MAX_PLAYERS];            // Objeto temporário exibido para cada jogador

// Offsets para objetos de jogadores
new Float:objectOffsets[MAX_PLAYERS][6]; // Armazena offsets (X, Y, Z, RotX, RotY, RotZ)

public OnFilterScriptInit()
{
    // Carrega a lista de objetos a partir de um arquivo "objects.txt"
    objectList = LoadModelSelectionMenu("objects.txt");
    return 1;
}

CMD:objetos(playerid, params[])
{
    // Mostra o menu para selecionar um objeto
    ShowModelSelectionMenu(playerid, objectList, "Selecionar Objeto");
    return 1;
}

public OnPlayerModelSelection(playerid, response, listid, modelid)
{
    if (response)
    {
        // Obtém a posição do jogador
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);

        // Cria o objeto na posição do jogador
        objetos[playerid] = CreateObject(modelid, x, y, z, 0.0, 0.0, 0.0);

        if (!IsValidObject(objetos[playerid]))
        {
            SendClientMessage(playerid, -1, "Erro: Objeto não foi criado!");
            return 0;
        }

        // Inicializa os offsets para o objeto
        objectOffsets[playerid][0] = 0.0; // Offset X
        objectOffsets[playerid][1] = 0.0; // Offset Y
        objectOffsets[playerid][2] = 0.5; // Offset Z (altura inicial padrão)
        objectOffsets[playerid][3] = 0.0; // Rotação X
        objectOffsets[playerid][4] = 0.0; // Rotação Y
        objectOffsets[playerid][5] = 0.0; // Rotação Z

        // Anexa o objeto ao jogador usando os offsets iniciais
        AttachObjectToPlayer(playerid, objetos[playerid],
            objectOffsets[playerid][0], objectOffsets[playerid][1], objectOffsets[playerid][2],
            objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5]);

        // Edita o objeto para o jogador ajustá-lo
        EditObject(playerid, objetos[playerid]);
    }
    return 1;
}

public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
    if (response == EDIT_RESPONSE_FINAL)
    {

        // Obtém a posição do jogador
        new Float:playerX, Float:playerY, Float:playerZ;
        GetPlayerPos(playerid, playerX, playerY, playerZ);

        // Calcula os novos offsets baseados na posição do jogador
        objectOffsets[playerid][0] = fX - playerX; // Offset X
        objectOffsets[playerid][1] = fY - playerY; // Offset Y
        objectOffsets[playerid][2] = fZ - playerZ; // Offset Z
        objectOffsets[playerid][3] = fRotX;        // Rotação X
        objectOffsets[playerid][4] = fRotY;        // Rotação Y
        objectOffsets[playerid][5] = fRotZ;        // Rotação Z

        // Reanexa o objeto ao jogador com os novos offsets
        AttachObjectToPlayer(objetos[playerid],playerid,
            objectOffsets[playerid][0], objectOffsets[playerid][1], objectOffsets[playerid][2],
            objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5]);
    }
    else if (response == EDIT_RESPONSE_CANCEL)
    {
        SendClientMessage(playerid, -1, "edicao do objeto foi cancelada.");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    // Remove o objeto associado ao jogador ao desconectar
    if (IsValidObject(objetos[playerid]))
    {
        DestroyObject(objetos[playerid]);
        objetos[playerid] = INVALID_OBJECT_ID; // Reseta o ID para evitar problemas futuros
    }
    return 1;
}



RE: me tira uma duvida - xbruno1000x - 03/12/2024

SetPlayerAttachedObject é a função que você busca. Dessa forma o objeto fica preso a uma das partes do corpo.

Documentação:

função SetPlayerAttachedObject:
https://www.open.mp/docs/scripting/functions/SetPlayerAttachedObject

Id das partes do corpo para usar o Attach:
https://www.open.mp/docs/scripting/resources/boneid


RE: me tira uma duvida - André Santos - 03/12/2024

(03/12/2024 11:40)xbruno1000x Escreveu: SetPlayerAttachedObject é a função que você busca. Dessa forma o objeto fica preso a uma das partes do corpo.

Documentação:

função SetPlayerAttachedObject:
https://www.open.mp/docs/scripting/functions/SetPlayerAttachedObject

Id das partes do corpo para usar o Attach:
https://www.open.mp/docs/scripting/resources/boneid

ola bruno eu criei um comando e nao estou sabendo colocar a sintax correta me ajuda a corrigir mano pois o o objeto nao ta sendo anexado ao corpo do player desculpe pelo encomodo
Código:
#include <a_samp>
#include <mSelection>
#include <zcmd>

new objectList = mS_INVALID_LISTID;  // ID da lista de seleção de objetos
new objetos[MAX_PLAYERS];            // Armazena o ID do objeto anexado para cada jogador

// Offsets para objetos de jogadores
new Float:objectOffsets[MAX_PLAYERS][6]; // Armazena offsets (X, Y, Z, RotX, RotY, RotZ)

public OnFilterScriptInit()
{
    // Carrega a lista de objetos a partir de um arquivo "objects.txt"
    objectList = LoadModelSelectionMenu("objects.txt");

    if (objectList == mS_INVALID_LISTID) {
        print("Falha ao carregar a lista de objetos.");
    }

    return 1;
}

CMD:objetos(playerid, params[])
{
    ShowModelSelectionMenu(playerid, objectList, "Selecionar Objeto");
    return 1;
}

public OnPlayerModelSelection(playerid, response, listid, modelid)
{
    if (response)
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        if (IsValidObject(objetos[playerid]))
{
            DestroyObject(objetos[playerid]); // Remove o objeto anterior, se existir
        }
        objetos[playerid] = CreateObject(modelid, x, y, z, 0.0, 0.0, 0.0);
        // Anexa o objeto ao jogador (índice 0)
        // Inicializa os offsets para o objeto
        objectOffsets[playerid][0] = 0.0; // Offset X
        objectOffsets[playerid][1] = 0.0; // Offset Y
        objectOffsets[playerid][2] = 0.5; // Offset Z (altura inicial padrão)
        objectOffsets[playerid][3] = 0.0; // Rotação X
        objectOffsets[playerid][4] = 0.0; // Rotação Y
        objectOffsets[playerid][5] = 0.0; // Rotação Z

        SetPlayerAttachedObject(playerid, 0, objetos[playerid], 0, objectOffsets[playerid][0], objectOffsets[playerid][1], objectOffsets[playerid][2], objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5], 1.0, 1.0, 1.0, 0xFF00FF00);

        EditAttachedObject(playerid, 0);
    }
    return 1;
}

public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
    if (response == EDIT_RESPONSE_FINAL)
    {
        // Obtém a posição do jogador
        new Float:playerX, Float:playerY, Float:playerZ;
        GetPlayerPos(playerid, playerX, playerY, playerZ);

        // Calcula os novos offsets baseados na posição do jogador
        objectOffsets[playerid][0] = fX - playerX; // Offset X
        objectOffsets[playerid][1] = fY - playerY; // Offset Y
        objectOffsets[playerid][2] = fZ - playerZ; // Offset Z
        objectOffsets[playerid][3] = fRotX;        // Rotação X
        objectOffsets[playerid][4] = fRotY;        // Rotação Y
        objectOffsets[playerid][5] = fRotZ;        // Rotação Z
        SetPlayerAttachedObject(objetos[playerid], 0, playerid, 0, objectOffsets[playerid][0], objectOffsets[playerid][1], objectOffsets[playerid][2], objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5], 1.0, 1.0, 1.0, 0xFF00FF00);
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    // Remove o objeto associado ao jogador ao desconectar
    if (IsValidObject(objetos[playerid]))
    {
        DestroyObject(objetos[playerid]);
        objetos[playerid] = INVALID_OBJECT_ID; // Reseta o ID para evitar problemas futuros
    }
    return 1;
}



RE: me tira uma duvida - xbruno1000x - 06/12/2024

Você está criando o objeto e depois usando SetPlayerAttachedObject, porém essa função espera por um model id e não um objeto.

Tenta da forma abaixo:
Código:
#include <a_samp>
#include <mSelection>
#include <zcmd>

new objectList = mS_INVALID_LISTID;  // ID da lista de seleção de objetos
new objetos[MAX_PLAYERS];            // Modelo anexado para cada jogador
new Float:objectOffsets[MAX_PLAYERS][6]; // Offsets de objetos

public OnFilterScriptInit()
{
    // Carrega a lista de objetos a partir de um arquivo "objects.txt"
    objectList = LoadModelSelectionMenu("objects.txt");

    if (objectList == mS_INVALID_LISTID) {
        print("Falha ao carregar a lista de objetos.");
    }

    return 1;
}

CMD:objetos(playerid, params[])
{
    if (objectList == mS_INVALID_LISTID) {
        SendClientMessage(playerid, 0xFFFF0000, "Lista de objetos não carregada.");
        return 1;
    }
    ShowModelSelectionMenu(playerid, objectList, "Selecionar Objeto");
    return 1;
}

public OnPlayerModelSelection(playerid, response, listid, modelid)
{
    if (response && listid == objectList)
    {
        if (IsValidObject(objetos[playerid]))
        {
            DestroyObject(objetos[playerid]); // Remove o objeto anterior, se existir
            objetos[playerid] = INVALID_OBJECT_ID;
        }

        // Inicializa os offsets
        objectOffsets[playerid][0] = 0.0; // Offset X
        objectOffsets[playerid][1] = 0.0; // Offset Y
        objectOffsets[playerid][2] = 0.5; // Offset Z
        objectOffsets[playerid][3] = 0.0; // Rotação X
        objectOffsets[playerid][4] = 0.0; // Rotação Y
        objectOffsets[playerid][5] = 0.0; // Rotação Z

        // Anexa o objeto ao jogador no slot 0
        SetPlayerAttachedObject(playerid, 0, modelid, 0, objectOffsets[playerid][0], objectOffsets[playerid][1], objectOffsets[playerid][2], objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5], 1.0, 1.0, 1.0);

        // Inicia a edição do objeto
        EditAttachedObject(playerid, 0);
    }
    return 1;
}

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 == EDIT_RESPONSE_FINAL && index == 0)
    {
        // Salva os novos offsets
        objectOffsets[playerid][0] = fOffsetX;
        objectOffsets[playerid][1] = fOffsetY;
        objectOffsets[playerid][2] = fOffsetZ;
        objectOffsets[playerid][3] = fRotX;
        objectOffsets[playerid][4] = fRotY;
        objectOffsets[playerid][5] = fRotZ;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    // Remove o objeto associado ao jogador ao desconectar
    if (IsValidObject(objetos[playerid]))
    {
        DestroyObject(objetos[playerid]);
        objetos[playerid] = INVALID_OBJECT_ID; // Reseta o ID para evitar problemas futuros
    }
    return 1;
}

Documentação para pegar modelid:
https://dev.prineside.com/en/gtasa_samp_model_id/tag/271-sa-mp-0-3-7-rc1/