Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


menyo

Member Since 09 May 2010
Offline Last Active Feb 17 2015 07:47 AM

Posts I've Made

In Topic: first players problem with 1vs1 network game.

22 January 2015 - 01:11 AM

Can you give me an example of what your definition of friend discovery? I mean how should this work? Just a button to post on your wall?

In Topic: first players problem with 1vs1 network game.

21 January 2015 - 08:52 AM

It is a basic turn based board game. Adding AI is going to be problematic, it will take a ton of code to make it interesting and even then it is probably easy to beat it once you get to know the pattern.

Yeah I need to implement google play services and Facebook sdk so people can find eachother more easy.

In Topic: Turn based multiplayer game

19 January 2015 - 09:32 AM

So with the knowledge gained above I started fiddling around and am wondering if this is a proper way of doing it. The server player and the client can in turn press a button that get registered by the server. It possibly also works with many clients but not tested that yet. Everything coded within the if (myTurn) statement is only executed when it really is the clients turn. Everything outside still works.

 

Still wondering if this is a good approach. Would love to have some feedback.

	//server fields
	private NetworkPlayer player;
	private NetworkPlayer[] playerPool;
	private int currentPlayer;

	//player fields
	private bool myTurn = false;


	// Use this for initialization
	void Start () {
		player = Network.player;

		if (Network.isServer)
		{
			playerPool = new NetworkPlayer[Network.connections.GetLength(0) + 1];
			playerPool[0] = player; //Adds server player to the pool
			//Put all clients in the pool
			for (int i = 0; i < Network.connections.GetLength(0); i++)
			{
				playerPool[i + 1] = Network.connections[i];
			}
			//give someone the first turn
			currentPlayer = Random.Range(0, playerPool.GetLength(0) - 1);
			networkView.RPC("GiveTurn", RPCMode.All, playerPool[currentPlayer]);

			//list players in pool
			foreach (NetworkPlayer p in playerPool)
			{
				Debug.Log("Player (" + p.ToString() + ") added to pool");
			}
		}
	}

	void Update () 
	{
		if (myTurn)
		{
			if (Input.GetMouseButtonDown(0))
			{
				if (Network.isServer)
				{
					EndTurn();
					myTurn = false;
				}
				else
				{
					networkView.RPC("EndTurn", RPCMode.Server);
					myTurn = false;
				}
			}
		}
	}

	[RPC]
	private void GiveTurn(NetworkPlayer player)
	{
		if (Network.player.ToString() == player.ToString())
			myTurn = true;
		Debug.Log("Player (" + player.ToString() + ") is ready to act.");
	}

	[RPC]
	private void EndTurn(NetworkMessageInfo info)
	{
		Debug.Log("Player (" + info.sender.ToString() + ") ended his turn.");
		currentPlayer++;
		if (currentPlayer >= playerPool.GetLength(0))
			currentPlayer = 0;
		Debug.Log(currentPlayer + ", " + playerPool.GetLength(0));
		networkView.RPC("GiveTurn", RPCMode.All, playerPool[currentPlayer]);
		
	}
	private void EndTurn()
	{
		Debug.Log("Player (" + Network.player.ToString() + ") ended his turn.");
		currentPlayer++;
		if (currentPlayer >= playerPool.GetLength(0))
			currentPlayer = 0;
		networkView.RPC("GiveTurn", RPCMode.All, playerPool[currentPlayer]);
	}

In Topic: Turn based multiplayer game

19 January 2015 - 07:28 AM

Thanks Ashaman,

 

But the problem is the player that creates the server is actually the server and not a client. Or am I missing something here? I have looked into creating a server on the MaterServer and then joining the player that created it to it but without success. I know I am not understanding the concept completely, trying to get there.

 

 

//I am actually getting somehwere. Using RCP i found out that the server player is NetworkPlayer.toString() == -1 and the other connected player is NetworkPlayer.toString() == 1.

 

I think i got it. What the problem is with the Network system of unity is that a player that creates the server has to act differently. This is not documented anywhere. I just created a test that finally seems to do what I want.

if (Input.GetMouseButtonDown(0))
{
	if (Network.isServer)
	{
		SentMouseClick(Input.mousePosition); //Do not sent a RPC call otherwise the NetworkPlayer will be -1 and not identical to the "server player" on the network.
	}
	else
	{
		networkView.RPC("SentMouseClick", RPCMode.Server, Input.mousePosition);
	}
}

        //Create a function for the clients [RPC] and for the player on the server. This still seems awkward to me
	[RPC]
	private void SentMouseClick(Vector3 v, NetworkMessageInfo info)
	{
		Debug.Log("Player (" + info.sender.ToString() + ") clicked at: " + v);
	}
	private void SentMouseClick(Vector3 v)
	{
		Debug.Log("Player (" + Network.player.ToString() + ") clicked at: " + v);
	}

Now i am wondering with what you mean with a token? But at least i can verify a move from a player on the server and instantiate or alter the scene on the server.


In Topic: Adding item modifiers

12 November 2014 - 02:44 PM

Yeah i noticed, I'm wondering what the power of an Interface exactly is. Why shouldn't i just add a class and implement that when needed?

 

I'm currently expirimenting with a simple class holding all the stats. This class is used in the entity class (player and NPC objects) and in Items. When a item is equipped it adds all it's stats to the player (or NPC if i would ever add that). When it is unequipped it removes these stats.

 

I'm wondering if i should implement Interfaces because of my initial question.

//Should be implemented by weapons
public interface IDamageStat {
    void AddDamage(Entity entity);
    void RemoveDamage(Entity entity);
}


//Should be implemented by rings and necklaces
public Interface IResistanceStats {
    void AddResistance(Entity entity);
    void RemoveResistanceStat(Entity entity);
}


//Etc...

Coding each stat(group) at the appropriate item type. Or just add every stat for each item even if a armor could never alter damage. Design wise i bet using Interfaces is the way to go but this would add a lot of unnecessary implements and coding. Any thoughts?


PARTNERS