Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --NPCManager is required for setting basic NPC properties
- local npcManager = require("npcManager")
- local bulbulNPC = require("npcs/ai/snailicorn")
- --Create the library table
- local bulbulNPC = {}
- --NPC_ID is dynamic based on the name of the library file
- local npcID = NPC_ID
- --Defines NPC config for our NPC. You can remove superfluous definitions.
- local bulbulNPCSettings = {
- id = npcID,
- --Sprite size
- gfxheight = 70,
- gfxwidth = 50,
- --Hitbox size. Bottom-center-bound to sprite size.
- width = 34,
- height = 66,
- --Sprite offset from hitbox for adjusting hitbox anchor on sprite.
- gfxoffsetx = 0,
- gfxoffsety = 0,
- --Frameloop-related
- frames = 4,
- framestyle = 0,
- framespeed = 8, --# frames between frame change
- --Movement speed. Only affects speedX by default.
- speed = 1,
- --Collision-related
- npcblock = false,
- npcblocktop = false, --Misnomer, affects whether thrown NPCs bounce off the NPC.
- playerblock = false,
- playerblocktop = false, --Also handles other NPCs walking atop this NPC.
- nohurt=false,
- nogravity = false,
- noblockcollision = false,
- nofireball = false,
- noiceball = false,
- noyoshi= true,
- nowaterphysics = false,
- --Various interactions
- jumphurt = false, --If true, spiny-like
- spinjumpsafe = false, --If true, prevents player hurt when spinjumping
- harmlessgrab = false, --Held NPC hurts other NPCs if false
- harmlessthrown = false, --Thrown NPC hurts other NPCs if false
- --Emits light if the Darkness feature is active:
- --lightradius = 100,
- --lightbrightness = 1,
- --lightoffsetx = 0,
- --lightoffsety = 0,
- --lightcolor = Color.white,
- --Define custom properties below
- }
- --Applies NPC settings
- npcManager.setNpcSettings(bulbulNPCSettings)
- --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.
- npcManager.registerHarmTypes(npcID,
- {
- HARM_TYPE_JUMP,
- --HARM_TYPE_FROMBELOW,
- --HARM_TYPE_NPC,
- HARM_TYPE_PROJECTILE_USED,
- --HARM_TYPE_LAVA,
- --HARM_TYPE_HELD,
- --HARM_TYPE_TAIL,
- HARM_TYPE_SPINJUMP,
- --HARM_TYPE_OFFSCREEN,
- HARM_TYPE_SWORD
- },
- {
- [HARM_TYPE_JUMP]=63,
- --[HARM_TYPE_FROMBELOW]=10,
- --[HARM_TYPE_NPC]=10,
- [HARM_TYPE_PROJECTILE_USED]=63,
- --[HARM_TYPE_LAVA]={id=13, xoffset=0.5, xoffsetBack = 0, yoffset=1, yoffsetBack = 1.5},
- --[HARM_TYPE_HELD]=10,
- --[HARM_TYPE_TAIL]=10,
- [HARM_TYPE_SPINJUMP]=63,
- --[HARM_TYPE_OFFSCREEN]=10,
- [HARM_TYPE_SWORD]=63,
- }
- );
- --Custom local definitions below
- --Register events
- function bulbulNPC.onInitAPI()
- --npcManager.registerEvent(npcID, bulbulNPC, "onTickNPC")
- npcManager.registerEvent(npcID, bulbulNPC, "onTickEndNPC")
- --npcManager.registerEvent(npcID, bulbulNPC, "onDrawNPC")
- registerEvent(bulbulNPC, "onNPCHarm")
- registerEvent(npcID, bulbulNPC, "onTickEnd")
- end
- function bulbulNPC.onTickEndNPC(v)
- --Don't act during time freeze
- if Defines.levelFreeze then return end
- local data = v.data
- --If despawned
- if v.despawnTimer <= 0 then
- --Reset our properties, if necessary
- data.initialized = false
- return
- end
- --Initialize
- if not data.initialized then
- --Initialize necessary data.
- data.initialized = true
- data.health = 4
- end
- --Depending on the NPC, these checks must be handled differently
- if v:mem(0x12C, FIELD_WORD) > 0 --Grabbed
- or v:mem(0x136, FIELD_BOOL) --Thrown
- or v:mem(0x138, FIELD_WORD) > 0 --Contained within
- then
- --Handling
- return
- end
- end
- --v.speedX = v.speedX * 0.92
- --if math.abs(v.speedX) < 0.1 then
- --v.speedX = 0
- --end
- --v.speedY = 1 + 0.1
- --Execute main AI. This template just jumps when it touches the ground.
- --if v.collidesBlockBottom then
- --v.speedY = v.speedX * 1.2
- --v.speedX = 1.3 * v.direction
- --end
- --end
- function bulbulNPC.onNPCHarm(eventObj, v, killReason, culprit)
- local data = v.data
- if v.id ~= npcID then return end
- if killReason == HARM_TYPE_JUMP or killReason == HARM_TYPE_SWORD then
- data.health = data.health - 1
- SFX.play(82)
- if data.health ~= 0 then
- eventObj.cancelled = true
- end
- end
- --elseif killReason == HARM_TYPE_ SPINJUMP then
- --data.health = data.health - 2
- --SFX.play(82)
- --if data.health ~= 0 then
- --eventObj.cancelled = true
- --end
- --elseif killReason == HARM_TYPE_PROJECTILE_USED then
- --data.health = data.health - 2
- --SFX.play(82)
- --if data.health ~= 0 then
- --eventObj.cancelled = true
- --end
- --end
- end
- function bulbulNPC.onTickEnd(v)
- local data = v.data
- if data.health == nil then
- data.health = 4
- end
- if data.health == 4 then
- v.animationFrame = math.floor((lunatime.tick()/interval) % 8)
- elseif data.health == 3 then
- v.animationFrame = math.floor((lunatime.tick()/interval) % 8) + 8
- end
- end
- --Gotta return the library table!
- return bulbulNPC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement