Multi Player Scripting, Blinking GUI Text

Hello, i would like to ask a few questions. Please help. Thank you Pardon for the poor English and explanation.

  1. Currently, i am working on a game and i name it as “Click Match”.As i am implementing in multiplayer mode, the game will go this way : Player 1 click A, B and form words, so what i want to do is in Player B’s screen, they won’t get to see A, B as this sets are already form by Player A. The sets A, B will be reappearing on the Player B’s screen after some time. How do i go about doing it?? I am using the MasterServer to control everything.

  2. Next, I want to make a blinking guiText, I would like to ask how do I make some guiText to blink awhile and then disappear. It will reappear about like 5seconds later. As i have an array of guiText in the scene, how do i randomly pick one or two guiText to blink at the same time.

  3. Thirdly, i got a main character walking around the scene. So when the main character go near the door or click on the door, i want it to trigger a scene, they need to finish the quest in order to open the door. Any ideas how could i get started with it.

  4. Lastly, i have an empty gameObject with all the scripts attached to it. I want to destroy it if “something = true”, how can i go about it.

var onoff		= false;
var Games         : GameObject;
if(!MenuScript.onoff)
{
      Destroy(Games);	
}

I tried doing this way, but it doesn’t seem to work properly.

Thank you :slight_smile:

  1. Master server can’t control anything in your game. It’s only a proxy to be able to connect players to a game.
    Use RPC calls to execute commands on the other players.
  2. Create an array containing the GuiText’s and use a random pattern to select one or more and then execute a ‘blink’ script.
  3. There are different ways to handle that, polish your programming skills ( if…switch (case)…)
  4. The script looks ok but you start of with the boolean to false, meaning instantly destroying the object.
    You also don’t show in what function the code gets executed.
    Try to debug your scripts, you will need to do that alot during programming.

GameSetup.js

var playerPref 			: Transform;
var gameName 			: String = "Chinese games";
var chatScript 			: FPSChat;
var gameScript 			: gameControl;

//Server-only playerlist
public var playerList 	= new ArrayList();

class FPSPlayerNode 
{
	var playerName 		: String;
	var networkPlayer 	: NetworkPlayer;
	
	//var kills 				: int =0;
	//var deaths 				: int =0;	
	var score				: int = 0;
}

function Awake() 
{
	playerName = PlayerPrefs.GetString("playerName");
	
	chatScript = GetComponent(FPSChat);
	//gameScript = GetComponent(gameControl);
	Network.isMessageQueueRunning = true;
	//Screen.lockCursor=true;	
	
	if(Network.isServer)
	{
		chatScript.ShowChatWindow();
		
		//RPCMode is set to AllBuffered, so everyone gets this RPC. And since it’s buffered, that means that anyone joining at a *later* time will also get this RPC called as soon as they join the server.
		networkView.RPC ("TellOurName", RPCMode.AllBuffered, playerName);
		networkView.RPC("ApplyGlobalScore", RPCMode.AllBuffered,playerName, score);
		//print("Score at Gamesetup: " + score);
		//print("PlayerName at Gamesetup: " + playerName);
		
		for (var go : GameObject in FindObjectsOfType(GameObject))
		{
			go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);	
		}	
		
		MasterServer.RegisterHost(gameName, PlayerPrefs.GetString("playerName")+" 's game");
			
	}
	else if(Network.isClient)
	{
		
		networkView.RPC ("TellOurName", RPCMode.AllBuffered, playerName);
		networkView.RPC("ApplyGlobalScore", RPCMode.AllBuffered, playerName,score);
		chatScript.ShowChatWindow();
		
		for (var go : GameObject in FindObjectsOfType(GameObject))
		{
			go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);	
		}	
		
	}
	else
	{
		//How did we even get here without connection?
		Screen.lockCursor=false;	
		Application.LoadLevel((Application.loadedLevel-1));	
		
	}
}

//Server function
function OnPlayerDisconnected(player: NetworkPlayer) 
{
	Network.RemoveRPCs(player, 0);
	Network.DestroyPlayerObjects(player);
	
	//Remove player from the server list
	for(var entry : FPSPlayerNode in  playerList)
	{
		if(entry.networkPlayer==player)
		{
			chatScript.addGameChatMessage(entry.playerName+" disconnected from: " + player.ipAddress+":" + player.port);
			playerList.Remove(entry);
			break;
		}
	}
}

//Server function
function OnPlayerConnected(player: NetworkPlayer) 
{
	chatScript.addGameChatMessage("Player connected from: " + player.ipAddress +":" + player.port);
}

@RPC
//Sent by newly connected clients, received by server
function TellOurName(name : String, info : NetworkMessageInfo)
{
	var netPlayer : NetworkPlayer = info.sender;
	
	if(netPlayer+""=="-1")
	{
		//This hack is required to fix the local players networkplayer when the RPC is sent to itself.
		netPlayer=Network.player;
	}
	
	var newEntry : FPSPlayerNode = new FPSPlayerNode();
	
	newEntry.playerName=name;
	newEntry.networkPlayer=netPlayer;
	//newEntry.score = ParseInt(score);
	print("playerName:" + name + "score:" + score);
	playerList.Add(newEntry);
	
	if(Network.isServer)
	{
		chatScript.addGameChatMessage(name+" joined the game");
	}
}

//Called via Awake()
/*function OnNetworkLoadedLevel()
{
	// Randomize starting location
	var spawnpoints : GameObject[] = GameObject.FindGameObjectsWithTag ("Spawnpoint");
	Debug.Log("spawns: "+spawnpoints.length);
	
	var spawnpoint : Transform = spawnpoints[Random.Range(0, spawnpoints.length)].transform;
	var newTrans : Transform = Network.Instantiate(playerPref,spawnpoint.position, spawnpoint.rotation, 0);
}*/


function OnDisconnectedFromServer () 
{
	//Load main menu
	Screen.lockCursor=false;
	//Application.LoadLevel((Application.loadedLevel-1));

}

@RPC
function ApplyGlobalScore(name:String, newscore : int)
{

	var entry : FPSPlayerNode = new FPSPlayerNode();
	entry.playerName = name;
	entry.score = newscore;
	print("score:" + newscore);
}

// scoreBoard.

private var displayingHighscore 		: boolean = false;
private var highscoreText 				: GUIText;

private var playerName 					: String = "";
private var score							: int;

private var scoreText 						: String = "Loading scores";

private var hidestats 						: boolean = true;
private var scoreBoardHeight 			: int = 70;
private var gameSetupScript 			: GameSetup;

function Awake()
{
	gameSetupScript = GetComponent(GameSetup);
	
	//highscoreText = GetComponent(GUIText);
	//highscoreText.enabled=false;
	playerName			= PlayerPrefs.GetString("playerName");
}

function OnGUI () 
{
	GUI.skin = skin;

	scoreText = "Scoreboard:\n";
	
	for(var entry : FPSPlayerNode in  gameSetupScript.playerList)
	{
		scoreText += entry.playerName+" \t"+ score+" score \n";	
		print(scoreText);
	}

	GUILayout.BeginArea (Rect ((Screen.width-185),6,175,scoreBoardHeight));
	GUILayout.Box(scoreText);
	GUILayout.EndArea ();
}


function LocalPlayerHasKilled()
{
	var kills 			: int =0;
	var score 		: int =0;
	
	for (var playerInstance : FPSPlayerNode in gameSetupScript.playerList) 
	{
		if (Network.player == playerInstance.networkPlayer) 
		{
			//kills 	= playerInstance.kills;
			score = playerInstance.score;
			
			break;
		}
	}
	
	kills++;
	
	//Overwrite the data of other players with the new correct score
	networkView.RPC("UpdateScore",RPCMode.All, Network.player, score); 
}

function LocalPlayerDied()
{
	var kills 		: int = 0;
	var deaths : int = 0;
	var score	: int = 0;
	
	for (var playerInstance : FPSPlayerNode in gameSetupScript.playerList) 
	{
		if (Network.player == playerInstance.networkPlayer) 
		{
			//kills = playerInstance.kills;
			score = playerInstance.score;
			//print("score at SB:" + playerInstance.score);
			//print("i am inside localPlayerDied");
			break;
		}
	}	
	//deaths++;
	
	//Overwrite with new correct score
	//RPCMode.All -> RPC call on everyone who is connected to the server but did not tell him to buffer the call for clients which connect later
	networkView.RPC("UpdateScore",RPCMode.All, Network.player,score); 
}

@RPC
function UpdateScore(player : NetworkPlayer,score : int)
{
	Debug.Log((Network.player==player)+"= local "+ score + "score");
	
	var found : boolean = false;
	
	for (var playerInstance : FPSPlayerNode in gameSetupScript.playerList) 
	{
		if (player == playerInstance.networkPlayer) 
		{
			//playerInstance.kills=kills;
			playerInstance.score = score;
			found=true;
			break;			
		}
	}	
	
	if(!found)
	{
		Debug.LogError("Could not find network player "+player+" in the gamesetup playerlist!");
	}
	scoreBoardHeight = gameSetupScript.playerList.Count*15+40;		
}

Basically i want to update the score at scoreBoard, but it seem that it doesn’t work properly. Have been trying this for quite some time but it still doesn’t work, please help. The script i got it from M2H networking example 4.

bump