Advertisement
Devish

A broken encounter please help.

Feb 2nd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.37 KB | None | 0 0
  1. -- The encounter wasn't my idea. I just made it a reality.
  2. music = "ooo" -- Music set in audio folder. If having trouble convert to .ogg.
  3. encountertext = "The Grey Child stands in your\rway." -- Text that appears in battle box when the ecounter starts
  4. nextwaves = {"bullettest_chaserorb"} -- The next wave set at start.
  5. wavetimer = 0.0001
  6. arenasize = {155, 130}
  7.  
  8. currentitem = 1
  9.  
  10. -- Enemies on screen, can have multiple enemies. Found in monsters folder.
  11. enemies = {
  12. "core!frisk",
  13. "items"
  14. }
  15.  
  16. enemypositions = { -- Position of enemeies. Works in order of listing.
  17. {0, 0},
  18. {0, 0}
  19. }
  20.  
  21. mask = nil
  22.  
  23. -- A custom list with attacks to choose from. Actual selection happens in EnemyDialogueEnding(). Put here in case you want to use it.
  24. possible_attacks = nil
  25.  
  26. -- What happens when you start the encounter lua script
  27. function EncounterStarting()
  28.     -- If you want to change the game state immediately, this is the place.
  29.     -- Don't ask why the player's name is in the monster's lua file it just works here.
  30.     Player.name="Chara" -- Name of player.
  31.     Player.lv=1 -- The player's level.
  32.     Player.hp=20 -- The player's starting HP
  33.     SetGlobal('turn',0) -- Sets the turn to 0 because we haven't had a turn yet.
  34.     SetGlobal('fight',0) -- Sets the global value of fighting to 0. [See core!frisk.lua]
  35.     SetGlobal('sparing',0) -- Sets the global value of sparing to 0 or false.
  36.     SetGlobal('pacifist',1) -- Sets the global value of sparing to 1 or true.
  37.     SetGlobal('question',0) -- Sets the global value of questioning to 0. [See core!frisk.lua]
  38.     SetGlobal('flirt',0) -- Sets the global value of flirting to 0. [See core!frisk.lua]
  39.     SetGlobal('insult',0) -- Sets the global value of insulting to 0. [See core!frisk.lua]
  40.     SetGlobal('masked',false) -- Something to do with the item system hack :P. Hides the heart or something in the item menu.
  41.     enemies[2].SetActive(false)
  42. end
  43.  
  44. function EnemyDialogueStarting()
  45.     -- Good location for setting monster dialogue depending on how the battle is going.
  46.     -- Example: enemies[1].SetVar('currentdialogue', {"Check it\nout!"})   See documentation for details.
  47. end
  48.  
  49. function EnemyDialogueEnding()
  50.     -- Good location to fill the 'nextwaves' table with the attacks you want to have simultaneously.
  51.     -- This example line below takes a random attack from 'possible_attacks'.
  52.     nextwaves = { possible_attacks[math.random(#possible_attacks)] }
  53. end
  54.  
  55. function DefenseEnding() --This built-in function fires after the defense round ends.
  56.     enemies[1].SetActive(true)
  57.     enemies[2].SetActive(false)
  58.    
  59.     if GetGlobal('pacifist',1) then
  60.     turn_dialogue = {
  61.         "You stare at Frisk.\nFrisk stares back at you.",
  62.     }
  63.  
  64.     encountertext = turn_dialogue[GetGlobal('turn')+1]
  65.  
  66.     SetGlobal('turn',GetGlobal('turn')+1)
  67.     end
  68. end
  69.  
  70. function HandleSpare()
  71.     if enemies[1].GetVar('canspare')==true then
  72.         State("DONE")
  73.     else
  74.         State("ENEMYDIALOGUE") --By default, pressing spare only spares the enemies but stays in the menu. Changing state happens here.
  75.     end
  76. end
  77.  
  78. function HandleItem(ItemID)
  79.     BattleDialog({"Selected item " .. ItemID .. "."})
  80. end
  81.  
  82. -- THE ITEM SYSTEM ISN'T MINE CREDIT TO: carnegiesgrave. Thread: https://www.reddit.com/r/Unitale/comments/40bbgl/020a_item_menu/
  83. function Update()
  84.     if GetGlobal('masked') and mask==nil then
  85.         --We need a mask because using State('ACTMENU') hides the Player heart by default - just a bugfix, basically
  86.         mask = CreateProjectile('ut-heart-red',0,0)
  87.         mask.MoveToAbs(64,190,true)
  88.     elseif GetGlobal('masked')==false and mask!=nil then
  89.         mask.Remove()
  90.         mask=nil
  91.     end
  92.  
  93.     if Player.absx>=350 and Player.absx<380 and Player.absy<=32 then
  94.         if Input.Confirm==1 then
  95.             --Now we swap the pretend enemy with the real enemy.
  96.             enemies[1].SetActive(false)
  97.             enemies[2].SetActive(true)
  98.             --If we don't change state indirectly, such as from BattleDialogue, it skips straight to the first act command
  99.             BattleDialog({"[func:State,ACTMENU]"})
  100.             SetGlobal('lies',true)
  101.             SetGlobal('masked',true)
  102.             currentitem=1
  103.         end
  104.     end
  105.    
  106.     --Input handling for the pretend Item menu.
  107.     if GetGlobal('lies') then
  108.         local inventory = enemies[2].GetVar('commands')
  109.    
  110.         --This is for handling one page of variable commands only. Nothing more will work right now
  111.         if Input.Cancel==1 then
  112.             SetGlobal('masked',false)
  113.             State("ACTIONSELECT")
  114.             SetGlobal('lies',false)
  115.             enemies[1].SetActive(true)
  116.             enemies[2].SetActive(false)
  117.         elseif Input.Right==1 then
  118.             if mask.absx==64 and #inventory>currentitem then
  119.                 currentitem = currentitem + 1
  120.                 mask.MoveTo(mask.x+264,mask.y)
  121.             elseif mask.absx>64 then
  122.                 currentitem = currentitem - 1
  123.                 mask.MoveTo(mask.x-264,mask.y)
  124.             end
  125.         elseif Input.Left==1 then
  126.             if mask.absx>64 then
  127.                 currentitem = currentitem - 1
  128.                 mask.MoveTo(mask.x-264,mask.y)
  129.             elseif mask.absx==64 and #inventory>currentitem then
  130.                 currentitem = currentitem + 1
  131.                 mask.MoveTo(mask.x+264,mask.y)
  132.             end
  133.         --never program nested ifs at 1 AM
  134.         elseif (Input.Down==1 or Input.Up==1) and mask.absy==190 then
  135.             if #inventory==4 or (#inventory==3 and currentitem!=2) then
  136.                 currentitem = currentitem + 2
  137.                 mask.MoveTo(mask.x,mask.y-28)
  138.             elseif #inventory==3 and currentitem==2 then
  139.                 currentitem = currentitem + 1
  140.                 mask.MoveTo(mask.x-264,mask.y-28)
  141.             end
  142.         elseif (Input.Down==1 or Input.Up==1) and mask.absy<190 then
  143.             currentitem = currentitem - 2
  144.             mask.MoveTo(mask.x,mask.y+28)
  145.         end
  146.     end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement