Untitled Game - Quest System v0.01


SUBMITTED BY: Guest

DATE: Jan. 26, 2014, 10:58 p.m.

FORMAT: JavaScript

SIZE: 3.0 kB

HITS: 10436

  1. //#pragma strict
  2. static var playerObj : GameObject;
  3. static var talkCamera : GameObject;
  4. static var sexCamera : GameObject;
  5. static var linkToChat;
  6. static var linkToInv;
  7. static var quests = new Array([["Collect 5 Apples", 0]]);
  8. function Start () {
  9. playerObj = GameObject.Find("Main Camera");
  10. talkCamera = GameObject.Find("QuestCamera");
  11. sexCamera = GameObject.Find("Camera");
  12. linkToChat = GameObject.Find("chat").GetComponent(chat);
  13. linkToInv = GameObject.Find("Inventory").GetComponent(Inventory);
  14. linkToItemEffect = GameObject.Find("Inventory").GetComponent(Inventory);
  15. // Quest Name, State (0 = not started, 1 = in progress, 2 = completed)
  16. //quests = [["Collect 5 Apples", 0]];
  17. }
  18. function Update ()
  19. {
  20. }
  21. function startQuest(index)
  22. {
  23. switch (index)
  24. {
  25. case 0:
  26. if (quests[index][1] == 0)
  27. {
  28. changeCamera("on");
  29. linkToChat.addLine("Kat: I have a quest for you! Go pick 5 apples and bring them back to me!", 5);
  30. yield WaitForSeconds (5);
  31. changeCamera("off");
  32. quests[index][1] = 1;
  33. } else if (quests[index][1] == 1)
  34. {
  35. changeCamera("on");
  36. apples = 0;
  37. for(var t:Transform in linkToInv.Contents)
  38. {
  39. var a:Item=t.GetComponent(Item);
  40. if (a.name == "default")
  41. {
  42. apples += a.stack;
  43. }
  44. }
  45. //Debug.Log(apples);
  46. if (apples >= 5)
  47. {
  48. linkToChat.addLine("Kat: Oh thank you! Here is your reward! *winks*", 5);
  49. for (var count=0; count<5; count++)
  50. {
  51. for(var t:Transform in linkToInv.Contents)
  52. {
  53. var i:Item=t.GetComponent(Item);
  54. if (i.name == "default")
  55. {
  56. playersInv = FindObjectOfType(Inventory); //finding the players inv.
  57. if (i.stack == 1) //Remove item
  58. {
  59. playersInv.RemoveItem(i.transform);
  60. break;
  61. }
  62. else //Remove from stack
  63. {
  64. i.stack -= 1;
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. quests[index][1] = 2;
  71. } else
  72. {
  73. linkToChat.addLine("Kat: Please go get me those apples I asked for!", 5);
  74. }
  75. yield WaitForSeconds (5);
  76. changeCamera("off");
  77. } else if (quests[index][1] == 2)
  78. {
  79. changeCamera("on");
  80. linkToChat.addLine("Kat: I sure hope you liked your reward. *grins*", 5);
  81. yield WaitForSeconds (5);
  82. changeCamera("off");
  83. }
  84. //break;
  85. }
  86. }
  87. function changeCamera(state)
  88. {
  89. switch(state)
  90. {
  91. case "on":
  92. sexCamera.camera.active = false;
  93. talkCamera.camera.active = true;
  94. playerObj.camera.active = false;
  95. break;
  96. case "off":
  97. talkCamera.camera.active = false;
  98. playerObj.camera.active = true;
  99. break;
  100. }
  101. }

comments powered by Disqus