playMaker

Author Topic: PUN 2: How to take and receive damage?  (Read 1131 times)

paradiseprime

  • Full Member
  • ***
  • Posts: 105
PUN 2: How to take and receive damage?
« on: October 08, 2021, 07:16:25 AM »
Damage is sent by making a "Hit Detection Module" every time an attack starts and when a trigger event happens, it will send an event to the target that is parented to that Hit Detection Module. The attack information is sent over to it and then that information is sent to the player then the Module is destroyed to prevent multi-trigger situations.

Animations are synced now but nothing is actually happening between the 2 players.

Wpx13

  • Playmaker Newbie
  • *
  • Posts: 7
Re: PUN 2: How to take and receive damage?
« Reply #1 on: October 08, 2021, 10:08:46 AM »
1- add health manager fsm to the player object
2- make the player sends RPC event to the hited object with the the damage as string data
3- make a state in the health manager call it damage receiver make the shooter ( the player who wants to send the damage ) send an event and then damage receiver ( the damaged player ) can do float\int add as the event data he received and

that's it sry about bad english btw

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Re: PUN 2: How to take and receive damage?
« Reply #2 on: October 08, 2021, 04:45:42 PM »
1- add health manager fsm to the player object
2- make the player sends RPC event to the hited object with the the damage as string data
3- make a state in the health manager call it damage receiver make the shooter ( the player who wants to send the damage ) send an event and then damage receiver ( the damaged player ) can do float\int add as the event data he received and

that's it sry about bad english btw

Thank you for the answer. I managed to get half of it working. The sending part works. The receiving part on the other hand doesnt. I have an Get Event Info on the receiving end and it just gets the Main Camera for some reason whenever I attack.

Is there some way to get the sender's info?

Microck

  • Playmaker Newbie
  • *
  • Posts: 22
Re: PUN 2: How to take and receive damage?
« Reply #3 on: October 09, 2021, 07:44:57 AM »
Hi !
All you have to do is "build string" with all the data you want to send (player name, damage,...). Use a separator like "/".
Then call an RPC with the data string.

After the Get Event info, if the string contains multiple data, make sure to use "String split" action with the same separator ("/") and array get action for each string data (index 1, 2 ,3... depending of how many data you're sending. Let's say you have 2 data, you should use array get two times, the 1st array get index 0, 2nd array get index 1...).
« Last Edit: October 09, 2021, 12:25:30 PM by Microck »

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Re: PUN 2: How to take and receive damage?
« Reply #4 on: October 09, 2021, 11:30:16 PM »
Hi !
All you have to do is "build string" with all the data you want to send (player name, damage,...). Use a separator like "/".
Then call an RPC with the data string.

After the Get Event info, if the string contains multiple data, make sure to use "String split" action with the same separator ("/") and array get action for each string data (index 1, 2 ,3... depending of how many data you're sending. Let's say you have 2 data, you should use array get two times, the 1st array get index 0, 2nd array get index 1...).

I still am not able to get it. I dont full understand RPC events also.

In theory, the process should be straight forward for how I have my combat setup.

1. Press the attack button, do a sphere cast in a small radius around the player and store every player that is inside the spherecast in an Array. Send an event to all players inside the cast and have them create a "Damage Module" that will be parented to them.

2. Play the attack and have a trigger event on the weapon. Any enemy hit will have an event sent to their spawned "Damage Module".

3. "Damage Module" will get the sender and get the info for the attack from the weapon. Info like Hit animation/Hit distance/Damage/ect. The info will be used then the object is destroyed to prevent constant use.


I cycle through the items in the array and send an RPC event to each of them to spawn a "Hit Module". - This works fine.

I get the collider for the player hit and then send an RPC event to the "Hit Module" attached to it. I perform a check to see if the target hit is the same as the target I am sending the event too since I am sending the event to ALL players.

The issue comes up when I try to send an event to the player I hit on my side of the network but what I am hitting is a clone of the player so it gets the clone name so when the global event attempts to check the string name, it fails because the clone and the real player share different names.

TLDR: I need to figure out how to detect the ACTUAL player that is getting hit and use the clone of that player as a proxy to get to the ACTUAL player's Damage FSM so I can send the event and the Game Object Compare can pass.

If I cannot use game objects to make the comparison then what can I use that both the CLONE Player and the REAL Player can share that is unique only to them?

Wpx13

  • Playmaker Newbie
  • *
  • Posts: 7
Re: PUN 2: How to take and receive damage?
« Reply #5 on: October 10, 2021, 12:33:58 AM »
can you show use your Fsm's? so we can find the issuse  ;D

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: PUN 2: How to take and receive damage?
« Reply #6 on: October 10, 2021, 01:47:59 PM »
The unique identifier on your target that is shared between all instances on the network is the PhotonView ID. I don't see any other way of comparing the local and remote versions of your target.

But it seems like you're already doing that on your "Hit Module".

Wpx13

  • Playmaker Newbie
  • *
  • Posts: 7
Re: PUN 2: How to take and receive damage?
« Reply #7 on: October 12, 2021, 09:29:54 AM »
also when you make a rpc with string data maybe you will face this error

i don't know why is this happens