Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

FPS Kit | Version 2.0

Discussion in 'Assets and Asset Store' started by NSdesignGames, Oct 2, 2012.

  1. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Thanks, we'll give this a try.

    Do you know how picking up weapons would work online? I don't think there's an example with this kit.
     
  2. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    I've added smoke/flash grenades. Effects are seen on player who is throwing them but effect not seen by network player. I've gone through the code and prefabs and can't seem to find what links this to the "GrenadeExplosion (Remote)" prefabs found in the Detonator folder. I understand I need to have the same effects for remote which I do however facing the problem in which I cannot seem to see where they are linked to the code/prefab in the project.

    Any ideas?
     
  3. midorina

    midorina

    Joined:
    Jun 1, 2012
    Posts:
    131
    Go to Line 377 of the WeaponScript.cs and find

    Code (csharp):
    1. firePoint.LookAt(GetCenterOfScreen());
    Replace it with

    Code (csharp):
    1. Vector3 pos = Camera.main.ScreenToWorldPoint( new Vector3(Screen.width/2, Screen.height/2, Camera.main.nearClipPlane));
    Now find (should be 378 )

    Code (csharp):
    1. instantiatedProjectile = Instantiate (machineGun.bullet, firePoint.position, firePoint.rotation) as Transform;
    Replace with

    Code (csharp):
    1. instantiatedProjectile = Instantiate (machineGun.bullet, pos, firePoint.rotation) as Transform;
    Now repeat for rest of the functions.
     
  4. Steve-of-Construction

    Steve-of-Construction

    Joined:
    Jan 26, 2013
    Posts:
    67
    Smokegrenade works fine here.
    Check if you have added the grenade to the WeaponManager and added the scripts:

    -WeaponScript
    -AmmoDeactivator
    -WeaponSync(Catcher)

    In WeaponScript select GRENADE_LAUNCHER and your projectile-prefab.

    The grenade explosion (remote) can be seen by everyone if the projectile-prefab is ok.
    So if you can see the projectile (grenade) you can see the explosion too.
     
  5. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    This sounds like why it's not working. I am using WarFX Asset for the smoke particle effects. So I'm not actually using the Detonator Prefabs. I know they are linked in someway but that relationship I cannot see. Everything else works.

    What I did was duplicated the grenade and renamed to Smoke and changed the explosion effect to the WarFX smoke prefab. So it shows in all GUI's, ammo reduction works, looks like a normal grenade until explosion then smokes. Even if I simply change the explosion effect on the Grenades to the one I created with WarFX it does everything the same but the smoke is not seen by Remote players.

    Essentially everything is no different then a normal grenade, only a different explosion particle. The fact there are remote explosion prefabs in the Detonator asset folders lead me to believe this is somehow related. I have remote prefabs for the new smoke particles but where to link I don't seem to see it.
     
    Last edited: Apr 27, 2014
  6. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Neat, but I'd suggest lookup up "prepared statements PHP". They'll make your code much safer - I see you're already doing anti SQL injection, but prepared statements will essentially make that "bulletproof" since what they do isn't send a raw string, they basically send a command and list of parameters (that way it's not even remotely possible to bypass the SQL injection)
     
  7. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    Had to remove i was messing with it during the security check and it i didnt upload the corrected format so i will do so shortly.
     
  8. Ingress Design

    Ingress Design

    Joined:
    Apr 23, 2014
    Posts:
    38
    this cool assets
     
  9. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Does anyone know how picking up weapons would work online? If so, could someone explain how?
     
  10. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    I was attempting to add something like this $user_name=mysql_real_escape_string($_POST['name']); which I think you were talking about. I will likely switch to this for the account system.

    My host is crazy lagged right now so I can't work on it atm so I'll post the simple version.

    I'm starting with this then working into a full login and account system that will keep track of a players kills/deaths and show a KDR "kill to death ratio" and then modify the php to show the top 10 KDR ranked players

    Script Name: KDRTopPlayers.cs
    Code (csharp):
    1. //Script: KDRTopPlayers.cs
    2. //Last Modified: 4.27.2014
    3. //Modified By: ThrillKill
    4. //
    5. // </Usage Example> I added this script to __Lobby prefab then modified the values in Unity Inspector
    6. // </Usage Example> Added a button to open the top list and close main menu and vice versa
    7. // </Usage Example> I call the save function in RoomMultiPlayerMenu in IEnumerator Restart() to save only player is top player
    8. // </Usage Example> Additional variables for buttons to show the GUI on / off = bool showTop10 = false;
    9.  
    10. using UnityEngine;
    11. using System.Collections;
    12. using System.Text;
    13. using System.Security;
    14.  
    15.  
    16. public class KDRTopPlayers : MonoBehaviour {
    17.  
    18.     //Database information
    19.     //Change this information in Unity Inspector
    20.     public string secretKey = "123456";
    21.     public string SaveKDRListUrl = "http://your.host.mySQL/saveKDRlist.php?";
    22.     public string LoadKDRListUrl = "http://your.host.mySQL/loadKDRlist.php";
    23.  
    24.     //Holds the KDRList obtained from the mysSQL database
    25.     public string KillList = "";
    26.     //Maximum player name length
    27.     public int maxNameLength = 10; //Change the value to show any limit
    28.     //Currently A Top 10 List.
    29.     public int getResultsLimit = 10; //Change the value to show any limit
    30.    
    31.     // <summary> Loads the KDR list from mySQL database.
    32.     // <Example> Instance: public KDRTopPlayers KDRmySQL;
    33.     // <Example> Initalize in Start Method: KDRmySQL = GetComponent<KDRTopPlayers>();
    34.     // <returns>The KDR list.</returns>
    35.     // Usage Example: StartCoroutine (KDRmySQL.LoadKDRList());
    36.     public IEnumerator LoadKDRList() {
    37.         //Debugging information to see whats happening
    38.         Debug.Log ("Loading the KDR List from the mySQL database");
    39.         // Create instance of WWWForm
    40.         WWWForm kdrForm = new WWWForm();
    41.         //sets the mySQL query to the amount of rows to load
    42.         kdrForm.AddField("limit", getResultsLimit);
    43.         //Creates instance to run the php script to access the mySQL database
    44.         WWW www = new WWW(LoadKDRListUrl, kdrForm);
    45.         yield return www;
    46.        
    47.         if(www.text == "")  { Debug.Log (("Error Loading the KDR list from the mySQL database: " + www.error));}
    48.         else { Debug.Log ("Loaded Successfuly."); KillList = www.text;} //Assigns the loaded information To KillList
    49.     }
    50.    
    51.     // <summary> Saves the KDR list to the mySQL Database
    52.     // <Example> "name" = PhotonNetwork.playerName</Example>
    53.     // <Example> "kills" = PhotonNetwork.player.customProperties["Kills"];
    54.     // <Example> "deaths" = PhotonNetwork.player.customProperties["Deaths"];
    55.     // <Usage Example Instance> public KDRTopPlayers KDRmySQL;
    56.     // <Usage Example Initalize in Start Method> KDRmySQL = GetComponent<KDRTopPlayers>();
    57.     // <Usage Example Set Values> int totalKIlls = (int)PhotonNetwork.player.customProperties["Kills"];
    58.     // <Usage Example Set Values> int totalDeaths = (int)PhotonNetwork.player.customProperties["Deaths"];
    59.     // <Usage Example Save> StartCoroutine (KDRmySQL.SaveKDRList(leadingPlayer, totalKIlls , totalDeaths));
    60.     public IEnumerator SaveKDRList(string name, int kills, int deaths)  {
    61.         string _name = name; // The players name to save
    62.         int _kills = kills; // Total kills to save
    63.         int _deaths = deaths; // Total deaths to save
    64.  
    65.         //Used for security check for authorization to modify database
    66.         string hash = Md5Sum(_name + _kills + _deaths + secretKey).ToLower();
    67.  
    68.         //Assigns the data we want to save
    69.         //Where -> kdrForm.AddField("name" = matching name of value in SQL database
    70.         WWWForm kdrForm = new WWWForm();
    71.         kdrForm.AddField("name",_name); // adds the player name to the form
    72.         kdrForm.AddField("kills",_kills); // adds the kill total to the form
    73.         kdrForm.AddField("deaths",_deaths); // adds the death Total to the form
    74.         kdrForm.AddField("hash",hash); // adds the security hash for Authorization
    75.  
    76.         //Creates instance of WWW to runs the PHP script to save data to mySQL database
    77.         WWW www = new WWW(SaveKDRListUrl, kdrForm);
    78.         Debug.Log ("Processing...");
    79.         yield return www;
    80.        
    81.         if(www.text == "done") { Debug.Log ("Saved Successfully.");}
    82.         else { Debug.Log ("ERROR: Unable to save the kill/death list to the mySQL database");}
    83.     }
    84.  
    85.     /// <summary>
    86.     /// Md5s Security Features
    87.     /// </summary>
    88.     public string Md5Sum(string input) {
    89.         System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
    90.         byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
    91.         byte[] hash = md5.ComputeHash(inputBytes);
    92.        
    93.         StringBuilder sb = new StringBuilder();
    94.         for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("X2"));}
    95.             return sb.ToString();
    96.     }
    97. }
    **** Note: These files are saved to your weburl location. If using a free host and have issues make sure permissions are 0644.

    Script Name:
    Code (csharp):
    1. crossdomain.xml
    2. <?xml version="1.0"?>
    3. <cross-domain-policy>
    4. <allow-access-from domain="*"/>
    5. </cross-domain-policy>
    Script Name: database.php
    In the code below you need to modify all the words in capitals to your personal settings.
    Code (csharp):
    1. <?php
    2.  
    3. $dbName = 'YOURDATABASENAME';
    4. $secretKey = "YOURSECRETKEY";
    5.  
    6. function dbConnect()
    7. {
    8.     global  $dbName;
    9.     global  $secretKey;
    10.  
    11.     $link = mysql_connect('YOURMYSQLHOST', 'YOURDATABASEUSERNAME', 'YOURUSERPASSWORD');
    12.    
    13.     if(!$link)
    14.     {
    15.         fail("Couldn´t connect to database server");
    16.     }
    17.    
    18.     if(!@mysql_select_db($dbName))
    19.     {
    20.         fail("Couldn´t find database $dbName");
    21.     }
    22.    
    23.     return $link;
    24.     }
    25.    
    26. function safe($variable)
    27. {
    28.     $variable = addslashes(trim($variable));
    29.     return $variable;
    30. }
    31.  
    32. function fail($errorMsg)
    33. {
    34.     print $errorMsg;
    35.     exit;
    36. }
    37.  
    38. ?>
    Script Name: getKDRlist.php
    Code (csharp):
    1. <?php
    2. include("database.php");
    3.     $link=dbConnect();
    4.  
    5.     $limit = safe($_POST['limit']);
    6.    
    7.     $query = "SELECT * FROM $dbName . `scores` ORDER by `kills` DESC LIMIT $limit";
    8.  
    9.     $result = mysql_query($query);    
    10.     $my_err = mysql_error();
    11.     if($result === false || $my_err != '')
    12.     {
    13.         echo "
    14.        <pre>
    15.            $my_err <br />
    16.            $query <br />
    17.        </pre>";
    18.         die();
    19.     }
    20.  
    21.     $num_results = mysql_num_rows($result);
    22.  
    23.     for($i = 0; $i < $num_results; $i++)
    24.     {
    25.          $row = mysql_fetch_array($result);
    26.          echo $row['name'] . "\t - \t " . $row['kills'] . "\t - \t " . $row['deaths']. "\n";
    27.     }
    28. ?>
    Script Name: saveKDRlist.php
    Code (csharp):
    1. <?php
    2. include("database.php");
    3.     $link=dbConnect();
    4.  
    5.     $name = safe($_POST['name']);
    6.     $kills = safe($_POST['kills']);
    7.     $deaths = safe($_POST['deaths']);
    8.     $hash = safe($_POST['hash']);
    9.  
    10.     $real_hash = md5($name . $kills . $deaths . $secretKey);
    11.     if($real_hash == $hash)
    12.     {
    13.         $query = "INSERT INTO $dbName .`scores` (`id`, `name`, `kills`, 'deaths') VALUES (NULL, '$name', '$kills', '$deaths');";
    14.         $result = mysql_query($query);    
    15.         $my_err = mysql_error();
    16.         if($result === false || $my_err != '')
    17.         {
    18.             echo "
    19.             <pre>
    20.            $my_err <br />
    21.            $query <br />
    22.             </pre>";
    23.             die();
    24.         }
    25.        
    26.         echo "done";
    27.     }
    28. ?>
     
  11. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    Not the dev but pretty sure this is what your after
    1. AmmoDisplay.cs
    2. WhoKilledWho.cs
     
  12. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    Might notice I had wrong quotes in saveKDRlist.php for fixed below
    Code (csharp):
    1. $query = "INSERT INTO $dbName .`scores` (`id`, `name`, `kills`, `deaths`) VALUES (NULL, '$name', '$kills', '$deaths');";
     
  13. nertworks

    nertworks

    Joined:
    Mar 6, 2014
    Posts:
    21
    Hey ThrillKill,

    You were just awarded 500 cool points by me. Thank you so very much for the advice.
     
  14. Steve-of-Construction

    Steve-of-Construction

    Joined:
    Jan 26, 2013
    Posts:
    67
    1.
    Please help before I'm going mad, cause I'm searching for an error in WhoKilledWho for 2 weeks now:x
    Here's what happens:

    2 Players join team1: A1+B1
    A1 shoots at B1 and can't kill him, everything is ok.

    Now a third player joins team2: A2
    A1 shoots at B1 and B1 dies.
    WkW says that A2 has killed B1 wich is absolutely wrong (and A1 should not be able to kill B1 !).


    I've checked the RoomMultiplayer, PlayerNetworkController, PlayerDamage and HitBox scripts but couldn't figure out why this happens,

    Maybe I'm thinking wrong somewhere? The bullet goes from A1 to B1.
    B1 has disableDamage for A1 so the bullet shouldn't do any damage.
    But instead it gets damage from player A2 (???) and sends killed-notification.

    I've noticed that it only happens if the upper part of the body and the head gets shot, but these are configured correct, just like legs and arms.

    Please help, any ideas would be much appreciated!



    2.
    Another thing that was asked by someone else before but never answered: in large maps the player starts to tremble while aiming.
    This sounds a little bit funny but is very horrible.
    I've got the same problem in every 2048x2048 map.
    Here's a short video what happens
     
  15. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Seriously, you owe it to yourself to look up Prepared Statements in PHP. They're faster than string queries, and also more secure.
    http://mattbango.com/notebook/code/prepared-statements-in-php-and-mysqli/

    EDIT: Also, seriously, look into putting some of that stuff into helper classes. Object-oriented programming was designed for a reason ;)
    For instance I'm designing a login system, one thing I'm doing is encapsulating all of my user data in a User class. The User class also has a static factory function which, given a database connection, queries the database and either returns a User if the given user exists in the database, or returns NULL.

    Something like this:

    Code (csharp):
    1.  
    2. class User
    3. {
    4.     public $UID = 0;
    5.     public $Username = "";
    6.     public $Email = "";
    7.     public $Passkey = "";
    8.  
    9.  
    10.     public $ActivateKey = NULL;
    11.     public $Banned = FALSE;
    12.     public $BanReason = NULL;
    13.     public $Admin = FALSE;
    14.  
    15.  
    16.     public $AccessToken = "";
    17.  
    18.  
    19.     public function __constructor( $UID, $Username, $Email, $Passkey, $ActivateKey, $Banned, $BanReason, $Admin, $AccessToken )
    20.     {
    21.         $this->UID = $UID;
    22.         $this->Username = $Username;
    23.         $this->Email = $Email;
    24.         $this->Passkey = $Passkey;
    25.         $this->ActivateKey = $ActivateKey;
    26.         $this->Banned = $Banned;
    27.         $this->BanReason = $BanReason;
    28.         $this->Admin = $Admin;
    29.         $this->AccessToken = $AccessToken;
    30.     }
    31.  
    32.  
    33.     // Factory method which submits username and password to database
    34.     // Returns a User on success, NULL otherwise
    35.     public static function GetUser( $dbConnection, $username, $passkey )
    36.     {
    37.         $db_logInUserStmnt = getLogInUserStatement( $dbConnection );
    38.  
    39.  
    40.         // [snip] query database for username and password
    41.  
    42.  
    43.         if( $foundUser )
    44.         {
    45.             return new User( $uid, $username, $email, $passkey, $activatekey, $banned, $banreason, $admin, $accessToken );
    46.         }
    47.         else
    48.         {
    49.             return NULL;
    50.         }
    51.     }
    52. }
    53.  
     
    Last edited: Apr 28, 2014
  16. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Does anyone know how to adjust the 3rd person aiming? If a player is looking at another player the aiming is way off. How can I get the player's 3rd person to better match where he's aiming in first person?

    Also, is there a way to add jumping and landing motions while in first person view? Right now the gun or arms don't move and it's unappealing.
     
  17. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    See my solution on page 70
    My solution for jump and run:
    1. WeaponAnimation.cs
    add to the declaration:
    Code (csharp):
    1.  
    2.     public string Run = "Run";
    3.     public string Jump = "Jump";
    4.  
    Add:
    Code (csharp):
    1.  
    2.     public void PlayerRun(){
    3.         animation.Rewind(Run);
    4.         animation.Play(Run);
    5.     }
    6.    
    7.     public void PlayerJump(){
    8.         animation.Rewind(Jump);
    9.         animation.Play(Jump);
    10.     }
    11.  
    12.     public void PlayerIdle(){
    13.         animation.Rewind(Idle);
    14.         animation.Play(Idle);
    15.     }
    16.  
    $wa.jpg

    2. WeaponScript.cs
    add declaration:
    Code (csharp):
    1.  
    2.     private bool isRunning;
    3.     private bool isJumping;
    4.  
    add to InputUpdate()
    Code (csharp):
    1.  
    2.         if(motor.jumping  !isJumping  !aimed){
    3.             isJumping = true;
    4.            
    5.             weaponAnimation.PlayerJump();
    6.         }
    7.         else if(!motor.jumping  isJumping){
    8.             isJumping = false;
    9.             if(motor.Running){
    10.                 weaponAnimation.PlayerRun();
    11.             }
    12.         }
    13.        
    14.         if(motor.Running  (!isRunning || isJumping)){
    15.             isRunning = true;
    16.             if(!motor.IsJumping())
    17.                 weaponAnimation.PlayerRun();
    18.         }
    19.         else if(!motor.Running  isRunning){
    20.             isRunning = false;
    21.             weaponAnimation.Idle();
    22.         }
    23.  
     
    Last edited: Apr 28, 2014
  18. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Last edited: Apr 29, 2014
  19. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Hi Guys
    I've recently posted how to add classes:
    http://forum.unity3d.com/threads/153337-FPS-Kit-Version-2-0/page79
    If you want to add weapon pick-up, there is an issue that after re-spawn player is loosing the new picked weapon. Here is the simple solution to resolve it:
    - Add prefab for pick-up for your scene from "Prefabs\MultiplayerPrefabs\WeaponsForPick" folder. Make sure the weapon for pick-up is not part of your class.
    - Add functions to the RoomMultiplayerMenu.cs:
    Code (csharp):
    1.     public void UpdateWeapon(string oldWeapon, string newWeapon)
    2.     {
    3.         Debug.Log(oldWeapon + " " + newWeapon);
    4.         for(int i = 0; i < allClasses.Count; i++)
    5.         {
    6.             if(playerClassIndex == i)
    7.             {
    8.                 for(int j = 0; j < allClasses[i].WeaponName.Count; j++)
    9.                 {
    10.                     if(allClasses[i].WeaponName[j].Trim() == oldWeapon.Trim())
    11.                     {
    12.                         Debug.Log("rmm: " + newWeapon);
    13.                         allClasses[i].WeaponName[j] = newWeapon;
    14.                     }
    15.                 }
    16.             }
    17.         }
    18.     }
    19.    
    20.     public void AddWeapon(string newWeapon)
    21.     {
    22.         Debug.Log(newWeapon);
    23.         for(int i = 0; i < allClasses.Count; i++)
    24.         {
    25.             if(playerClassIndex == i)
    26.             {
    27.                 allClasses[i].WeaponName.Add(newWeapon);
    28.             }
    29.         }
    30.     }
    - WeaponPickup.cs update section of Update ():
    Code (csharp):
    1.         if(WeaponToPick){
    2.             //Press F key to pick up weapon
    3.             if(Input.GetKeyDown(KeyCode.F)){
    4.                 if(weapManager.allWeapons.Contains(newWeapon))
    5.                     return;
    6.  
    7.                 if(pickUpStyle == PickUpStyle.Replace){
    8.                     //Throw current weapon      
    9.                     GameObject clone = Instantiate(weaponToThrow, spawnObject.position, spawnObject.rotation) as GameObject;
    10.                     clone.name = weaponToThrow.name;
    11.                     //Add force when we throw weapon
    12.                     clone.rigidbody.AddForce (-spawnObject.transform.up * throwForce);
    13.                     StartCoroutine(weapManager.SwitchWeapons(weapManager.allWeapons[weapManager.index].gameObject, newWeapon.gameObject));
    14.                     weapManager.allWeapons[weapManager.index] = newWeapon;
    15.                     Destroy(WeaponToPick);
    16.                    
    17.                     RoomMultiplayerMenu rmm = GameObject.Find("__Room").GetComponent<RoomMultiplayerMenu>();
    18.                     rmm.UpdateWeapon(weaponToThrow.name, newWeapon.name);
    19.                    
    20.                     //Register Action
    21.                     actionsList.Add(("Picked | " + newWeapon.weaponName).ToString());
    22.                     timer.Add(messageTimeOut);
    23.                 }
    24.                 if(pickUpStyle == PickUpStyle.Add){
    25.                     weapManager.allWeapons.Add(newWeapon);
    26.                     weapManager.index = weapManager.allWeapons.Count-1;
    27.                     StartCoroutine(weapManager.SwitchWeapons(weapManager.SelectedWeapon.gameObject, weapManager.allWeapons[weapManager.index].gameObject));
    28.                     Destroy(WeaponToPick);
    29.                    
    30.                     RoomMultiplayerMenu rmm = GameObject.Find("__Room").GetComponent<RoomMultiplayerMenu>();
    31.                     rmm.AddWeapon(newWeapon.name);
    32.                    
    33.                     //Register Action
    34.                     actionsList.Add(("Picked | " + newWeapon.weaponName).ToString());
    35.                     timer.Add(messageTimeOut);
    36.                 }
    37.             }
    38.         }
    The similar logic can be used for the non-classes solution as well(you'll need to modify scrips a bit)

    Update: Fixed minor bug and added support for PickUpStyle "Add"
     
    Last edited: Apr 30, 2014
  20. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80
    I thought that minimap looked cool so I put this together. All you need to do and make a new camera and adjust it where you want it change to Orthorgraphic projection and add this script to it. Then you can create a new prefab and save this to it. I added the prefab to NetworkPlayer prefab.


    Code (csharp):
    1. // Script Name: MiniMap.cs
    2. // Last Updated: 04.28.2014
    3. // Modified by: ThrillKill
    4. //
    5. // Shows a basic mini map
    6. //
    7. using UnityEngine;
    8. using System.Collections;
    9.  
    10. public class MiniMap : MonoBehaviour {
    11.     // Modify position in the inspecter
    12.     [System.Serializable]
    13.     public enum miniMapScreenPosition {TopLeft, BottomLeft}; // add more locations here
    14.     public miniMapScreenPosition placememt;
    15.  
    16.     //Default Minimap Placement Top Left of screen
    17.     miniMapScreenPosition placement = miniMapScreenPosition.TopLeft;
    18.  
    19.     public float minimapSize = 1.0f;
    20.     public float offsetX = 20.0f;
    21.     public float offsetY = 20.0f;
    22.     private float adjustSize = 0.0f;
    23.  
    24.     //Mini Map GUI
    25.     public Texture miniMapBorder;  // Border around the minimap
    26.     public Texture overlayEffect; // Overlay Effect = example transparent arrow representing the player
    27.     public Camera minimapCamera; // The Minimap Camera
    28.  
    29.     //Create a target for the camera and object to hold the target
    30.     Transform miniMapCameraTarget;
    31.     GameObject Target;
    32.     //Adjusts the camara position to follow the target
    33.     void LateUpdate (){
    34.         transform.position = new Vector3 (miniMapCameraTarget.position.x, transform.position.y, miniMapCameraTarget.position.z);
    35.     }  
    36.    
    37.     void  Update (){
    38.         //this finds the player and assigns the minimap to the payer
    39.         Target = GameObject.FindWithTag("Player").gameObject;
    40.         miniMapCameraTarget = Target.transform;
    41.  
    42.         if (minimapCamera == null) return;
    43.  
    44.         //this adjusts the minimap size
    45.         adjustSize = Mathf.RoundToInt(Screen.width/15);
    46.         //where to place the camera
    47.         if(placement == miniMapScreenPosition.TopLeft){
    48.             minimapCamera.pixelRect = new Rect(offsetX - 10, (Screen.height -(minimapSize  * adjustSize)) - offsetY, minimapSize  * adjustSize, minimapSize * adjustSize);
    49.         } else if(placement == miniMapScreenPosition.BottomLeft){
    50.             minimapCamera.pixelRect = new Rect(offsetX- 10, offsetY - 10 , minimapSize  * adjustSize, minimapSize * adjustSize);
    51.         }  
    52.     }  
    53.    
    54.     void  OnGUI (){
    55.         if(miniMapBorder != null){
    56.             minimapCamera.Render ();
    57.             if(placement == miniMapScreenPosition.TopLeft){
    58.                 GUI.DrawTexture( new Rect(offsetX - 10, offsetY - 10, minimapSize  * adjustSize, minimapSize * adjustSize), overlayEffect);
    59.                 GUI.DrawTexture( new Rect(offsetX- 10, offsetY - 10, minimapSize  * adjustSize, minimapSize * adjustSize), miniMapBorder);
    60.             }
    61.            
    62.             if(placement == miniMapScreenPosition.BottomLeft){
    63.                 GUI.DrawTexture( new Rect(offsetX, (Screen.height -(minimapSize  * adjustSize)) - offsetY, minimapSize  * adjustSize, minimapSize * adjustSize), overlayEffect);
    64.                 GUI.DrawTexture( new Rect(offsetX, (Screen.height -(minimapSize  * adjustSize)) - offsetY, minimapSize  * adjustSize, minimapSize * adjustSize), miniMapBorder);
    65.             }  
    66.         }
    67.     }  
    68. }
     
  21. Le_Hieu

    Le_Hieu

    Joined:
    Mar 26, 2011
    Posts:
    31
    hi, after change the script, "fall damage" don't work? How can i fix?
     
  22. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Can we get a better example with implementing pickupable weapons? We can't seem to get it to work.
     
  23. Steve-of-Construction

    Steve-of-Construction

    Joined:
    Jan 26, 2013
    Posts:
    67
    Please heeeeeeeeeeeeeeeeeeelp ! :cry:

    Player A Team 1 shoots at Player B Team 1.
    Then every player from Team 2 sends a kill notification to all players wich is absolutely wrong!

    The bullet goes from A1 to B1.
    B1's hitboxes send damage value to B1 PlayerDamage.

    B1 reports the kill to Multiplayer Room - WhoKilledWho.
    Code (csharp):
    1. if(PhotonNetwork.player == player){
    2.     //Send death notification message to script WhoKilledWho.cs
    3.     networkObject.SendMessage("AddKillNotification", gameObject.name, SendMessageOptions.DontRequireReceiver);
    Then Multiplayer Room WhoKilledWho sends info to all players.

    Code (csharp):
    1. void AddKillNotification(string killed){
    2.     photonView.RPC("networkAddMessage", PhotonTargets.All, PhotonNetwork.player.name, killed, "killed", (string)PhotonNetwork.player.customProperties["TeamName"]);
    3. }
    But somehow player C Team2, player D Team2 and everyone else in Team2 says that he has killed player B Team1.
    Question No. 1 is: why could A1 kill B1 who is in the same team?
    Question No. 2: why does everyone from Team 2 report a kill though it was a teamkill from A1?


    Please Stan B. I need help with this! Are there any other scripts I should look at?
     
  24. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80

    Well as you have followed you will notice you have now an added variable to the damage so when your applying damage you need to compensate for that new feature.

    Example to fix with a breakdown explaination.

    Script: PlayerDamage.cs

    When using it: photonView.RPC("DoDamage" = message to send over network
    PhotonTargets.All = what players get the message
    damage = amount of damage the player takes
    "Falling" = type of damage player is taking
    "" = name of weapon or way the player died
    PhotonNetwork.player = who is taking the damage

    *** the values obviously change with how your using it but what they do are the same.
    This:
    Code (csharp):
    1.  
    2.     public void ApplyFallDamage(float damage){
    3.         if(photonView.isMine){
    4.             photonView.RPC("DoDamage", PhotonTargets.All, damage, "Falling", "", PhotonNetwork.player);
    5.         }
    6.     }
     
    Last edited: Apr 30, 2014
  25. ThrillKill

    ThrillKill

    Joined:
    Apr 7, 2014
    Posts:
    80


    I would suggest looking at player damage. It is the script that actually puts the value to the kill notification.

    Code (csharp):
    1. if(PhotonNetwork.player == player){
    2.                     //Send death notification message to script WhoKilledWho.cs
    3.                     networkObject.SendMessage("AddKillNotification", gameObject.name + "(" + weapon + ")", SendMessageOptions.DontRequireReceiver);
    My guess would be its in the
    Code (csharp):
    1.     [RPC]
    2.     //This is damage sent fro remote player instance to our local
    3.     void DoDamage(float damage, string weapon, string message, PhotonPlayer player){
     
  26. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    You'd be better off asking about that somewhere else. This is the forum thread for a particular product, not a general questions thread.
     
  27. Smartline-Games

    Smartline-Games

    Joined:
    Aug 15, 2013
    Posts:
    67
    Sorry, may I edit? I think I wrote it too fast. The question should be: So... Does this kit works well with this kind of system? Because maybe I could buy this kit for our next game project.
     
  28. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Did you add classes? Pickup would not work if weapon that you try to pickup is in the player weapon list, so you need to create loadout menu or classes to test it.
    Code (csharp):
    1.             if(Input.GetKeyDown(KeyCode.F)){
    2.                 if(weapManager.allWeapons.Contains(newWeapon))
    3.                     return;
     
  29. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Okay I got it working, but when a player picks up a weapon online that same weapon for the other player is still there. How can I make it so the weapons are synced online? I tried adding a photon view script but that didn't do anything. Any ideas?

    Also, can we, as in everyone who has the FPS Kit, collaborate to get a decent working Lobby or Matchmaking system going?
     
  30. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Check my post on page 73 "spawn medic kits"
    Same idea for weapon to pickup - add "photon view" component to the weapon prefab, than instantiate it from somewhere like:
    Weapon = PhotonNetwork.Instantiate(WeaponForPickup.name, SpawnPoints.position, SpawnPoints.rotation, 0);
     
  31. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725


    I did just this, but it never spawned the weapon. I even tested with player spawn points. I don't get any errors so I'm not sure what I'm doing wrong.
     
  32. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Ok there are 2 minor issues:
    - When you do PhotonNetwork.Instantiate photon changes network object name from "Objectname" to "Objectname Clone()"
    - Network prefab should be in "Resources" folder.

    To make it work follow my steps "Adding classes" and "Weapon pick-up and classes"
    1. To fix the "Clone()" issue edit WeaponPickUp.cs AssignWeapon() - replace line
    Code (csharp):
    1. if(playerWeapons[a].weaponName == WeaponToPick.name){
    2.  
    with
    Code (csharp):
    1. if(WeaponToPick.name.Contains(playerWeapons[a].weaponName.Trim())){
    2.  
    2. Replace Destroy(WeaponToPick); with PhotonNetwork.Destroy(WeaponToPick);

    3. Edit prefab "Blaser R93 "(or any other)
    Add Photon View component to it and assign itself to "Observe"
    $1.jpg

    4. Save prefab to the "Resources" folder

    5. For quick test follow the steps from page 73:

    6. Assign "Blaser R93 " to WeaponObject

    PS "GameObject clone = Instantiate(weaponToThrow, spawnObject.position, spawnObject.rotation) as GameObject;"
    needs to be changed to PhotonNetwork.Instantiate as well

    Edit: you can't just replace Destroy(WeaponToPick); with PhotonNetwork.Destroy(WeaponToPick);
    Only master client can do it. You need to create RPC function to destroy network object
     
    Last edited: May 1, 2014
  33. Steve-of-Construction

    Steve-of-Construction

    Joined:
    Jan 26, 2013
    Posts:
    67
    Unfortunatelly it's not.
    I think the problem is starting at another point: Player A Team 1 can kill Player B Team 1 and all the other code of FPS-Kit gets in trouble.
    Can someone explain, how the player gets the information who has shot the bullet?
    PlayerDamage should notice it's a teammate who shot the bullet and stop the code, but it doesn't (funnily only if the main body or head is shot, NOT the arms and legs!).
    My legs and arms hitboxes have a damage value of 6-10, body 15 and head 60.
    I tried to lower these values to 10 (like legs and arms) but still they got damage from teammates.
    Can't understand this at all cause there's no special code for head and mainbody.

    This all just happens if it's a teamkill !
    If enemies shoot everything is fine.
     
  34. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Can you add some debug.log to see what is going on

    - Bullet.cs sends message to the HitBox.cs
    - HitBox.cs calls PlayerDamage.cs TotalDamage()
    add log here:
    Debug.Log ("TotalDamage:" + PhotonNetwork.player.name + "|" + PhotonNetwork.player.customProperties["TeamName"] );
    - TotalDamage() sends RPC DoDamage to all players
    add log after "if(PhotonNetwork.player == player){"
    Debug.Log ("Player " + player.name + "|" + player.customProperties["TeamName"] + " Killed " + gameObject.name);
     
  35. Steve-of-Construction

    Steve-of-Construction

    Joined:
    Jan 26, 2013
    Posts:
    67
    Yes of course.
    I did the Debug.Log at the places you said.

    The Scene:
    • Player B1 North Vietnamese Army - Unity Editor (Debug results)
    • Player A1 US Army
    • Player A2 US Army

    Player A2 kills Player A1 (both in same team!), but WKW reports B1 killed A1.
    If there are more players in B-Team WKW would report that everyone from B-Team has killed A1.


    Here's what it logs:
    Code (csharp):
    1. TotalDamage:PlayerB1|North Vietnamese Army
    2. UnityEngine.Debug:Log(Object)
    3. PlayerDamage:TotalDamage(Single) (at Assets/EoD3 REDUX Script Pack/Network C#/PlayerDamage.cs:89)
    4. HitBox:ApplyDamage(Single) (at Assets/EoD3 REDUX Script Pack/Network C#/HitBox.cs:14)
    5. UnityEngine.Component:SendMessageUpwards(String, Object, SendMessageOptions)
    6. Bullet:Update() (at Assets/EoD3 REDUX Script Pack/WeaponSystem/Bullet.js:68)
    7.  
    8.  
    9.  
    10.  
    11. Player PlayerB1|North Vietnamese Army Killed PlayerA1
    12. UnityEngine.Debug:Log(Object)
    13. PlayerDamage:DoDamage(Single, PhotonPlayer) (at Assets/EoD3 REDUX Script Pack/Network C#/PlayerDamage.cs:135)
    14. System.Reflection.MethodBase:Invoke(Object, Object[])
    15. NetworkingPeer:ExecuteRPC(Hashtable, PhotonPlayer) (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:1695)
    16. NetworkingPeer:RPC(PhotonView, String, PhotonTargets, Object[]) (at Assets/Plugins/PhotonNetwork/NetworkingPeer.cs:2509)
    17. PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Object[]) (at Assets/Plugins/PhotonNetwork/PhotonNetwork.cs:1769)
    18. PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Plugins/PhotonNetwork/PhotonView.cs:205)
    19. PlayerDamage:TotalDamage(Single) (at Assets/EoD3 REDUX Script Pack/Network C#/PlayerDamage.cs:94)
    20. HitBox:ApplyDamage(Single) (at Assets/EoD3 REDUX Script Pack/Network C#/HitBox.cs:14)
    21. UnityEngine.Component:SendMessageUpwards(String, Object, SendMessageOptions)
    22. Bullet:Update() (at Assets/EoD3 REDUX Script Pack/WeaponSystem/Bullet.js:68)
    23.  
     
  36. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Based on the logs bullet came from the PlayerB1:
    TotalDamage:playerB1|North Vietnamese Army

    Try to replace:
    if(hit.transform.tag != "Player" doDamage){
    hit.transform.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    }
    with
    if(hit.transform.tag == "Blood" doDamage)
    {
    hit.transform.GetComponent<HitBox>().ApplyDamage(damage);
    }

    and in HitBox.cs
    Change ApplyDamage to public
     
    Last edited: May 1, 2014
  37. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    I've done everything you said, but I'm still not getting weapon spawns even though I have the prefab in the resources folder with a Photon View on it.

    I get this error because it can't destroy a non-instantiated non-network gameobject.

    How would I write an RPC function? Something like this? I'm new to Photon.

    Code (csharp):
    1. public class DestroyNetworkWeapon : MonoBehaviour {
    2.         void OnPlayerConnected(NetworkPlayer player) {
    3.             PhotonNetwork.RemoveRPCs(WeaponToPick);
    4.             PhotonNetwork.DestroyPlayerObjects(WeaponToPick);
    5.         }
    6.     }
    Edit: I got the network instantiation to work. I had to add the function call to the last line of the Awake function because you have to connect to the network before you can instantiate.

    I'm still stuck with the RPC function though.
     
    Last edited: May 1, 2014
  38. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Script WeaponPickUp.cs
    - Change inheritance to Photon.MonoBehaviour
    - Add RPC
    Code (csharp):
    1.     [RPC]
    2.     void DestroyWeapon(int Weapon)
    3.     {
    4.         if(PhotonNetwork.isMasterClient)
    5.         {
    6.             PhotonNetwork.Destroy(PhotonView.Find(Weapon));
    7.         }
    8.     }
    -replace Destroy(WeaponToPick); with:
    Code (csharp):
    1. photonView.RPC("DestroyWeapon", PhotonTargets.All, WeaponToPick.GetPhotonView().viewID);
    - open NetworkPlayer prefab and remove(update to None) Player Network Controller > Remote Scripts To Deactivate > NetworkPlayer(WeaponPickUp)

    After that it works fine for me.
     
  39. Steve-of-Construction

    Steve-of-Construction

    Joined:
    Jan 26, 2013
    Posts:
    67
    No no no. It's like I said: player A2 has shot A1, but B1+B2+B3+B4+B5 report themselves as the killer (everyone from team B).
    But the bullet came from A2 (team-mate!).
    That is it what's making me crazy.

    I've tried your code but exactly the same results.

    The problem is that I'm able to kill teammates, though disableDamage in PlayerDamage is enabled for every teammate.
     
  40. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Thanks for this.

    It seems to work, but when I pick up a network instantiated weapon then put it back down it's using a instantiation method for the throw down of the equip weapon:
    Code (csharp):
    1. GameObject clone = Instantiate(weaponToThrow, spawnObject.position, spawnObject.rotation) as GameObject;
    Edit: It's this:
    Code (csharp):
    1. GameObject clone = PhotonNetwork.Instantiate(weaponToThrow.name, spawnObject.position, spawnObject.rotation, 0) as GameObject;  
    Okay, everything is working, but when another player picks up a recently drop item it's creates an instant of that weapon. It does like should but it doesn't destroy the weapons. It only creates 1 extra weapon each time they go through 1 cycle of swapping.

    Any idea how to fix this?
     
    Last edited: May 1, 2014
  41. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Have you added your own custom game type? We did this and were mistakenly instantiating the wrong players (I think players from the opposite team). We had the exact same problem. That's the only thing I can think of. I'm not sure if your problem is something deeper.
     
    Last edited: May 1, 2014
  42. Steve-of-Construction

    Steve-of-Construction

    Joined:
    Jan 26, 2013
    Posts:
    67
    Yes I have another game type (CNQ = Conquest). But the players look fine, they are in correct teams.
    And this also happens in TDM mode.
    Do you remember what exactly was wrong?
     
  43. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    It was a simple mistake, and it sounds like you haven't made the same mistake, but we had the same players prefabs for our player instantiation. There's an if statement and then there's an else statement, we had the same prefab on both. When the players were spawned in a game they could kill each other, but each time a teammate got a kill it would add that score to all players on that team.
     
  44. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    I'm not a photon expert but I guess you'll need to create/modify all pickup prefabs adding photon view to them and than declare and assign them in WeaponPickUp.cs. After that when you do PhotonNetwork.Instantiate you'll reference prefab the same way as in RoomMultiplayerMenu.cs
    Hope this helps.

    Edit: I think we are very close to the right solution. If you finally resolve the problem, please post you findings here.
     
    Last edited: May 2, 2014
  45. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    Will do, I feel like we're close to figuring it out.

    I added a new player model to our game and setup everything exactly as I did with the other character. However, all character movement is now controlling both players. I have quadruple checked everything, but can't seem to find what's causing it. Is there some stupid obvious mistake we're making?
     
  46. Stan-B

    Stan-B

    Joined:
    Aug 5, 2013
    Posts:
    126
    Check if you assigned all necessary objects/scripts to deactivate under PlayerNetworkController
     
  47. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,725
    I checked all of that and still could not find a solution to the problem. I ended up just making a new character and it worked. I accidentally pasted in an extra weapon manager, I pasted in the one in from my test character, and it crashed Unity when we tried testing it. I think this was what caused the problem.

    I seemed to have found some bugs related to the animations. On start if a player is running, in our situation it happens quite often, then the player's animations are going way faster than they should. We use a setting of .8 and it looks like they're going at a setting of 6 or 7. I'm not sure if this value is mistakenly grabbed from the weapon reload speed or not, but it happens every time. It's really unappealing.

    The other bug is also related to the animations. This one happens when you run and shoot a weapon at the same time. This results in the same problem with sped up animations.

    I'm not sure if you know of a solution, but if I find anything I'll post it here.

    Edited: I may have found out what's the issue with spawning weapons online. After testing a network game while still in Unity i saw this error:
    I think this is why it creates an extra instance of each weapon.
     
    Last edited: May 3, 2014
  48. Drymarti111

    Drymarti111

    Joined:
    Jun 23, 2013
    Posts:
    201
    Sometimes players cant spawn in game, or respawn again. A screen loading from 3 to 1 and stop. Player want to leave from the server and join again to play.
    Why?
    I was recovered scripts 8 times

    I have only that problem: NullReferenceException: Object reference not set to an instance of an object
    RoomMultiplayerMenu.Awake () (at Assets/FPS Kit 2.0 C#/_CustomAssets/Scripts/Network/RoomMultiplayerMenu.cs:110)
     
    Last edited: May 3, 2014
  49. Le_Hieu

    Le_Hieu

    Joined:
    Mar 26, 2011
    Posts:
    31
    Who can guide how to show the image and sound when head-shot?
    Thank you very much!
     
  50. nertworks

    nertworks

    Joined:
    Mar 6, 2014
    Posts:
    21
    After adding my own character it doesn't seem to use the animations for the soldier. I marked the model as legacy. Pretty sure I followed the tutorial step by step. I'm not getting any errors. Just no animations. Is there something else I'm missing.