Guest User

Untitled

a guest
Feb 5th, 2021
82
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. local bulbulNPC = require("npcs/ai/snailicorn")
  4.  
  5. --Create the library table
  6. local bulbulNPC = {}
  7. --NPC_ID is dynamic based on the name of the library file
  8. local npcID = NPC_ID
  9.  
  10. --Defines NPC config for our NPC. You can remove superfluous definitions.
  11. local bulbulNPCSettings = {
  12.     id = npcID,
  13.     --Sprite size
  14.     gfxheight = 70,
  15.     gfxwidth = 50,
  16.     --Hitbox size. Bottom-center-bound to sprite size.
  17.     width = 34,
  18.     height = 66,
  19.     --Sprite offset from hitbox for adjusting hitbox anchor on sprite.
  20.     gfxoffsetx = 0,
  21.     gfxoffsety = 0,
  22.     --Frameloop-related
  23.     frames = 4,
  24.     framestyle = 0,
  25.     framespeed = 8, --# frames between frame change
  26.     --Movement speed. Only affects speedX by default.
  27.     speed = 1,
  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 = false,
  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 = false, --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(bulbulNPCSettings)
  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]=63,
  76.         --[HARM_TYPE_FROMBELOW]=10,
  77.         --[HARM_TYPE_NPC]=10,
  78.         [HARM_TYPE_PROJECTILE_USED]=63,
  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 bulbulNPC.onInitAPI()
  92.     --npcManager.registerEvent(npcID, bulbulNPC, "onTickNPC")
  93.     npcManager.registerEvent(npcID, bulbulNPC, "onTickEndNPC")
  94.     --npcManager.registerEvent(npcID, bulbulNPC, "onDrawNPC")
  95.     registerEvent(bulbulNPC, "onNPCHarm")
  96.     registerEvent(npcID, bulbulNPC, "onTickEnd")
  97. end
  98.  
  99. function bulbulNPC.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 = 4
  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. end
  129.  
  130.     --v.speedX = v.speedX * 0.92
  131.  
  132.     --if math.abs(v.speedX) < 0.1 then
  133.         --v.speedX = 0
  134.     --end
  135.  
  136.     --v.speedY = 1 + 0.1
  137.    
  138.     --Execute main AI. This template just jumps when it touches the ground.
  139.     --if v.collidesBlockBottom then
  140.         --v.speedY = v.speedX * 1.2
  141.         --v.speedX = 1.3 * v.direction
  142.     --end
  143. --end
  144.  
  145. function bulbulNPC.onNPCHarm(eventObj, v, killReason, culprit)
  146.     local data = v.data
  147.     if v.id ~= npcID then return end
  148.  
  149.     if killReason == HARM_TYPE_JUMP or killReason == HARM_TYPE_SWORD then
  150.  
  151.         data.health = data.health - 1
  152.         SFX.play(82)
  153.  
  154.         if data.health ~= 0 then
  155.             eventObj.cancelled = true
  156.         end
  157.     end
  158.    
  159.     --elseif killReason == HARM_TYPE_ SPINJUMP then
  160.  
  161.         --data.health = data.health - 2
  162.         --SFX.play(82)
  163.  
  164.         --if data.health ~= 0 then
  165.             --eventObj.cancelled = true
  166.         --end
  167.  
  168.     --elseif killReason == HARM_TYPE_PROJECTILE_USED then
  169.  
  170.         --data.health = data.health - 2
  171.         --SFX.play(82)
  172.  
  173.         --if data.health ~= 0 then
  174.             --eventObj.cancelled = true
  175.         --end
  176.     --end
  177. end
  178.  
  179. function bulbulNPC.onTickEnd(v)
  180.     local data = v.data
  181.     if data.health == nil then
  182.         data.health = 4
  183.     end
  184.     if data.health == 4 then
  185.         v.animationFrame = math.floor((lunatime.tick()/interval) % 8)
  186.     elseif data.health == 3 then
  187.         v.animationFrame = math.floor((lunatime.tick()/interval) % 8) + 8
  188.     end
  189. end
  190.  
  191. --Gotta return the library table!
  192. return bulbulNPC
  193.  
  194.  
RAW Paste Data