Advertisement
ywkls

Alternate NPC

Sep 14th, 2020 (edited)
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int 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 altnpc_script{
  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. Game->SetComboCSet(Screen->LayerMap(NPC_LAYER), Screen->LayerScreen(NPC_LAYER), loc, this->CSet);
  35. }
  36. else{
  37. SetLayerComboD(NPC_LAYER,loc,GetLayerComboD(NPC_LAYER-1,loc));
  38. //Once you have the item, change the combo at this position
  39. //Uses the stored combo on layer 1 to determine what to put here
  40. this->Data= GH_INVISIBLE_COMBO;
  41. Quit();
  42. }
  43. }
  44. else if(item_req<0){
  45. //Npc is invisible until you have the item
  46. this->Data= GH_INVISIBLE_COMBO;
  47. //Do nothing until you have the item
  48. while(!Link->Item[Abs(item_req)])
  49. Waitframe();
  50. //Restore npc appearance
  51. this->Data = store_combo;
  52. //Change the combo on layer 2 to npc data to affect solidity
  53. SetLayerComboD(NPC_LAYER,loc,this->Data);
  54. }
  55. int LinkX;
  56. int LinkY;
  57. int centerX;
  58. int centerY;
  59. while(true){
  60. // Set up some values to make the if statement smaller.
  61. LinkX = Link->X + 8;
  62. LinkY = Link->Y + 8;
  63. centerX = this->X + this->EffectWidth / 2;
  64. centerY = this->Y + this->EffectHeight / 2;
  65. // If Link is on one of the sides of the NPC and facing it
  66. if(
  67. ((Abs(LinkX - centerX) < this->EffectWidth / 2
  68. && Abs(LinkY - centerY) <= this->EffectHeight / 2 + 12
  69. && LinkY < centerY && Link->Dir == DIR_DOWN) ||
  70. (Abs(LinkX - centerX) < this->EffectWidth / 2
  71. && Abs(LinkY - centerY) <= this->EffectHeight / 2 + 4
  72. && LinkY > centerY && Link->Dir == DIR_UP) ||
  73. (Abs(LinkY + 3 - centerY) < this->EffectHeight / 2
  74. && Abs(LinkX - centerX) <= this->EffectWidth / 2 + 12
  75. && LinkX < centerX && Link->Dir == DIR_RIGHT) ||
  76. (Abs(LinkY + 3- centerY) < this->EffectHeight / 2
  77. && Abs(LinkX - centerX) <= this->EffectWidth / 2 + 12
  78. && LinkX > centerX && Link->Dir == DIR_LEFT))){
  79. if(Link->PressEx1){
  80. Link->InputEx1=false;
  81. Screen->Message(string);
  82. if(Screen->D[perm]==0){
  83. //This is so that any string control codes which read Screen->D aren't
  84. //immediately triggered
  85. Waitframes(5);
  86. //Set screen D register
  87. Screen->D[perm]=1;
  88. //Trigger secrets
  89. if(secret){
  90. Screen->TriggerSecrets();
  91. Screen->State[ST_SECRET]= true;
  92. }
  93. }
  94. }
  95. }
  96. Waitframe();
  97. } // End of while(true)
  98. } // End of void run(int message)
  99. } // End of ffc script npcscript
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement