NPC (class)

From PGE Wiki
(Redirected from SMBX NPC Offsets)
Jump to: navigation, search

This class provides fields/functions for managing NPCs in the current level. DO NOT SAVE THIS CLASS/VARIABLE, ONLY USE IT LOCALLY PER FRAME.

NPC class
Type Function/Field Return values/Value type Description
Constructor myNPC = NPC(int internalIndex) NPC Construct a new NPC-Object. Only use this constructor with caution. Use NPC.get() or NPC.getIntersecting() instead!
function NPC:mem(int offset, int fieldtype, object value) nil Sets a value of the NPC struct at a specific address-offset.
function NPC:mem(int offset, int fieldtype) object Returns a value of the NPC struct at a specific address-offset.
function NPC:kill() nil Kills the npc with the standard kill animation.
function NPC:kill(int killanimation) nil Kills the npc with the kill animation killanimation.
function NPC:harm() nil Harms the npc as if it were hit by a thrown npc. (LunaLua ≥ v0.7.3)
function NPC:harm(int harmType) nil Harms the npc as if it took a certain type of damage. See constants for the different harm types. (LunaLua ≥ v0.7.3)
function NPC:harm(int harmType, int damage) nil Deals the given amount of damage to an NPC with the given harm type. The damage value is ignored by one-hit npcs. (LunaLua ≥ v0.7.3)
function NPC:toIce() nil Freezes a npc and transform it into ice. (LunaLua ≥ v0.7.2.1)
function NPC:toCoin() nil Transforms the npc into the coin effect. (Similar to Misc.npcToCoins(), just per NPC) (LunaLua ≥ v0.7.2.1)
Field NPC.x double The x coordinate of the npc.
Field NPC.y double The y coordinate of the npc.
Field NPC.width int The width of the npc.
Field NPC.height int The height of the npc.
Field NPC.speedX double The x-speed of the npc.
Field NPC.speedY double The y-speed of the npc.
Field NPC.id int The npc-id of the npc.
Field NPC.direction int The direction of the npc. NOTE: Setting the direction of a npc, resets the momentum of the npc. You can modify the speedX value if you want to set your own momentum.
Field NPC.msg VBStr The message of the npc.
Field (ro) NPC.attachedLayerName VBStr The attached layer.
Field (ro) NPC.activateEventName VBStr The event name of the activate-event.
Field (ro) NPC.deathEventName VBStr The event name of the death-event.
Field (ro) NPC.noMoreObjInLayer VBStr The event name of the "No more objects in layer"-event.
Field (ro) NPC.talkEventName VBStr The event name of the talk-event.
Field (ro) NPC.layerName VBStr The layer name of the npc.
Field (ro) NPC.layerObj Layer The layer object of the npc.
Field (ro) NPC.attachedLayerObj Layer The attached layer object.
Field NPC.ai1 number The 1. AI-field. This field controls the behavouir of NPCs. Read more about it at: SMBX NPC AI (LunaLua ≥ v0.7.2)
Field NPC.ai2 number The 2. AI-field. This field controls the behavouir of NPCs. Read more about it at: SMBX NPC AI (LunaLua ≥ v0.7.2)
Field NPC.ai3 number The 3. AI-field. This field controls the behavouir of NPCs. Read more about it at: SMBX NPC AI (LunaLua ≥ v0.7.2)
Field NPC.ai4 number The 4. AI-field. This field controls the behavouir of NPCs. Read more about it at: SMBX NPC AI (LunaLua ≥ v0.7.2)
Field NPC.ai5 number The 5. AI-field. This field controls the behavouir of NPCs. Read more about it at: SMBX NPC AI (LunaLua ≥ v0.7.2)
Field NPC.drawOnlyMask boolean If only the mask of the NPC should be drawn. May not work if the sprite uses PNG. (LunaLua ≥ v0.7.2.1)
Field NPC.invincibleToSword boolean If the NPC is invincible to Link's sword. (LunaLua ≥ v0.7.2.1)
Field NPC.legacyBoss boolean If the NPC is a legacy boss. (LunaLua ≥ v0.7.2.1)
Field NPC.friendly boolean If the NPC is friendly. (LunaLua ≥ v0.7.2.1)
Field NPC.dontMove boolean If the NPC doesn't move. (LunaLua ≥ v0.7.2.1)
Field NPC.collidesBlockBottom boolean If the NPC collides with a block on the bottom side. (LunaLua ≥ v0.7.2.2)
Field NPC.collidesBlockLeft boolean If the NPC collides with a block on the left side. (LunaLua ≥ v0.7.2.2)
Field NPC.collidesBlockUp boolean If the NPC collides with a block on the up side. (LunaLua ≥ v0.7.2.2)
Field NPC.collidesBlockRight boolean If the NPC collides with a block on the right side. (LunaLua ≥ v0.7.2.2)
Field NPC.underwater boolean If the NPC is underwater. (LunaLua ≥ v0.7.2.2)
Field NPC.animationFrame number The current frame of the NPC. (LunaLua ≥ v0.7.2.2)
Field NPC.animationTimer number The animation timer. If the timer reaches a specific value, then the animation frame of the NPC changes. (LunaLua ≥ v0.7.2.2)

Offsets

This is the memory map for the npc struct. This struct is not fully analysed. Any help is appreciated! Please note that the data may not be fully 100% accurate.

NPC Memory (0x158 bytes)
Name Memory address Memory type Description
Attached layer name NPC+0x00 VB6 String Pointer The attached layer name.
Unknown NPC+0x04 FIELD_WORD Unknown
Unknown decrementing timer NPC+0x06 FIELD_WORD Unknown decrementing timer
Collides below NPC+0x0A FIELD_WORD Set to 2 when touching a block below and briefly immediately after being thrown by the player
Collides left NPC+0x0C FIELD_WORD Set to 2 when touching a block to the left
Collides above NPC+0x0E FIELD_WORD Set to 2 when touching a block above
Collides right NPC+0x10 FIELD_WORD Set to 2 when touching a block to the right
Unknown NPC+0x18 FIELD_FLOAT NPC x-axis movement related, perhaps temporary
Is Underwater? NPC+0x1C FIELD_WORD underwater state (2 is underwater, 0 is no)
Hit Counter (ie for hammers) NPC+0x24 FIELD_WORD Hit counter, for point calculation
Invincibility to Sword NPC+0x26 FIELD_WORD Invincibility frame countdown, for sword attacks
Activate event layer name NPC+0x2C VB6 String Pointer Activate event layer name
Death event layer name NPC+0x30 VB6 String Pointer Death event layer name
Talk event name? NPC+0x34 VB6 String Pointer Talk event name?
No More Objs event layer name NPC+0x38 VB6 String Pointer No More Objs event layer name
Layer name NPC+0x3C VB6 String Pointer Layer name
isHidden NPC+0x40 FIELD_WORD If the NPC is hidden.
Activated NPC+0x44 FIELD_WORD Activated / interacted with player flag
Friendly NPC+0x46 FIELD_WORD Friendly (on = -1)
Don't Move NPC+0x48 FIELD_WORD Don't Move (on = -1)
NPC Message text NPC+0x4C VB6 String Pointer NPC Message text
Is a generator NPC+0x64 FIELD_WORD Is a generator?
Generator delay setting NPC+0x68 FIELD_WORD Generator delay setting
Generator firing rate NPC+0x6A FIELD_WORD Generator firing rate
Generator delay countdown NPC+0x6C FIELD_FLOAT Generator delay countdown
Direction to generate NPC? NPC+0x70 FIELD_WORD Direction to generate NPC?
Generator type NPC+0x72 FIELD_WORD The generator type (1 = Warp; 2 = Projectile)
Invalidity/offscreen flag? NPC+0x74 FIELD_WORD Invalidity or offscreen flag?
X position NPC+0x78 FIELD_DFLOAT X position
Y position NPC+0x80 FIELD_DFLOAT Y position
Height NPC+0x88 FIELD_DFLOAT Height
Width NPC+0x90 FIELD_DFLOAT Width
X Speed NPC+0x98 FIELD_DFLOAT X Speed
Y Speed NPC+0xA0 FIELD_DFLOAT Y Speed
Spawn X NPC+0xA8 FIELD_DFLOAT Spawn X
Spawn Y NPC+0xB0 FIELD_DFLOAT Spawn Y
GFX Height NPC+0xB8 FIELD_DFLOAT GFX Height
GFX Width NPC+0xC0 FIELD_DFLOAT GFX Width
Spawn Direction NPC+0xD8 FIELD_FLOAT Direction the NPC is spawned in
Respawn Id NPC+0xDC FIELD_WORD Respawn Identity. 0 means doesn't respawn, otherwise same as 0xE2
Id NPC+0xE2 FIELD_WORD Sprite GFX index/Identity
Animation frame NPC+0xE4 FIELD_WORD Animation frame
Animation timer NPC+0xE8 FIELD_FLOAT Animation timer
Direction faced NPC+0xEC FIELD_FLOAT Direction faced (Unknown difference from 0x118)
NPC AI 1 NPC+0xF0 FIELD_DFLOAT Multipurpose NPC AI state/timer 1
NPC AI 2 NPC+0xF8 FIELD_DFLOAT Multipurpose NPC AI state/timer 2
NPC AI 3 NPC+0x100 FIELD_DFLOAT Multipurpose NPC AI state/timer 3
NPC AI 4 NPC+0x108 FIELD_DFLOAT Multipurpose NPC AI state/timer 4
NPC AI 5 NPC+0x110 FIELD_DFLOAT Multipurpose NPC AI state/timer 5
Direction faced NPC+0x118 FIELD_FLOAT Direction faced
Bounce off block NPC+0x120 FIELD_WORD -1 means just bounced off a block to change direction
Kill flag NPC+0x122 FIELD_WORD Kill/Kill effect (0 = No kill/ 1-? Kill effect with kill)
Respawned, but onscreen NPC+0x124 FIELD_WORD This is set to 0 when an NPC resets its respawn position, but will not spawn itself fully because it's still visible by the player. Note: Must be set to -1 when spawning a new NPC
Offscreen flag NPC+0x128 FIELD_WORD Offscreen flag (-1 = offscreen)
Offscreen countdown timer? NPC+0x12A FIELD_WORD Offscreen countdown timer. 180 is onscreen. Set to 0 to force despawn. This is set to -1 when an NPC is ready to respawn (but may not be able to if the player is close by)
Player carrying index NPC+0x12C FIELD_WORD The index of the player grabbing the NPC. Defaults to 0 when not grabbed, setting to 1 or higher deactivates block collision when grabbed but causes the respective player to drop other objects
Grab Timer? NPC+0x12E FIELD_WORD Related to grabbing npcs. Starts at 30 then quickly returns to 0 when released.
Collides with NPCs NPC+0x136 FIELD_WORD -1 indicates it collides with other NPCs. Doubles as a "grabbed" flag
Contained Within NPC+0x138 FIELD_WORD Set to the container ID when contained in another NPC (e.g. jar). 1 = Coming out of the top of a block, 2 = Dropped from itembox, 3 = Coming out of the bottom of a block, 4 = Being spawned by generator, 5 = Being eaten by Yoshi
Current Section NPC+0x146 FIELD_WORD Current section this NPC is on
Hit Count NPC+0x148 FIELD_FLOAT Boss Hit count
P-Switch Block ID NPC+0x14E FIELD_WORD ID of the block they were created from due to p-switch
NPC Collision NPC+0x152 FIELD_WORD Seems to be set to -1 for a bullet when it destroys another NPC. May apply to all 0x136-related collisions but untested.
Invincibility frames NPC+0x156 FIELD_WORD Invincibility frame countdown for all sources of harm