So am just wondering if am doing somthing wrong (did i forget somthing?)
So in my Character class i have made a function.
UFUNCTION(Reliable, Server, WithValidation, BlueprintCallable, Category = "Player Health Interface")
void DecresePlayerHealth(float HealthModifyedValue); // This function Subtract from the players current health. (Use TakeDamage to apply damage.).
And what happens if i define this function is that i get a error telling me its redefined.
So i removed the Defenition from my .cpp file and left only.
bool AMyProjectPlayerClass::DecresePlayerHealth_Validate(float HealthModifyedValue)
{
return true;
}
void AMyProjectPlayerClass::DecresePlayerHealth_Implementation(float HealthModifyedValue)
{
const float HealthCheck = (Health - HealthModifyedValue);
if (HealthCheck >= 0)
{
Health = HealthCheck;
}
else if (HealthCheck < 0)
{
Health = 0.f;
// KillPlayer();
}
else if (HealthCheck == 0)
{
// KillPlayer();
}
if (Health == 0)
{
// KillPlayer();
}
}
Hey. I’m also just starting to learn this part, but as far as I could gather from the Blueprint Networking Tutorial series, I’ll put the “if (Role < ROLE_Authority)” part in the class “applying” the damage, ie. the rocket or bullet. When the rocket/bullet fires the “OnHit” method you put the “if (Role < ROLE_Authority)” in, which will then fire the “ApplyDamage” method depending on the Role. I’ll also put the “if (Role < ROLE_Authority)” in your “TakeDamage” method as a second layer of protection. Hope I got this right
And if so then it calls the RPC method witch in turn calls the SetSomeBool again.
Very confusing indeed wont it just keep calling the fucntion over and over again ? :P.
I be very greatfull for a short explination on the logic behind it.
So from the Wiki Example, maybe it would be easier if I just add some comments in there to explain!
void AYourPlayerController::SetSomeBool(bool bNewSomeBool)
{
// Change the value of the bSomeBool property
bSomeBool = bNewSomeBool;
// If this next check succeeds, we are *not* the authority, meaning we are a network client.
// In this case we also want to call the server function to tell it to change the bSomeBool property as well.
if (Role < ROLE_Authority)
{
ServerSetSomeBool(bNewSomeBool);
}
}
void AYourPlayerController::ServerSetSomeBool_Implementation(bool bNewSomeBool)
{
// This function is only called on the server (where Role == ROLE_Authority), called over the network by clients.
// We need to call SetSomeBool() to actually change the value of the bool now!
// Inside that function, Role == ROLE_Authority, so it won't try to call ServerSetSomeBool() again.
SetSomeBool(bNewSomeBool);
}
Hopefully that clears things up! I’ll go edit the Wiki as well!
P.S. - In this example there is an implicit assumption that only the client is triggering a change in the bool value, since there is no way for the server to send the value to clients.