MFPS 2 & DestroyIt integration

Useful Tutorials.
Post Reply
User avatar
MAC
Contributor
Contributor
Posts: 95
Joined: Sun May 27, 2018 7:59 am
Contact:

Hello,
I share whit you the method for using Destroyit whit MFPS !

From Zangad on Destroyit forum https://forum.unity.com/threads/release ... 22/page-10

Here is a step-by-step guide to using DestroyIt with MFPS 2.0 for multiplayer destruction.

(1) Import MFPS 2.0 Multiplayer FPS
(2) Open the \MFPS\Scenes\ExampleLevel scene
(3) Import Photon PUN 2 (Free)
(4) Login to Photon Cloud, setup a new Photon PUN project, and copy the AppId into the PUN Wizard
(5) Import DestroyIt
(6) From the top menu, choose Window => DestroyIt => Setup - Minimal

(7) From the \DestroyIt\Demos (safe to delete)\Prefabs\Destructible Objects\Pristine folder, drag the Column prefab into the ExampleLevel scene

(8) Select the Column game object in the Hierarchy and choose Add Component => Photon View
(9) Drag the Column game object to the Observed Components field, and check the Synchronize Position and Rotation checkboxes on the Photon Transform View component

(10) Open the \DestroyIt\Scripts\Behaviors\Destructible.cs script and add the [Photon.Pun.PunRPC] attribute to the ApplyDamage method
Destructible.cs

(11) Open the \MFPS\Scripts\Weapon\bl_Bullet.cs script and add the section of code below to the OnHit method
Code (CSharp):

Code: Select all

DestroyIt.Destructible destObj = hit.collider.gameObject.GetComponentInParent<DestroyIt.Destructible>();
if (destObj != null)
{
    PhotonView pv = destObj.GetComponent<PhotonView>();
    pv.RPC("ApplyDamage", RpcTarget.All, damage);
}
bl_Bullet.cs
(12) Save all your changes to the scripts and the ExampleLevel scene

Note: The instructions provided below are if you want to test multiplayer destruction in your scene with another developer. Each developer on your team will need MFPS 2.0 and DestroyIt and have them imported into the project as outlined in steps 1-5 above.

(13) Export your changes into an asset package. Use CTRL-click to select the ExampleLevel scene and the two scripts you modified, right-click and choose Export Package. Uncheck Include Dependencies so only the modified files are included.
(14) Have your developer friend delete his/her ExampleLevel scene, and import your package so you are both running the same code.
(15) Run the scene, and have your friend also run the scene on their computer. Note that they will also need to use the same Photon AppId as you.
(16) From the in-game menu, create a new server and Join. Your friend should join the other side. Now when either of you damage or destroy the destructible column with a bullet, you will each see progressive damage and the particle effect.



From here, you could expand your damage checking to knife cuts or grenades/molotov cocktails, so those also damage DestroyIt destructible objects. You could also try using a more advanced destructible object, one that has damage effects like smoke or sparks, or one that leaves persistent debris from a destroyed prefab. In the case of persistent debris, you might want to make the debris pieces observable to Photon by adding Photon View components to each of them and syncing the position/rotation. Or you might decide that you like persistent debris but don't want to worry about syncing each piece with all clients, to save network traffic. It really depends on if the position of each piece of debris is important to track in you game or not. If flying debris can damage players, block movement (ie, a cave collapse), or provide cover, then you probably want to track its position/rotation for all clients.

///////////////////////////////////////////////////////////////////////////

And for reloading the object destroyed on the reload of the scene you need this one :

///////////////////////////////////////////////////////////////////////////

What is used to reset the scene is bl_RoomSettings.ResetRoom(). The way it is setup, though, it only resets player and score data for PUN - it doesn't actually reload the scene. That's why the destructible objects are never reset. Not reloading the scene means your levels can only ever have static (non-modifiable) objects in them. Optionally, you could programmatically add the objects to your scene, but that would be fairly tedious and require more programming.

However, I found a place where you can reload the scene that seems to work: right before resetting the room. Now, I don't know if this is the preferred method for resetting a level in MFPS, but I'll share my changes in the hopes that it will at least get you past where you're stuck.

NOTE: I would advise contacting Lovatto Studio and asking them what is the best way to reload a dynamic (non-static) scene with MFPS 2.0. Be sure to mention that you are removing objects from the scene and need to reload the scene after a match in order to reset everything. They should be able to tell you the best way to do that for their asset.

Having said that, here's what worked for me:

1) Open the bl_RoundTime.cs script. Paste this using statement at the top:
Code (CSharp):

Code: Select all

using UnityEngine.SceneManagement;
2) In bl_RoundTime.cs, scroll down to the FinishGame() method. Look for the line that says "if (RoomSettings)". Change that section of code to this:
Code (CSharp):

Code: Select all

if (RoomSettings)
{
    RoomSettings.ResetRoom();
    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
Essentially, all we are doing is adding the code to reload the scene before it resets the room. But once I did that, things started working. Here a video of me running through the Game Per Round mode and destroying the destructible column a couple of times.

Note : You have pictures and video on the original post will help you to integrate it

https://forum.unity.com/threads/release ... 22/page-10

Enjoy
MFPS on HDRP --) https://ka2studio.net/
User avatar
mycomport
Contributor
Contributor
Posts: 3
Joined: Mon Mar 16, 2020 9:18 am

I'm trying to integrate MFPS2 with DestroyIt - Destruction System 1.10 and got an error "PhotonView with ID 6 has no (non-static) method "ApplyDamage" that takes 1 argument(s)" in Destructible.cs
Link to Tutorial : https://www.lovattostudio.com/en/integr ... -mfps-2-0/

And find discrepancy in tutorial in code.
I have Integer in ApplyDamage, in Tutorial it is Float in \DestroyIt\Scripts\Behaviors\Destructible.cs script

In original Destruction System 1.10 code:
/// <summary>Applies a generic amount of damage, with no specific impact or explosive force.</summary>
[PunRPC]
public void ApplyDamage(int amount)

In Tutorial Screenshot:

/// <summary>Applies a generic amount of damage, with no specific impact or explosive force.</summary>
[PunRPC]
public void ApplyDamage(float amount)
Please help me to fix it, I'm really exiting to using this two systems together.

Thanks!
User avatar
MAC
Contributor
Contributor
Posts: 95
Joined: Sun May 27, 2018 7:59 am
Contact:

This tutorial was made whit Mfps 1.5 version and number of things have change whit 1.6 ..
Did you modified the bl_Bullet.cs ?

(11) Open the \MFPS\Scripts\Weapon\bl_Bullet.cs script and add the section of code below to the OnHit method
Code (CSharp):
CODE: SELECT ALL

DestroyIt.Destructible destObj = hit.collider.gameObject.GetComponentInParent<DestroyIt.Destructible>();
if (destObj != null)
{
PhotonView pv = destObj.GetComponent<PhotonView>();
pv.RPC("ApplyDamage", RpcTarget.All, damage);
}
MFPS on HDRP --) https://ka2studio.net/
User avatar
mycomport
Contributor
Contributor
Posts: 3
Joined: Mon Mar 16, 2020 9:18 am

Using Mfps 1.6, modified bl_Bullet.cs as described,
got an error on Destructible object when hit it: PhotonView with ID 7 has no (non-static) method "ApplyDamage" that takes 1 argument(s).
The MFPS 1.6 its different, I check the code in \DestroyIt\Scripts\Behaviors\Destructible.cs script has ApplyDamage(int amount)
in MFPS its float amount , the question is how to use it now? Thanks!


MAC wrote: Fri Mar 20, 2020 9:57 am This tutorial was made whit Mfps 1.5 version and number of things have change whit 1.6 ..
Did you modified the bl_Bullet.cs ?

(11) Open the \MFPS\Scripts\Weapon\bl_Bullet.cs script and add the section of code below to the OnHit method
Code (CSharp):
CODE: SELECT ALL

DestroyIt.Destructible destObj = hit.collider.gameObject.GetComponentInParent<DestroyIt.Destructible>();
if (destObj != null)
{
PhotonView pv = destObj.GetComponent<PhotonView>();
pv.RPC("ApplyDamage", RpcTarget.All, damage);
}
User avatar
Bondarius
Contributor
Contributor
Posts: 11
Joined: Fri Apr 10, 2020 2:19 am

I recently purchased the DestroyIt asset and I am trying to integrate it now. By following the tutorial I am receiving an error on :
Assets\MFPS\Scripts\Weapon\Projectiles\bl_Bullet.cs(130,54) : error CS0103: The name 'damage' does not exist in the current context.

Any resolution to this?


Edit :

I deleted the 'damage' from the script and there were no errors until play. On play I get an error -> "PhotonView with ID 7 has no (non-static) method "ApplyDamage" that takes 0 argument(s);
User avatar
zangad
New Member
New Member
Posts: 1
Joined: Wed Apr 22, 2020 3:29 pm

It looks like the MFPS code has changed since we provided the tutorial. Please try adding this code instead for the MFPS bl_Bullet.cs script:

MFPS\Scripts\Weapon\Projectiles\bl_Bullet.cs
Image

The only difference is the way bullet damage is referenced. Instead of a float variable called "damage", MFPS now uses a "bulletData" variable with a "Damage" property.
Post Reply