Page 1 of 1

Why is my condition not fulfilled when if ???

Posted: Thu Dec 03, 2020 7:16 am
by Maxime66410
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

Re: Why is my condition not fulfilled when if ???

Posted: Thu Dec 03, 2020 11:02 am
by Leonid_RU
I confirm that there is such a problem on MFPS v1. 7.5

Re: Why is my condition not fulfilled when if ???

Posted: Thu Dec 03, 2020 9:10 pm
by Lovatto
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.

Re: Why is my condition not fulfilled when if ???

Posted: Fri Dec 04, 2020 1:22 am
by Maxime66410
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 ;)