Guest User

Untitled

a guest
Feb 9th, 2021
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --NPCManager is required for setting basic NPC properties
  2. local npcManager = require("npcManager")
  3.  
  4. --Create the library table
  5. local bodaciousBillNPC = {}
  6. --NPC_ID is dynamic based on the name of the library file
  7. local npcID = NPC_ID
  8.  
  9. --Defines NPC config for our NPC. You can remove superfluous definitions.
  10. local bodaciousBillNPCSettings = {
  11.     id = npcID,
  12.     --Sprite size
  13.     gfxheight = 100,
  14.     gfxwidth = 128,
  15.     --Hitbox size. Bottom-center-bound to sprite size.
  16.     width = 128,
  17.     height = 100,
  18.     --Sprite offset from hitbox for adjusting hitbox anchor on sprite.
  19.     gfxoffsetx = 0,
  20.     gfxoffsety = 0,
  21.     --Frameloop-related
  22.     frames = 1,
  23.     framestyle = 1,
  24.     framespeed = 8, --# frames between frame change
  25.     --Movement speed. Only affects speedX by default.
  26.     speed = 1,
  27.     spawnid = 414,
  28.     --Collision-related
  29.     npcblock = false,
  30.     npcblocktop = false, --Misnomer, affects whether thrown NPCs bounce off the NPC.
  31.     playerblock = false,
  32.     playerblocktop = false, --Also handles other NPCs walking atop this NPC.
  33.  
  34.     nohurt=false,
  35.     nogravity = true,
  36.     noblockcollision = false,
  37.     nofireball = false,
  38.     noiceball = false,
  39.     noyoshi= true,
  40.     nowaterphysics = false,
  41.     --Various interactions
  42.     jumphurt = false, --If true, spiny-like
  43.     spinjumpsafe = true, --If true, prevents player hurt when spinjumping
  44.     harmlessgrab = false, --Held NPC hurts other NPCs if false
  45.     harmlessthrown = false, --Thrown NPC hurts other NPCs if false
  46.  
  47.     --Emits light if the Darkness feature is active:
  48.     --lightradius = 100,
  49.     --lightbrightness = 1,
  50.     --lightoffsetx = 0,
  51.     --lightoffsety = 0,
  52.     --lightcolor = Color.white,
  53.  
  54.     --Define custom properties below
  55. }
  56.  
  57. --Applies NPC settings
  58. npcManager.setNpcSettings(bodaciousBillNPCSettings)
  59.  
  60. --Register the vulnerable harm types for this NPC. The first table defines the harm types the NPC should be affected by, while the second maps an effect to each, if desired.
  61. npcManager.registerHarmTypes(npcID,
  62.     {
  63.         --HARM_TYPE_JUMP,
  64.         --HARM_TYPE_FROMBELOW,
  65.         --HARM_TYPE_NPC,
  66.         HARM_TYPE_PROJECTILE_USED,
  67.         --HARM_TYPE_LAVA,
  68.         --HARM_TYPE_HELD,
  69.         --HARM_TYPE_TAIL,
  70.         --HARM_TYPE_SPINJUMP,
  71.         --HARM_TYPE_OFFSCREEN,
  72.         --HARM_TYPE_SWORD
  73.     },
  74.     {
  75.         --[HARM_TYPE_JUMP]=53,
  76.         --[HARM_TYPE_FROMBELOW]=10,
  77.         --[HARM_TYPE_NPC]=10,
  78.         [HARM_TYPE_PROJECTILE_USED]=16,
  79.         --[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
  80.         --[HARM_TYPE_HELD]=10,
  81.         --[HARM_TYPE_TAIL]=10,
  82.         --[HARM_TYPE_SPINJUMP]=63,
  83.         --[HARM_TYPE_OFFSCREEN]=10,
  84.         --[HARM_TYPE_SWORD]=63,
  85.     }
  86. );
  87.  
  88. --Custom local definitions below
  89.  
  90. --Register events
  91. function bodaciousBillNPC.onInitAPI()
  92.     npcManager.registerEvent(npcID, bodaciousBillNPC, "onTickNPC")
  93.     npcManager.registerEvent(npcID, bodaciousBillNPC, "onTickEndNPC")
  94.     --npcManager.registerEvent(npcID, bodaciousBillNPC, "onDrawNPC")
  95.     registerEvent(bodaciousBillNPC, "onNPCHarm")
  96.     registerEvent(npcID, bodaciousBillNPC, "onTickEnd")
  97. end
  98.  
  99. function bodaciousBillNPC.onTickEndNPC(v)
  100.     --Don't act during time freeze
  101.     if Defines.levelFreeze then return end
  102.    
  103.     local data = v.data
  104.  
  105.    
  106.     --If despawned
  107.     if v.despawnTimer <= 0 then
  108.         --Reset our properties, if necessary
  109.         data.initialized = false
  110.         return
  111.     end
  112.  
  113.     --Initialize
  114.     if not data.initialized then
  115.         --Initialize necessary data.
  116.         data.initialized = true
  117.         data.health = 9
  118.     end
  119.  
  120.     --Depending on the NPC, these checks must be handled differently
  121.     if v:mem(0x12C, FIELD_WORD) > 0    --Grabbed
  122.     or v:mem(0x136, FIELD_BOOL)        --Thrown
  123.     or v:mem(0x138, FIELD_WORD) > 0    --Contained within
  124.     then
  125.         --Handling
  126.         return
  127.     end
  128.  
  129.     v.speedX = v.speedX * 0.92
  130.  
  131.     if math.abs(v.speedX) < 0.1 then
  132.         v.speedX = 0
  133.     end
  134.  
  135.         v.speedX = 1.8 * v.direction
  136. end
  137.  
  138. function onTickNPC()
  139.     for index,bodaciousBillNPC in ipairs(NPC.get(942)) do
  140.         bodaciousBillNPC.speedY = -4
  141.     end
  142. end
  143.  
  144. function bodaciousBillNPC.onNPCHarm(eventObj, v, killReason, culprit)
  145.     local data = v.data
  146.     if v.id ~= npcID then return end
  147.  
  148.     if killReason == HARM_TYPE_PROJECTILE_USED then
  149.  
  150.         data.health = data.health - 1
  151.         SFX.play(39)
  152.  
  153.         if data.health < 3 then
  154.             NPC.config[v.id].speed = 3
  155.         end
  156.  
  157.         if data.health ~= 0 then
  158.             eventObj.cancelled = true
  159.         end
  160.     end
  161. end
  162.  
  163. function bodaciousBillNPC.onTickEnd(v)
  164.     local data = v.data
  165.     if data.health == nil then
  166.         data.health = 12
  167.     end
  168.     if data.health == 12 then
  169.         v.animationFrame = math.floor((lunatime.tick()/interval) % 8)
  170.     elseif data.health == 12 then
  171.         v.animationFrame = math.floor((lunatime.tick()/interval) % 8) + 8
  172.     end
  173. end
  174.  
  175. --Gotta return the library table!
  176. return bodaciousBillNPC
  177.  
  178.  
RAW Paste Data