heya guys im making a fps multiplayer game and so when a player kills another I have it set up to where the scoreboard I have adds a point to that player saying he died. However, I don't know how I would add a point for a kill?? Please help guys? the killing is done via raycasting...
No, because it was actually meant as a joke. To be honest, I don't quite understand what the question is. You need to provide more information about what's giving you trouble.
I want to add a score to a scoreboard when I kill another person across network. I already have a way to do this with death, just need one for kill.
So, where's the problem? You need to add a score, so just add the score, like 1 or 10 or 100? If adding is not the problem, what is?
how are you handling the "do damage to the thing you hit"? if you need to know "who killed me" just pass the "damage dealing object" as a parameter in the script, so you can do "my death count +1" "damage dealing object kill count + 1" in the "on death" section of your code.
yea ok ill try to process that @LeftyRight and @ I have a damage system by giving a int of damage. If the player receives the int and is <= 0 then he dies, how would I know WHO killed him?
heres my health script Code (JavaScript): public class FreddyHealth extends Photon.MonoBehaviour { var freddyhealth : int = 100; var scream : AudioClip; var FreddySpot : Transform; @RPC function ApplyFreddyDamage(damage : int) { freddyhealth -= damage; if( freddyhealth <= 0){ FreddyDie(); } } function FreddyDie() { if( photonView.isMine ) { if( gameObject.tag == "Freddy" ) { GameObject.Find("Score").SendMessage("FreddyDeath"); PhotonNetwork.Instantiate("FREDDYDEAD", FreddySpot.transform.position, FreddySpot.transform.rotation, 0); PhotonNetwork.Destroy(gameObject); } } } }
I think he is saying to add in your "ApplyFreddyDamage" method a second parameter such as a reference to the player that is dealing the damage and store it in a variable such as "lastPersonToHitMe". Then in FreddyDie, you get the lastpersontohitme variable and add a point to his score.
as @HiddenMonk says, at the moment you have a single parameter, the amount of damage done. Your problem is that when "freddy" dies, you need to know what did that damage. Solution, add a parameter to pass that information along. So instead of "do 5 damage" you say "do 5 damage from BigMeanie", you can then use that parameter when you need to say "BigMeanie scored a kill". Yes, gameobject, or whatever you base "unit"/"entity" class is if you have something specific setup.
its not fullcode, but Code (csharp): function ApplyFreddyDamage(damage : int, damager : GameObject) { ... FreddieDie(damager); ... } function FreddyDie(damager : GameObject) { ... GameObject.Find("Score").SendMessage("FreddyDeath", damager); ... }
oh ok. When I try to hit him, nothing happens, also this is the code another player has to inflict damage on him, what would I need to add in the parameters for this RPC to affect the 'ApplyFreddyDamage' function Above ^ :: Code (JavaScript): if (hit.transform.tag == "Freddy") { var targetID = hit.collider.gameObject.GetComponent(PhotonView); targetID.photonView.RPC("ApplyFreddyDamage", PhotonTargets.AllBuffered, damage); }
Hey Lefty, just add a counter in the if statement that checks if his health is 0. So.... Code (CSharp): function ApplyFreddyDamage(damage : int) { freddyhealth -= damage; if( freddyhealth <= 0){ //new varible here that increments everytime freddy has less than zero hp freddyScore ++; FreddyDie(); } Really it is just that simple.
@LeftyRighty I get an exception error saying that the code I use to inflict damage on freddy has only 1 parameter. what do I need to add on the other one.
If youre using leftys example then you need to add a gameobject parameter (the gameobject that is shooting). Then you know what gameobject did the kill, however, maybe you would prefer to pass a NetworkViewId parameter instead. All we have really done is give you an idea of how you could know who killed who. How you assign the points is really up to how you have things set up. In your freddydie method you would probably send another message to the scoreboard telling it to add a point to the owner of the networkid or gameobject. Im not sure if you are a beginner, but if you are, multiplayer might not be a great starting point. I have yet to touch multiplayer stuff. Its just an extra overhead to the code design you are doing, which might be confusing for a beginner.
RPC's don't take Transforms or Gameobjects by default. Try giving your Damage function an additional parameter (int) and set it to the PhotonView.UserID of the attacker. Then let the defender (the one executing the Damage function) run a PhotonView.Find() and pass along the ID as such: void ExampleShoot () { defender.transform.GetComponent<PhotonView>().RPC("ExampleDamage", PhotonTargets.All, damage, attacker.GetComponent<PhotonView>().viewID); } [PunRPC] public void ExampleDamage (float damage, int attackerID) { if ((Health - damage) <= 0) { Transform attacker= PhotonView.Find(attackerID).transform; attacker.Kills++; defender.Deaths++; //Respawn } else { Health -= damage; } }
You need to resolve who did the damage, we do it like this in our game Code (CSharp): public class NetworkedFirearm : NetworkTrackedObject, IRequireInitialSync { protected bool ApplyDamage(ulong avatarId, int hitZoneId, float damage, Vector3 point) { var hitZone = GetHitZone(avatarId, hitZoneId); hitZone.RegisterHit(OwnerId, LocalFirearm.BloodOnImpactPrefab, LocalFirearm.FlashPoint.transform.forward, point, LocalFirearm.FlashPoint.transform.rotation, damage); return hitZone.Avatar.Health < 0.01f; } Basicly we supply the RegisterHit method with the OwnerId of the firearm who did the damage. Anyway further down the chain this publishes a event Code (CSharp): EventBus.Instance.Publish(new PlayerKilled(killerId, OwnerId, shouldAffectScore)); This is picked up by the Scoring system and updates score accordingly