x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Handle different damage types

Hi,

I want to create multiple damage types (i.e normal damage, poison, slowdown, stun, fear...), but I don't know what is the best way to do it. I have different functions in which I have the implementation of the different damage types, but I don't know where call them, neither how works the parameter DamageType-DamageEvent. I also read about bind delegates with OnTakeAnyDamage, but I cannot make it run.

Can someone explain what is the best way to handle that different types of damage?

thanks :)

Product Version: Not Selected
Tags:
more ▼

asked Dec 03 '14 at 05:38 PM in C++ Programming

avatar image

Davixe
184 18 21 34

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello Davixe,

DamageType it is class that used to handle type of damage that was applied to some actor. For example you can have different damage types for your weapon (simple bullets, incendiary bullets, etc.) This function pass your damage type class to the TakeDamage function through EventDamage parameter.

 // process machine gun hit function
 UGameplayStatics::ApplyPointDamage(HitResult.Actor.Get(), ImpactDamage, ShootDir, HitResult, MyController.Get(), this, UDamageType_Gatling::StaticClass());
 
 // Take damage function
 float AMyPawn::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser)
 {
     …
     DamageEvent.DamageTypeClass;
     …
 }

Best regards, Gleb

more ▼

answered Dec 10 '14 at 01:07 PM

avatar image

Gleb.Bulgakov
1.8k 76 19 143

avatar image Davixe Dec 11 '14 at 12:12 PM

Yeah, that makes sense, thx for the answer, but still don't understand how can I bind a specific delegate function to execute in TakeDamage.

Thx.

avatar image Gleb.Bulgakov Dec 11 '14 at 02:00 PM

Hey Davixe,

Syntax for binding delegate looks like

 OnTakeAnyDamage.AddDynamic(this, &MyActor::MyTakeAnyDamage);
 void MyTakeAnyDamage(float Damage, const class UDamageType DamageType, class AController InstigatedBy, AActor* DamageCauser)
 {
 }

TakeDamage it is not delegate, it should be overridden.

Cheers

Gleb

avatar image Davixe Dec 18 '14 at 02:32 PM

Hi, What I want is something like bind a function inside my projectile class, so I can have a lot of different projectiles which have different behaviour, then, execute that behaviour on the TakeDamage, so I can avoid an endless switch case inside the TakeDamage. Can i do that? or I'm asking about magic? xD

thx for the answers :)

avatar image Gleb.Bulgakov Dec 18 '14 at 03:53 PM

Hi,

Yes, for example you can create virtual function in your base projectile class and override it in derived classes to implement specific behavior.

Best regards, Gleb

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question