Creating NPCs is an extension of creating Basic Items. Getting started we’ll want to create a .ce file in mods/core/npc/. NPCs have their own content template to simplify the creation.
The NPC template is fairly simple with only a few parameters.
Npc
(name, markerIcon='', gestureSound='', gestureSoundDelay=0, **kwargs)¶Sets up the content entity data of an NPC.
Parameters: |
|
---|
NPCs typically should be interactable so it is important to provide a custom interact()
function.
Below is a full example of an NPC content file.
from core.template.animation import Frame, Frames
from core.template.npc import Npc
from siege import game
from siege.io import DataStream
from siege.network import Message
from siege.util import PixelVector
merchant = Npc(
name = "Merchant",
markerIcon = 'mods/core/item/outfit/merchant_outfit.png',
gestureSound = "mods/core/audio/sfx/npc/merchant_gesture.ogg",
gestureSoundDelay = 100
)
@merchant.interact
def interact(player, entity, position):
packet = DataStream(Message.SHOW_UI)
packet.writeString("shop")
packet.writeUint32(entity.id)
packet.writeString("merchant")
game.network.getServer().send(player.networkId, packet)
idle = merchant.getSpriteFrames(
frames = [
Frame(2, 2),
Frame(33, 2),
Frame(64, 2),
Frame(95, 2),
Frame(126, 2),
Frame(2, 55),
Frame(33, 55)
],
size = PixelVector(31, 53),
origin = PixelVector(14, 29)
)
animate = merchant.getSpriteFrames(
frames = [
Frame(64, 55),
Frame(93, 55),
Frame(122, 55),
Frame(2, 117),
Frame(31, 117),
Frame(60, 117),
Frame(89, 117)
],
size = PixelVector(29, 62),
origin = PixelVector(15, 38)
)
merchant.animations(
start = 'idle',
idle = Frames(idle(1)),
gesture = (
Frames(idle(2, 3, 4, 5, 6, 7, 6, 5, 4), time=100),
Frames(idle(3), time=500),
Frames(idle(4, 5, 6, 7, 6, 5, 4), time=100),
Frames(idle(3), time=500),
Frames(idle(4, 5, 6, 7, 6, 5, 4, 3, 2), time=100)
),
animate = Frames(animate(), time=100),
disableLooping = ['animate', 'gesture']
)