Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --the table for storing all the functions
- NPCEngine = {}
- --for storing all the data for the NPCs
- NPCEngine.Data = {}
- --the list of stored entities
- NPCEngine.Data.entities = {}
- --the list of stored objects
- NPCEngine.Data.objects = {}
- --for creating a basic fireable event
- local function createEvent()
- --the returning table
- local ret = {}
- --for storeing the list of instances that we create for bindable functions
- ret.instances = {}
- --for fireing the event, with varied arguments
- function ret:fire(...)
- for i, v in pairs(ret.instances) do
- v(...)
- end
- end
- --for registering new events
- function ret:connect(_f)
- table.insert(ret.instances, _f)
- end
- --then returning the new bindable event
- return ret
- end
- --for registering new NPCs
- function NPCEngine:new(npcname)
- local npc = {}
- function npc:spawn(...)
- local args = {...}
- if #args == 1 then
- --using pos
- pos = args[1]
- npc.Events.OnSpawn:fire(pos)
- print("[Info] NPC SPAWNING COMING SOON!")
- elseif #args >= 3 then
- --use x, y, z
- local x, y, z = args[1], args[2], args[3]
- local pos = {x = x, y = y, z = z}
- npc.Events.OnSpawn:fire(pos)
- print("[Info] NPC SPAWNING COMING SOON!")
- else
- error("Invalid arguments, npc:spawn(pos) or npc:spawn(x,y,z)")
- end
- end
- --for creating new events
- --usage: event.EventName:connect(FiredFunction)
- --event.EventName:fire(...) will throw the event with the arguments you specify
- npc.Events = {}
- npc.Events.OnSpawn = createEvent()
- npc.Events.OnDied = createEvent()
- npc.Events.OnUpdate = createEvent()
- npc.Events.OnSave = createEvent()
- npc.Events.OnLoad = createEvent()
- table.insert(NPCEngine.Data.objects)
- end
- minetest.NPC = NPCEngine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement