Kill list

Hello, I need to my multiplayer game that if someone kills someone and it shows in the GUI. I would like to make it look like this: Player (player name) the weapon you figure someone killed Player2 (name of player who is now dead). Please help me.

hmm it will be a long process from wat u have now… the script u have now is basically creating a server with a player name and let someone join it.

right now u r getting the player name but u r not sending it to each client or not even to the server…

one method is when ever the player joins, u can send the player name to the server. in the server save all player name in an array. And from the server dispose a RPC message to all clients if someone gets killed. This method should suit u if u control most part of the game in server.

jus try using Scripting reference in unity for further details, it is really easy in unity to create a multiplayer game.

this would come handy for u Unity - Scripting API: NetworkView.RPC

If u are beginner try using leepo’s tutorial for networking http://forum.unity3d.com/threads/29015-UniKnowledge-entry-Unity-Networking-the-Zero-to-Hero-guide

8-):razz:

That helped me a lot. I have no money after I bought the project. A tutorial in pdf not is here. Should anyone have any free project or tutorial? Please I need it very

Unity has a network example… http://unity3d.com/support/resources/example-projects/networking-example

Should get you going with their exanple project and tutorial

In this project isn’t kill list.

In my script is the name so let’s name shows up when someone kills someone. Whether there is a player’s name and name of the second player who killed himself.

Help please

hope the following will help u :slight_smile:

//add this on player prefab that gets spawned in network....

//note that the player prefab should have a networkview component attached (component->misc.  -> networkView)
var playerIndex:int=0;                 //index of the player on the network...this will be easy to access his details
var playerName:String="";             // hope u r getting this using OnGUI function whn ever the player connects or creates the server.

var AllPlayerNames:String[]=new String[16];    // I jus assumed that the max number of players is 16 change it according to ur needs...

var GunTextures:Texture[]=new Textures[x];    /// replace x with number of guns and also link the image  of the guns in the editor


//the below are the data needed for displaying the kill message... if u need to display more than one, declare the below 5 var as arrays and handle it....

var bBroadCastMsg:boolean=false;
var broadcastKillerIndex:int;
var broadcastDeadIndex:int;
var broadcastGunIndex:int;
var broadcastStartTime;

 // add the amount of time it  has to be displayed in editor or change it here itslef..
var broadcastDuration:float=3;   


function OnConnectedToServer()   //the name explains it all
{

	playerIndex=int.Parse(Network.player.ToString());	
	networkView.RPC("SetName",RPCMode.AllBuffered,playerIndex,playerName);   // this will sent the name to all the peers connected and will connect in future..
	
}



// this thing will set the player name u get to all the peers of the game including server..
@RPC
function SetName(index:int,name:String)
{
	AllPlayerNames[index]=name;
}




function OnPlayerKill(){          // this is a user defined function   u shd take care of callin it whn the player gets a kill ... or u can call it whn a player gets  killed  . all depens on u

// hope u should be having some method to detect who was the killer and who got killed.... u have to send it to the function below...also send the number of gun that has to be displayed in the screen
// i dont know wat method u used to check who killed who so the parameters for this shd be passed by u..


	networkView.RPC("broadCastKillMessage",RPCMode.All,playerIndex,IndexOfPlayerKilled,GunIndex);

}


@RPC
function broadCastKillMessage(killerIndex:int,deadIndex:int,gunIndex:int)
{
	bBroadCastMsg=true;
	broadcastKillerIndex=killerIndex;
	broadcastDeadIndex=deadIndex;
	broadcastGunIndex=gunIndex;
}


function OnGUI()
{
	if(bBroadCastMsg)
	{
		//this will display wat u have asked for ... u have to fill the Rect(,,,) though = /
		
		GUI.Label(Rect(),AllPlayerNames[broadcastKillerIndex]);        //displays the player name...
		GUI.Label(Rect(),GunTextures[broadcastGunIndex]);			  //displays the gun image...
		GUI.Label(Rect(),AllPlayerNames[broadcastDeadIndex]);		  //displays the deadPlayer name...
	}
}



//if u want the kill message to be hidden after some time  add the following too...

function Update()
{
	if(Time.time-broadcastStartTime>broadcastDuration)
	{
		bBroadCastMsg=false;
	}
}

i might have done some mistakes too coz i didnt check it, so please pm me if u find something is a mistake here…

regarding the tutorial … have a look at leepo’s networking guide, the link for download is here http://www.megaupload.com/?d=M32UE5ZW

¨flamy your script have some errors and don’t working

please help

wat errors?

btw it wont work independently i made it such a way u can integrate it with ur code…

Assets/Kill score.js(9,31): BCE0018: The name ‘Textures’ does not denote a valid type (‘not found’). This is error.I do not know what it means

ah my bad its a typo change it to Texture

Now say this: Assets/Kill score.js(50,72): BCE0005: Unknown identifier: ‘IndexOfPlayerKilled’.
and Assets/Kill score.js(50,92): BCE0005: Unknown identifier: ‘GunIndex’.

those are the variables that u have to pass since i dont know ur code i wrote it tht way …

guess i mentioned this as a comment in tht script…

“IndexOfPlayerKilled” the index of the player who got killed… “GunIndex” the index of the gun used by the player to kill him…

So how do get rid of error?

hmm can u post the code that checks when the player is dead?!.. i want to know how ur checking for the death condition…

I use the script from FPS Tutorial. FPSPlayer

var maximumHitPoints = 100.0;
var hitPoints = 100.0;

var bulletGUI : GUIText;
var rocketGUI : DrawRockets;
var healthGUI : GUITexture;

var walkSounds : AudioClip[];
var painLittle : AudioClip;
var painBig : AudioClip;
var die : AudioClip;
var audioStepLength = 0.3;

private var machineGun : MachineGun;
private var rocketLauncher : RocketLauncher;
private var healthGUIWidth = 0.0;
private var gotHitTimer = -1.0;

var rocketTextures : Texture[];

function Awake () {
	machineGun = GetComponentInChildren(MachineGun);
	rocketLauncher = GetComponentInChildren(RocketLauncher);
	
	PlayStepSounds();

	healthGUIWidth = healthGUI.pixelInset.width;
}

function ApplyDamage (damage : float) {
	if (hitPoints < 0.0)
		return;

	// Apply damage
	hitPoints -= damage;

	// Play pain sound when getting hit - but don't play so often
	if (Time.time > gotHitTimer  painBig  painLittle) {
		// Play a big pain sound
		if (hitPoints < maximumHitPoints * 0.2 || damage > 20) {
			audio.PlayOneShot(painBig, 1.0 / audio.volume);
			gotHitTimer = Time.time + Random.Range(painBig.length * 2, painBig.length * 3);
		} else {
			// Play a small pain sound
			audio.PlayOneShot(painLittle, 1.0 / audio.volume);
			gotHitTimer = Time.time + Random.Range(painLittle.length * 2, painLittle.length * 3);
		}
	}

	// Are we dead?
	if (hitPoints < 0.0)
		Die();
}

function Die () {
	if (die)
		AudioSource.PlayClipAtPoint(die, transform.position);
	
	// Disable all script behaviours (Essentially deactivating player control)
	var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
	for (var b in coms) {
		var p : MonoBehaviour = b as MonoBehaviour;
		if (p)
			p.enabled = false;
	}

	LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.red, 2.0);
}

function LateUpdate () {
	// Update gui every frame
	// We do this in late update to make sure machine guns etc. were already executed
	UpdateGUI();
}

function PlayStepSounds () {
	var controller : CharacterController = GetComponent(CharacterController);

	while (true) {
		if (controller.isGrounded  controller.velocity.magnitude > 0.3) {
			audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
			audio.Play();
			yield WaitForSeconds(audioStepLength);
		} else {
			yield;
		}
	}
}


function UpdateGUI () {
	// Update health gui
	// The health gui is rendered using a overlay texture which is scaled down based on health
	// - Calculate fraction of how much health we have left (0...1)
	var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);

	// - Adjust maximum pixel inset based on it
	healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;

	// Update machine gun gui
	// Machine gun gui is simply drawn with a bullet counter text
	if (machineGun) {
		bulletGUI.text = machineGun.GetBulletsLeft().ToString();
	}
	
	// Update rocket gui
	// This is changed from the tutorial PDF. You need to assign the 20 Rocket textures found in the GUI/Rockets folder
	// to the RocketTextures property.
	if (rocketLauncher)	{
		rocketGUI.UpdateRockets(rocketLauncher.ammoCount);
		/*if (rocketTextures.Length == 0) {
			Debug.LogError ("The tutorial was changed with Unity 2.0 - You need to assign the 20 Rocket textures found in the GUI/Rockets folder to the RocketTextures property.");
		} else {
			rocketGUI.texture = rocketTextures[rocketLauncher.ammoCount];
		}*/
	}
}

Can you help?