Portal SAMP
[Ajuda] Air Trafficking From - 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] Air Trafficking From (/showthread.php?tid=4935)



Air Trafficking From - Enila182 - 15/12/2024

Eae pessoal estou usando o sistema do rootcause e está ocorrendo um erro que quando solta a mercadoria em cima do checkpoint fala que 'O pacote não caiu na área marcada'. tentei aumentar a distancia e nada.

Código:
#define     FILTERSCRIPT
#include     <a_samp>
#include    <mapandreas>     // http://forum.sa-mp.com/showthread.php?t=273263

#define     PACKAGE_MODEL   (2912)
#define     MAPICON_INDEX   (69)

#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))

enum    e_droplocations
{
    dropLocation[32],
    Float: dropX,
    Float: dropY,
    Float: dropZ
};

enum    e_dropobjects
{
    OBJECT_PACKAGE,
    OBJECT_ZONE
};

new
    DropLocations[][e_droplocations] = {
    // example locations
        {"Farm", 22.3, 17.4, 5.0},
        {"Area 51", 302.2160, 1955.8740, 17.6406},
        {"Flying School", 415.5471, 2503.8643, 16.9425},
        {"NSA HQ", -317.4946, 1523.1005, 75.3594}
    };

new
    bool: InDelivery[MAX_PLAYERS] = {false, ...},
    PackageCount[MAX_PLAYERS] = {5, ...},
    TraffickingObjects[MAX_PLAYERS][2];

stock IsATraffickingPlane(modelid)
{
    new planes[] = {593, 511, 460};
    for(new i; i < sizeof(planes); ++i)
    {
        if(planes[i] == modelid) return 1;
    }

    return 0;
}

stock ResetDelivery(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
    InDelivery[playerid] = false;
    PackageCount[playerid] = 5;
    RemovePlayerMapIcon(playerid, MAPICON_INDEX);
    SetPVarInt(playerid, "DeliveryCooldown", tickcount()+120000);
    
    if(IsValidObject(TraffickingObjects[playerid][OBJECT_PACKAGE]))
    {
        DestroyObject(TraffickingObjects[playerid][OBJECT_PACKAGE]);
        TraffickingObjects[playerid][OBJECT_PACKAGE] = INVALID_OBJECT_ID;
    }

    if(IsValidPlayerObject(playerid, TraffickingObjects[playerid][OBJECT_ZONE]))
    {
        DestroyPlayerObject(playerid, TraffickingObjects[playerid][OBJECT_ZONE]);
        TraffickingObjects[playerid][OBJECT_ZONE] = INVALID_OBJECT_ID;
    }
    
    return 1;
}

stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2) // http://forum.sa-mp.com/showpost.php?p=2919962&postcount=2
    return floatsqroot((((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));

stock RandomEx(min, max)
    return random(max - min) + min;

public OnPlayerConnect(playerid)
{
    InDelivery[playerid] = false;
    PackageCount[playerid] = 5;
    TraffickingObjects[playerid][OBJECT_PACKAGE] = INVALID_OBJECT_ID;
    TraffickingObjects[playerid][OBJECT_ZONE] = INVALID_OBJECT_ID;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    ResetDelivery(playerid);
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(InDelivery[playerid])
    {
        SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY FAILED: {FFFFFF}You died.");
        ResetDelivery(playerid);
    }
    
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER && IsATraffickingPlane(GetVehicleModel(GetPlayerVehicleID(playerid))) && GetPVarInt(playerid, "DeliveryCooldown") < tickcount())
    {
        GameTextForPlayer(playerid, "~n~~n~~n~~w~Air Trafficking Available~n~Press ~y~~k~~TOGGLE_SUBMISSIONS~ ~w~to start", 3000, 3);
    }
    
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(InDelivery[playerid])
    {
        SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY FAILED: {FFFFFF}You left your plane.");
        ResetDelivery(playerid);
    }
    
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(IsATraffickingPlane(GetVehicleModel(GetPlayerVehicleID(playerid))) && PRESSED(KEY_SUBMISSION))
    {
        if(!InDelivery[playerid]) {
            if(GetPVarInt(playerid, "DeliveryCooldown") > tickcount()) return SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY: {FFFFFF}Please wait to start another delivery mission again.");
            new id = random(sizeof(DropLocations)), string[144];
            TraffickingObjects[playerid][OBJECT_ZONE] = CreatePlayerObject(playerid, 19946, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 0.0, 0.0, 0.0, 1200.0);
           
            SetPlayerMapIcon(playerid, MAPICON_INDEX, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 24, 0, MAPICON_GLOBAL);
            SendClientMessage(playerid, 0x2ECC71FF, "DELIVERY: {FFFFFF}You've started a delivery mission.");
            format(string, sizeof(string), "DELIVERY: {FFFFFF}Drop the package in the marked area at {3498DB}%s {FFFFFF}and you'll get your money.", DropLocations[id][dropLocation]);
            SendClientMessage(playerid, 0x2ECC71FF, string);
            SendClientMessage(playerid, 0x2ECC71FF, "DELIVERY: {FFFFFF}You can drop a crate using H/CAPS LOCK.");
            SendClientMessage(playerid, 0x2ECC71FF, "DELIVERY: {FFFFFF}You can cancel the delivery mission using 2 or by leaving your plane.");
            InDelivery[playerid] = true;
            PackageCount[playerid] = 5;
        }else{
            SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY CANCELLED: {FFFFFF}You've cancelled the delivery mission.");
            ResetDelivery(playerid);
        }
    }
    
    if(InDelivery[playerid] && PRESSED(KEY_CROUCH))
    {
        if(IsValidObject(TraffickingObjects[playerid][OBJECT_PACKAGE])) return 1;
        if(PackageCount[playerid] == 0) return SendClientMessage(playerid, 0xE74C3CFF, "DELIVERY: {FFFFFF}You don't have any more packages.");
        new Float: x, Float: y, Float: z, Float: z2;
        GetPlayerPos(playerid, x, y, z);
        GetPointZPos(x, y, z2);
        TraffickingObjects[playerid][OBJECT_PACKAGE] = CreateObject(PACKAGE_MODEL, x, y, z-1.5, 0.0, 0.0, 0.0);
        MoveObject(TraffickingObjects[playerid][OBJECT_PACKAGE], x, y, z2, 20.0);
        PackageCount[playerid]--;
    }
    
    return 1;
}

public OnObjectMoved(objectid)
{
    if(GetObjectModel(objectid) == PACKAGE_MODEL)
    {
        new owner = INVALID_PLAYER_ID;
        for(new i, p = GetPlayerPoolSize(); i <= p; ++i)
        {
            if(objectid == TraffickingObjects[i][OBJECT_PACKAGE])
            {
                owner = i;
                break;
            }
        }
        
        new Float: objx, Float: objy, Float: objz, Float: zonex, Float: zoney, Float: zonez, money;
        GetObjectPos(objectid, objx, objy, objz);
        GetPlayerObjectPos(owner, TraffickingObjects[owner][OBJECT_ZONE], zonex, zoney, zonez);
        new Float: dist = Distance(objx, objy, objz, zonex, zoney, zonez);
        if(dist < 8.0) {
            money = 1500 + floatround(-100 * dist, floatround_floor);
            if(money < 250) money = 250;
            GivePlayerMoney(owner, money);

            new id = random(sizeof(DropLocations)), string[144];
            format(string, sizeof(string), "DELIVERY: {FFFFFF}You've delivered a package and earned {2ECC71}$%d{FFFFFF}.", money);
            SendClientMessage(owner, 0x2ECC71FF, string);
           
            DestroyPlayerObject(owner, TraffickingObjects[owner][OBJECT_ZONE]);
            TraffickingObjects[owner][OBJECT_ZONE] = CreatePlayerObject(owner, 19946, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 0.0, 0.0, 0.0, 1200.0);
            SetPlayerMapIcon(owner, 69, DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 24, 0, MAPICON_GLOBAL);
            format(string, sizeof(string), "DELIVERY: {FFFFFF}Drop the package in the marked area at {3498DB}%s{FFFFFF}.", DropLocations[id][dropLocation]);
            SendClientMessage(owner, 0x2ECC71FF, string);
            format(string, sizeof(string), "DELIVERY: {FFFFFF}Packages left: {3498DB}%d{FFFFFF}.", PackageCount[owner]);
            SendClientMessage(owner, 0x2ECC71FF, string);
        }else{
            SendClientMessage(owner, 0xE74C3CFF, "DELIVERY: {FFFFFF}Package didn't land in the marked area, better luck next time.");
        }
        
        DestroyObject(TraffickingObjects[owner][OBJECT_PACKAGE]);
        TraffickingObjects[owner][OBJECT_PACKAGE] = INVALID_OBJECT_ID;
        if(PackageCount[owner] == 0)
        {
            SendClientMessage(owner, 0x2ECC71FF, "DELIVERY: {FFFFFF}You're out of packages.");
            ResetDelivery(owner);
        }
    }
    
    return 1;
}



RE: Air Trafficking From - strelo - 16/12/2024

Possíveis Causas do Problema


1. Distância de Verificação:


 No evento OnObjectMoved, você verifica a distância entre a posição do pacote e a posição da "zona de entrega" usando a função Distance. O valor definido para a distância máxima é 8.0:

Código PHP:
if(dist 8.0) { 


Se o pacote não "cair" dentro de 8.0 unidades da zona de entrega, a lógica considera que ele não caiu na área.

Porém, dependendo do tamanho do checkpoint (do objeto 19946 que representa a área) e do modelo do pacote (2912), essa distância pode ser insuficiente. O objeto pode estar visualmente dentro do checkpoint, mas o cálculo da distância pode resultar em um valor maior devido às coordenadas.


2. Verificação com GetPlayerObjectPos:



A função GetPlayerObjectPos está sendo usada para obter as coordenadas do checkpoint:

Código PHP:
GetPlayerObjectPos(ownerTraffickingObjects[owner][OBJECT_ZONE], zonexzoneyzonez); 

Se o checkpoint estiver criado com uma coordenada Z específica (elevação), mas o pacote "cair" em uma altura ligeiramente diferente, isso pode causar imprecisão no cálculo de distância.

Solução Proposta

1. Ajustar a Distância Máxima

Aumente o valor da distância de 8.0 para algo mais permissivo, como 10.0 ou 12.0


Código PHP:
if(dist 12.0) { 

Isso garantirá que pequenas variações na posição não impeçam a validação do pacote.

2. Ignorar Pequenas Diferenças na Altura (Z)


Ao calcular a distância, você pode reduzir a influência da coordenada Z (altura). Isso é útil caso o pacote e o checkpoint estejam em elevações ligeiramente diferentes.

Aqui está a modificação na lógica de cálculo da distância:


Código PHP:
new FloatadjustedDist Distance(objxobjyzonezzonexzoneyzonez);
if(
adjustedDist 12.0) { 

Basicamente, usamos a coordenada Z do checkpoint como referência para a altura, ignorando a altura exata do pacote.

3. Adicionar Debug para Testar Coordenadas

Se o problema persistir, adicione mensagens de depuração para verificar as coordenadas e a distância calculada:

Código PHP:
printf("Object Pos: %.2f, %.2f, %.2f"objxobjyobjz);
printf("Zone Pos: %.2f, %.2f, %.2f"zonexzoneyzonez);
printf("Distance: %.2f"dist); 

Isso ajudará a entender se a distância calculada está correta.


Código Ajustado

Abaixo está a versão ajustada da lógica em OnObjectMoved:

Código PHP:
public OnObjectMoved(objectid)
{
    if(GetObjectModel(objectid) == PACKAGE_MODEL)
    {
        new owner INVALID_PLAYER_ID;
        for(new iGetPlayerPoolSize(); <= p; ++i)
        {
            if(objectid == TraffickingObjects[i][OBJECT_PACKAGE])
            {
                owner i;
                break;
            }
        }
        
        
new FloatobjxFloatobjyFloatobjzFloatzonexFloatzoneyFloatzonezmoney;
        GetObjectPos(objectidobjxobjyobjz);
        GetPlayerObjectPos(ownerTraffickingObjects[owner][OBJECT_ZONE], zonexzoneyzonez);
        
        
// Ajusta para ignorar pequenas diferenças de altura
        new Floatdist Distance(objxobjyzonezzonexzoneyzonez);
        if(dist 12.0) { // Aumentei a distância para 12.0
            money 1500 floatround(-100 distfloatround_floor);
            if(money 250money 250;
            GivePlayerMoney(ownermoney);

            new id random(sizeof(DropLocations)), string[144];
            format(stringsizeof(string), "DELIVERY: {FFFFFF}You've delivered a package and earned {2ECC71}$%d{FFFFFF}."money);
            SendClientMessage(owner0x2ECC71FFstring);
           
            DestroyPlayerObject
(ownerTraffickingObjects[owner][OBJECT_ZONE]);
            TraffickingObjects[owner][OBJECT_ZONE] = CreatePlayerObject(owner19946DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 0.00.00.01200.0);
            SetPlayerMapIcon(owner69DropLocations[id][dropX], DropLocations[id][dropY], DropLocations[id][dropZ], 240MAPICON_GLOBAL);
            format(stringsizeof(string), "DELIVERY: {FFFFFF}Drop the package in the marked area at {3498DB}%s{FFFFFF}."DropLocations[id][dropLocation]);
            SendClientMessage(owner0x2ECC71FFstring);
            format(stringsizeof(string), "DELIVERY: {FFFFFF}Packages left: {3498DB}%d{FFFFFF}."PackageCount[owner]);
            SendClientMessage(owner0x2ECC71FFstring);
        }else{
            SendClientMessage(owner0xE74C3CFF"DELIVERY: {FFFFFF}Package didn't land in the marked area, better luck next time.");
        }
        
        DestroyObject
(TraffickingObjects[owner][OBJECT_PACKAGE]);
        TraffickingObjects[owner][OBJECT_PACKAGE] = INVALID_OBJECT_ID;
        if(PackageCount[owner] == 0)
        {
            SendClientMessage(owner0x2ECC71FF"DELIVERY: {FFFFFF}You're out of packages.");
            ResetDelivery(owner);
        }
    }
    
    
return 1;




RE: Air Trafficking From - Enila182 - 16/12/2024

Oi, tentei aumentar pra 20.0 e mesmo assim não deu