Why is my condition not fulfilled when if ???

Support for MFPS 2.0
Post Reply
User avatar
Maxime66410
New Member
New Member
Posts: 3
Joined: Tue Dec 01, 2020 9:53 am

Hello, I've been blocked for two days now to make the system so that the players win.

Well in fact the conditions work, but not all the time, and if I replace "<=" by ">=" it works except that I do not want it to win the team from the start of the game, since the players do not even have time to join or load.

Image

Video of this bug : https://i.gyazo.com/55a09126b667370e61a ... 4a4c6c.mp4

So I have to put

Code: Select all

bl_GameManager.Instance.GameMatchState == MatchState.Playing to fix the problem
But

Video : https://i.gyazo.com/176166c993ff45ae5d2 ... 13159e.mp4


It work BUT

If the time exceeds what I wrote it doesn't work
Image
Image
Sanchez
User avatar
Leonid_RU
Contributor
Contributor
Posts: 56
Joined: Tue Sep 11, 2018 3:04 am

I confirm that there is such a problem on MFPS v1. 7.5
User avatar
Lovatto
Admin
Admin
Posts: 1585
Joined: Sun Dec 07, 2014 3:18 pm
Contact:

Hmm...
That will be hard for me to debug this since it's a custom modification and there are a few things that concern me about the piece of code that you show me,
instead of trying to figure out what is wrong in your code and I'll provide a better approach for what you are trying to do using the IGameMode interface which provide many useful events.

So basically, you want to detect when they're not more players of Team1 alive or the if match time ends, Team2 win, so:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using ExitGames.Client.Photon;
using Photon.Realtime;
using UnityEngine;
using Photon.Pun;

public class InfectedMode : MonoBehaviour, IGameMode
{

    /// <summary>
    /// 
    /// </summary>
    void Awake()
    {
        if (!PhotonNetwork.IsConnected)
            return;

        Initialize();
    }

    /// <summary>
    /// 
    /// </summary>
    void OnDisable()
    {
        bl_PhotonCallbacks.PlayerPropertiesUpdate -= OnPlayerPropertiesUpdate;
    }


    #region Interface
    public bool isLocalPlayerWinner
    {
        get
        {
            return "No defined";

        }
    }

    public void Initialize()
    {
        //check if this is the game mode of this room
        if (bl_GameManager.Instance.IsGameMode(GameMode.Infected, this))
        {
            bl_GameManager.Instance.SetGameState(MatchState.Starting);
            bl_PhotonCallbacks.PlayerPropertiesUpdate += OnPlayerPropertiesUpdate;
            //show your game mode specif objects

        }
        else
        {
            //hide the game mode objects.
        }
    }

    /// <summary>
    /// This will be called when the round time ends.
    /// </summary>
    /// <param name="gameOver"></param>
    public void OnFinishTime(bool gameOver)
    {
        if (PhotonNetwork.OfflineMode) return;

       if(Team1Alive > 0)
        {
            bl_InfectedUI.Instance.WinValue = true;
            bl_InfectedUI.Instance.WinUI();
            WinnerTeam = Team.Team1;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="target"></param>
    /// <param name="changedProps"></param>
    public void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps)
    {
        //When someone die
        if (changedProps.ContainsKey(PropertiesKeys.KillsKey))
        {
            CheckScore();
        }
    }

    /// <summary>
    /// 
    /// </summary>
    void CheckScore()
    {
        if (Team1Alive <= 0)
        {
            bl_InfectedUI.Instance.WinValue = false;
            bl_InfectedUI.Instance.WinUI();
            WinnerTeam = Team.Team2;
        }
    }

    public void OnRoomPropertiesUpdate(ExitGames.Client.Photon.Hashtable propertiesThatChanged)
    {
    }

    public void OnLocalPlayerDeath()
    {
    }

    public void OnLocalPlayerKill()
    {
    }

    public void OnLocalPoint(int points, Team teamToAddPoint)
    {
        CheckScore();
    }

    public void OnOtherPlayerEnter(Player newPlayer)
    {
    }

    public void OnOtherPlayerLeave(Player otherPlayer)
    {
    }
    #endregion
}
I think the code explain itself, you can use it as reference and merge with your code,
I hope this helps.
User avatar
Maxime66410
New Member
New Member
Posts: 3
Joined: Tue Dec 01, 2020 9:53 am

Lovatto wrote: Thu Dec 03, 2020 9:10 pm Hmm...
That will be hard for me to debug this since it's a custom modification and there are a few things that concern me about the piece of code that you show me,
instead of trying to figure out what is wrong in your code and I'll provide a better approach for what you are trying to do using the IGameMode interface which provide many useful events.

So basically, you want to detect when they're not more players of Team1 alive or the if match time ends, Team2 win, so:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using ExitGames.Client.Photon;
using Photon.Realtime;
using UnityEngine;
using Photon.Pun;

public class InfectedMode : MonoBehaviour, IGameMode
{

    /// <summary>
    /// 
    /// </summary>
    void Awake()
    {
        if (!PhotonNetwork.IsConnected)
            return;

        Initialize();
    }

    /// <summary>
    /// 
    /// </summary>
    void OnDisable()
    {
        bl_PhotonCallbacks.PlayerPropertiesUpdate -= OnPlayerPropertiesUpdate;
    }


    #region Interface
    public bool isLocalPlayerWinner
    {
        get
        {
            return "No defined";

        }
    }

    public void Initialize()
    {
        //check if this is the game mode of this room
        if (bl_GameManager.Instance.IsGameMode(GameMode.Infected, this))
        {
            bl_GameManager.Instance.SetGameState(MatchState.Starting);
            bl_PhotonCallbacks.PlayerPropertiesUpdate += OnPlayerPropertiesUpdate;
            //show your game mode specif objects

        }
        else
        {
            //hide the game mode objects.
        }
    }

    /// <summary>
    /// This will be called when the round time ends.
    /// </summary>
    /// <param name="gameOver"></param>
    public void OnFinishTime(bool gameOver)
    {
        if (PhotonNetwork.OfflineMode) return;

       if(Team1Alive > 0)
        {
            bl_InfectedUI.Instance.WinValue = true;
            bl_InfectedUI.Instance.WinUI();
            WinnerTeam = Team.Team1;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="target"></param>
    /// <param name="changedProps"></param>
    public void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps)
    {
        //When someone die
        if (changedProps.ContainsKey(PropertiesKeys.KillsKey))
        {
            CheckScore();
        }
    }

    /// <summary>
    /// 
    /// </summary>
    void CheckScore()
    {
        if (Team1Alive <= 0)
        {
            bl_InfectedUI.Instance.WinValue = false;
            bl_InfectedUI.Instance.WinUI();
            WinnerTeam = Team.Team2;
        }
    }

    public void OnRoomPropertiesUpdate(ExitGames.Client.Photon.Hashtable propertiesThatChanged)
    {
    }

    public void OnLocalPlayerDeath()
    {
    }

    public void OnLocalPlayerKill()
    {
    }

    public void OnLocalPoint(int points, Team teamToAddPoint)
    {
        CheckScore();
    }

    public void OnOtherPlayerEnter(Player newPlayer)
    {
    }

    public void OnOtherPlayerLeave(Player otherPlayer)
    {
    }
    #endregion
}
I think the code explain itself, you can use it as reference and merge with your code,
I hope this helps.
Hello, last night I managed to sort out this whole problem, thank you again for your help.

Your resolution works too ;)
Sanchez
Post Reply