Solved How to get players weapon?

Advertisement

Official Game Server Partner

Codeboy

New member
Messages
21
Likes
0
Points
1
Michidu, Can you help me have a look? I want to make long tube rifle dozen players without damage, Here is my code snippet, But it dozen dino also no harm, this is not what I want results.:confused:


C++:
DECLARE_HOOK(AShooterCharacter_TakeDamage, float, AShooterCharacter *, float, FDamageEvent *, AController *, AActor *);
float Hook_AShooterCharacter_TakeDamage(AShooterCharacter *_this, float Damage, FDamageEvent * DamageEvent, AController* EventInstigator, AActor * DamageCauser)
{
    if (_this && _this->PlayerStateField() && EventInstigator && !EventInstigator->IsLocalController() && EventInstigator->IsA(AShooterPlayerController::StaticClass()))
    {
        AShooterPlayerController* InstigatorShooterController = static_cast<AShooterPlayerController*>(EventInstigator);

        if (InstigatorShooterController && InstigatorShooterController->PlayerStateField() && InstigatorShooterController->GetPlayerCharacter())
        {
            if (InstigatorShooterController->GetPlayerCharacter()->CurrentWeaponField() && InstigatorShooterController->GetPlayerCharacter()->CurrentWeaponField()->AssociatedPrimalItemField())
            {
                UPrimalItem* WeaponItem = InstigatorShooterController->GetPlayerCharacter()->CurrentWeaponField()->AssociatedPrimalItemField();

                const FString WeaponItemBP = ArkApi::IApiUtils::GetItemBlueprint(WeaponItem);

                if (WeaponItemBP.EndsWith("PrimalItem_WeaponOneShotRifle'"))
                {//长管步枪;
                    return AShooterCharacter_TakeDamage_original(_this, 1.0f, DamageEvent, EventInstigator, DamageCauser);
                }
                else if (WeaponItemBP.EndsWith("PrimalItem_WeaponMachinedSniper'"))
                {//制式狙击步枪;
                    return AShooterCharacter_TakeDamage_original(_this, 1.0f, DamageEvent, EventInstigator, DamageCauser);
                }
            }
        }
    }

    return AShooterCharacter_TakeDamage_original(_this, Damage, DamageEvent, EventInstigator, DamageCauser);
}
 

Codeboy

New member
Messages
21
Likes
0
Points
1
sorry, I don't know how to check, I only found AShooterPlayerController, there is no AShooterPlayerCharacter.

TIM截图20181208000723.png
 

OwnProx

Moderator
Plugin Developer
Messages
681
Likes
345
Points
63
try AShooterCharacter::GetPrivateStaticClass() or AShooterCharacter::StaticClass()

on another note.
if you want to intercept both character and dino damage hook APrimalCharacter::TakeDamage
if you want to intercept dino damage hook APrimalDinoCharacter::TakeDamage
 
Last edited:

Codeboy

New member
Messages
21
Likes
0
Points
1
try AShooterCharacter::GetPrivateStaticClass() or AShooterCharacter::StaticClass()

on another note.
if you want to intercept both character and dino damage hook APrimalCharacter::TakeDamage
if you want to intercept dino damage hook APrimalDinoCharacter::TakeDamage
thank you, I know, I just need to intercept the player's damage, dino and don't want to damage.
But, I didn't find AShooterPlayerCharacter::TakeDamage, so use APrimalCharacter::TakeDamage.
Now I don't know how to distinguish between _this is a player, rather than a dino.:confused:
in ArkApi all .h file, not found AShooterPlayerCharacter related information.
 
Top