Advertisement
ywkls

NPC2

Sep 17th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. const NPC_LAYER =2;//Has to be layer 2 or 1.
  2. //Used to affect solidity
  3.  
  4. // FFC script for talking NPCs with different functions
  5. // It's pretty much a sign you can approach from any side.
  6. // D0: String number to be displayed
  7. // D1: Item for interaction
  8. // If positive, npc persists until you have the item
  9. // If Negative, npc doesn't appear until you have the item
  10. //
  11. // D2: Screen->D register to store information in.
  12. // A number between 0-7 unique for each npc on screen
  13. //
  14. // D3: Whether screen secrets are triggered after talking to this npc
  15.  
  16. ffc script altnpcscript{
  17. void run(int string, int item_req, int perm,bool secret){
  18. // So that people don't have to be pixel perfect on placing npcs.
  19. //Used for determining what combo to change
  20. int loc= ComboAt(this->X,this->Y);
  21. //Remember what combo was here before
  22. int this_combo= Screen->D[loc];
  23. //Remember the npc's appearance if it is supposed to be invisible until you have an item
  24. int store_combo= this->Data;
  25. //NPC appears until you have an item
  26. if(item_req>0){
  27. //You don't have the item
  28. if(!Link->Item[item_req]){
  29. //Set the combo on layer one at this position
  30. //To whatever was here before
  31. SetLayerComboD(NPC_LAYER-1,loc,this_combo);
  32. //Set the combo here on layer 2 to the npc's data
  33. SetLayerComboD(NPC_LAYER,loc,this->Data);
  34. }
  35. else
  36. SetLayerComboD(NPC_LAYER,loc,GetLayerComboD(NPC_LAYER-1,loc));
  37. //Once you have the item, change the combo at this position
  38. //Uses the stored combo on layer 1 to determine what to put here
  39. }
  40. else if(item_req<0){
  41. //Npc is invisible until you have the item
  42. this->Data= GH_INVISIBLE_COMBO;
  43. //Do nothing until you have the item
  44. while(!Link->Item[item_req])
  45. Waitframe();
  46. //Restore npc appearance
  47. this->Data = store_combo;
  48. //Change the combo on layer 2 to npc data to affect solidity
  49. SetLayerComboD(NPC_LAYER,loc,this->Data);
  50. }
  51. //When placed here, no errors manifest
  52. //int LinkX;
  53. //int LinkY;
  54. //int centerX;
  55. //int centerY;
  56. while(true){
  57. //When placed here, they do
  58. // Set up some values to make the if statement smaller.
  59. int LinkX = Link->X + 8;
  60. int LinkY = Link->Y + 8;
  61. int centerX = this->X + this->EffectWidth / 2;
  62. int centerY = this->Y + this->EffectHeight / 2;
  63. // If Link is on one of the sides of the NPC and facing it
  64. if(
  65. ((Abs(LinkX - centerX) < this->EffectWidth / 2
  66. && Abs(LinkY - centerY) <= this->EffectHeight / 2 + 12
  67. && LinkY < centerY && Link->Dir == DIR_DOWN) ||
  68. (Abs(LinkX - centerX) < this->EffectWidth / 2
  69. && Abs(LinkY - centerY) <= this->EffectHeight / 2 + 4
  70. && LinkY > centerY && Link->Dir == DIR_UP) ||
  71. (Abs(LinkY + 3 - centerY) < this->EffectHeight / 2
  72. && Abs(LinkX - centerX) <= this->EffectWidth / 2 + 12
  73. && LinkX < centerX && Link->Dir == DIR_RIGHT) ||
  74. (Abs(LinkY + 3- centerY) < this->EffectHeight / 2
  75. && Abs(LinkX - centerX) <= this->EffectWidth / 2 + 12
  76. && LinkX > centerX && Link->Dir == DIR_LEFT))){
  77. if(Link->PressEx1){
  78. Link->InputEx1=false;
  79. Screen->Message(string);
  80. if(Screen->D[perm]==0){
  81. //This is so that any string control codes which read Screen->D aren't
  82. //immediately triggered
  83. Waitframes(5);
  84. //Set screen D register
  85. Screen->D[perm]=1;
  86. //Trigger secrets
  87. if(secret){
  88. Screen->TriggerSecrets();
  89. Screen->State[ST_SECRET]= true;
  90. }
  91. }
  92. }
  93. }
  94. Waitframe();
  95. } // End of while(true)
  96. } // End of void run(int message)
  97. } // End of ffc script npcscript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement