Advertisement
Guest User

Untitled

a guest
May 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. IEnumerator getPlayers(bool running)
  2. {
  3. Debug.Log("DAHAL-------METH-----------------");
  4.  
  5. string querystring = "?operation=select";
  6. string fullURL = url+querystring;
  7. while (true) {
  8. Debug.Log("DAHAL------WHILE------------------");
  9. //http://localhost:8084/example1/index.php?operation=SELECT
  10. Debug.Log(fullURL);
  11. WWW webresult = new WWW(fullURL);
  12. //wait for the result of the web query
  13. yield return webresult;
  14.  
  15. string[] records = webresult.text.Split('%');
  16.  
  17. foreach (string record in records){
  18. try{
  19. Debug.Log("DAHAL-------FOR-----------------");
  20. //Debug.Log(record);
  21. string[] fields = record.Split('|');
  22.  
  23.  
  24.  
  25. if (int.Parse(fields[0]) != currentPlayer.GetComponent<playerController>().playerID)
  26. {
  27. Debug.Log("DAHAL------IF------------------");
  28. canAdd = true;
  29.  
  30. foreach (GameObject p in currentPlayers)
  31. {
  32. if (p.GetComponent<nonplayerController>().playerID == int.Parse(fields[0]))
  33. {
  34. canAdd = false;
  35. }
  36. }
  37.  
  38. //add the player to the list
  39. //check the ids, filter the IDs of the players who are already in the game
  40.  
  41.  
  42. if (canAdd)
  43. {
  44. //instantiate a box at each position
  45. GameObject playerBox = Instantiate(player,
  46. new Vector3(float.Parse(fields[5]),float.Parse(fields[6])),
  47. Quaternion.identity);
  48.  
  49. playerBox.name = fields[1];
  50.  
  51. //restore the colour & shape from the server
  52.  
  53. //-----------------------------------
  54. //-----------------Shape------------
  55. if (fields[4] == "Circle"){
  56. playerBox.GetComponent<SpriteRenderer>().sprite = circleSprite;
  57. Debug.Log("circ-----------------------------");
  58. }else if (fields[4] == "Square")
  59. {
  60. playerBox.GetComponent<SpriteRenderer>().sprite = squareSprite;
  61. Debug.Log("SQUAAARE-----------------------------");
  62. }else if (fields[4] == "Diamond"){
  63. playerBox.GetComponent<SpriteRenderer>().sprite = diamondSprite;
  64. Debug.Log("Diamoonds-----------------------------");
  65. }else{
  66. Debug.Log("----------------how? not getting info");
  67. }
  68. //----------------------------------------
  69. //-------------Colour--------------------
  70. if (fields[3] == "Red"){
  71. playerBox.GetComponent<SpriteRenderer>().color = Color.red;
  72. Debug.Log("RED------------------------------------");
  73. }else if (fields[3] == "Green"){
  74. playerBox.GetComponent<SpriteRenderer>().color = Color.green;
  75. Debug.Log("Green------------------------------");
  76. }else if (fields[3] == "Blue"){
  77. playerBox.GetComponent<SpriteRenderer>().color = Color.blue;
  78. }else{
  79. Debug.Log("----------------how? not getting info");
  80. }
  81.  
  82.  
  83. //set the name of each player box
  84. playerBox.GetComponentInChildren<TextMesh>().text = playerBox.name;
  85.  
  86. playerBox.AddComponent<nonplayerController>();
  87.  
  88. //get the ID from the database and add it to the script inside playerbox
  89. playerBox.GetComponent<nonplayerController>().playerID = int.Parse(fields[0]);
  90.  
  91. int playeridtoadd = int.Parse(fields[0]);
  92.  
  93. currentPlayers.Add(playerBox);
  94. }
  95. }
  96.  
  97. }catch(System.Exception e){
  98. Debug.Log(e);
  99. }
  100. }
  101. //run the join game script AFTER I have loaded all the players on the web server
  102. if (!running){
  103. joinGameOnServer();
  104. break;
  105. } else {
  106. //sync users every 2 seconds
  107. Debug.Log("Synced users again"+Time.time);
  108. yield return new WaitForSeconds(2f);
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement