Alert of attacked tribe

sky1145960810

New member
Messages
5
Points
1
C++:
bool Hook_APrimalStructure_Die(APrimalStructure* _this, float KillingDamage, FDamageEvent* DamageEvent, AController* Killer, AActor* DamageCauser)
{
    int structureTeamId = _this->TargetingTeamField();
    if (structureTeamId != 0) // tribe
    {
        if (Killer && Killer->IsA(APlayerController::StaticClass())) {
            AShooterPlayerController* player = (AShooterPlayerController*)Killer;
            int killerTeamId = player->TargetingTeamField();

            ArkApi::GetApiUtils().SendChatMessage(player, "TestPlugin", *FString("[Structure Death] StructureTeamId: " + std::to_string(structureTeamId)));
            ArkApi::GetApiUtils().SendChatMessage(player, "TestPlugin", *FString("[Structure Death] KillerTeamId: " + std::to_string(killerTeamId)));
        }
    }
}
Learn from the code of 0x21, I want to know How can I send a chat message to the building owner
 
Advertisement

Official Game Server Partner

kalendell

Active member
Plugin Developer
Messages
136
Points
28
C++:
int GetTribeId(AShooterPlayerController* playerController)
{
    int tribeId = 0;

    auto playerState = reinterpret_cast<AShooterPlayerState*>(playerController->PlayerStateField());
    if (playerState)
    {
        tribeId = playerState->MyTribeDataField()->TribeIDField();
    }

    return tribeId;
}
bool Hook_APrimalStructure_Die(APrimalStructure* _this, float KillingDamage, FDamageEvent* DamageEvent, AController* Killer, AActor* DamageCauser)
{
    int structureTeamId = _this->TargetingTeamField();
    if (structureTeamId != 0) // tribe
    {
        if (Killer && Killer->IsA(AShooterPlayerController::StaticClass())) {
            AShooterPlayerController* player = (AShooterPlayerController*)Killer;
            int killerTeamId = player->TargetingTeamField();

            ArkApi::GetApiUtils().SendChatMessage(player, "TestPlugin", "[Structure Death] StructureTeamId: {}", structureTeamId);
            ArkApi::GetApiUtils().SendChatMessage(player, "TestPlugin", "[Structure Death] KillerTeamId: {}", killerTeamId);

            auto world = ArkApi::GetApiUtils().GetWorld();
            if (world) {
                auto playerControllers = world->PlayerControllerListField();
                for (auto playerController : playerControllers)
                {
                    AShooterPlayerController* aShooterPC = static_cast<AShooterPlayerController*>(playerController.Get());
                    if (aShooterPC) {
                        auto tribeId = GetTribeId(aShooterPC);
                        if (tribeId == structureTeamId) {
                            ArkApi::GetApiUtils().SendChatMessage(aShooterPC, "TestPlugin", "Your structure has been destroyed by a player.");
                        }
                    }
                }
            }
        }
    }
}
 
Last edited:

Lethal

Active member
Plugin Developer
Messages
363
Points
43
Small error that I corrected in the last SendChatMessage().

C++:
int GetTribeId(AShooterPlayerController* playerController)
{
    int tribeId = 0;

    auto playerState = reinterpret_cast<AShooterPlayerState*>(playerController->PlayerStateField());
    if (playerState)
    {
        tribeId = playerState->MyTribeDataField()->TribeIDField();
    }

    return tribeId;
}
bool Hook_APrimalStructure_Die(APrimalStructure* _this, float KillingDamage, FDamageEvent* DamageEvent, AController* Killer, AActor* DamageCauser)
{
    int structureTeamId = _this->TargetingTeamField();
    if (structureTeamId != 0) // tribe
    {
        if (Killer && Killer->IsA(AShooterPlayerController::StaticClass())) {
            AShooterPlayerController* player = (AShooterPlayerController*)Killer;
            int killerTeamId = player->TargetingTeamField();

            ArkApi::GetApiUtils().SendChatMessage(player, "TestPlugin", "[Structure Death] StructureTeamId: {}", structureTeamId);
            ArkApi::GetApiUtils().SendChatMessage(player, "TestPlugin", "[Structure Death] KillerTeamId: {}", killerTeamId);

            auto world = ArkApi::GetApiUtils().GetWorld();
            if (world) {
                auto playerControllers = world->PlayerControllerListField();
                for (auto playerController : playerControllers)
                {
                    AShooterPlayerController* aShooterPC = static_cast<AShooterPlayerController*>(playerController.Get());
                    if (aShooterPC) {
                        auto tribeId = GetTribeId(aShooterPC);
                        if (tribeId == structureTeamId) {
                            ArkApi::GetApiUtils().SendChatMessage(aShooterPC, "TestPlugin", "Your structure has been destroyed by a player.");
                        }
                    }
                }
            }
        }
    }
}
 
Top