how to auto pickup bag and corpse?

fal

New member
Messages
3
Likes
0
Points
1
i want recover items when player respawn.

bag name is "DeathItemCache_PlayerDeath_C_**"
player or corpse name is "PlayerPawnTest_Male_**"
player or corpse name is "PlayerPawnTest_Female_C_**"

can you help me?

Hook
Code:
DECLARE_HOOK(AShooterCharacter_AuthPostSpawnInit, void, AShooterCharacter*);

void InitHooks() {
    ArkApi::GetHooks().SetHook("AShooterCharacter.AuthPostSpawnInit", &Hook_AShooterCharacter_AuthPostSpawnInit, &AShooterCharacter_AuthPostSpawnInit_original);
}

void RemoveHooks() {
    ArkApi::GetHooks().DisableHook("AShooterCharacter.AuthPostSpawnInit", &Hook_AShooterCharacter_AuthPostSpawnInit);
}
Code:
void Hook_AShooterCharacter_AuthPostSpawnInit(AShooterCharacter* _this)
{
    AShooterCharacter_AuthPostSpawnInit_original(_this);

    AShooterPlayerController* player = ArkApi::GetApiUtils().FindControllerFromCharacter(_this);
    if (!player)
    {
        return;
    }
    int teamid_spawn = player->TargetingTeamField();
    FString playername_spawn = _this->PlayerNameField();
    uint64 steam_id = ArkApi::IApiUtils::GetSteamIdFromController(player);

    const auto& actors = ArkApi::GetApiUtils().GetWorld()->PersistentLevelField()->GetActorsField();
    for (AActor* actor : actors)
    {
        if (actor != nullptr)
        {
            FString actorString;
            actor->NameField().ToString(&actorString);
            const std::string actorName = actorString.ToString();
            USceneComponent* Component = actor->RootComponentField();
            if (Component) {
                FVector pos = Component->RelativeLocationField();
                if (actorString.Contains("DeathItemCache_PlayerDeath_C")) {
                    //DeathItemCache_PlayerDeath_C
                    if (actor->IsA(APrimalStructure::GetPrivateStaticClass())) {
                        APrimalStructure* structure = static_cast<APrimalStructure*>(actor);
                        int teamid_owner = structure->TargetingTeamField();
                        FString playername_owner = structure->OwnerNameField();
                        if (teamid_spawn == teamid_owner && playername_owner.Contains(playername_spawn)) {
                            Log::GetLog()->info("{} admincheat SetPlayerPos {} {} {}", actorName, pos.X, pos.Y, pos.Z);
                            // TODO : pick up bag
                            // TODO : remove bag
                        }
                    }
                }
                else if (actor->IsA(AShooterCharacter::GetPrivateStaticClass()))
                {
                    // PlayerPawnTest_Male
                    // PlayerPawnTest_Female
                    int teamid_spawn = actor->TargetingTeamField();
                    AShooterCharacter* findShooterCharacter = static_cast<AShooterCharacter*>(actor);
                    if (findShooterCharacter->IsDead()) {
                        int teamid_owner = findShooterCharacter->TargetingTeamField();
                        FString playername_owner = findShooterCharacter->PlayerNameField();
                        if (teamid_spawn == teamid_owner && playername_spawn.Equals(playername_owner)) {
                            Log::GetLog()->info("{} admincheat SetPlayerPos {} {} {}", actorName,  pos.X, pos.Y, pos.Z);
                            UPrimalInventoryComponent* inventory_old = findShooterCharacter->MyInventoryComponentField();
                            if (!inventory_old)
                            {
                                return;
                            }

                            TArray<UPrimalItem*> items_for_removal;
                            TArray<UPrimalItem*> items = inventory_old->InventoryItemsField();
                            for (UPrimalItem* item : items)
                            {
                                if (item->ClassField() != nullptr)
                                {
                                   // TODO : giveitem to player
                                    items_for_removal.Add(item);
                                }
                            }

                            for (UPrimalItem* item : items_for_removal)
                            {
                                inventory_old->RemoveItem(&item->ItemIDField(), false, false, true, true);
                            }
                           // TODO : remove corpse 
                        }
                    }
                }
            }
        }
    }
}
 
Advertisement

Monetise Your Game Server

Want to monetise your ARK Server? Create your own webstore at tebex.io

Top