Craig Martin

(Official) LUA Scripting Documentation

spawn_npc

Spawn an NPC (Non Player Character).


Spec:

spawn_npc(
	string type,
	long x,
	long y,
	long z,
	string name,
	string ai,
	string dialog,
	string kill_script,
	NLua.LuaTable combat_stats,
	NLua.LuaTable loot_table)

Parameters


Loot Table

The loot table specifies either a chest location (map point), or a drop item list (table), or both.

Chance items instruct the game to select a random item.

Loot Table Definition:

Point: X, Y, Z: The location of a chest.

Table of DropItems:

Examples:

local loot = { point = vector3(1,200,2) } -- loot table is just a chest location
local loot = { item.chance, { item.steelsword, 1, 50 } } -- loot table is a chance item and a steelsword with a 50 percent drop rate.
local loot = { point = vector3(1,200,2), item.chance, { item.steelsword, 1, 50 } } -- loot table is a chest location, chance item and a sword with a 50 percent drop rate.

Combat Stats

The combat stats allow you to specify custom health, attack, defence, strength and ranged stats. These 5 stats define the NPCs combat level.

Examples:

local stats = { health = 100, attack = 50 } -- health = 100, attack = 50, defence = 1, strength = 1, ranged = 1
local stats = { health = 100, attack = 50, defence = 30, strength = 40, ranged = 10 } -- health = 100, attack = 50, defence = 30, strength = 40, ranged = 10

Example

local name, dialog, kill_script
local x, y, z = get_cursor_point()
local type = "zombie"
local ai = "MyZombieAI"
local stats = { health = 100, attack = 50 }
local chest_pos = vector3(1, 201, 2)
local loot = { point = chest_pos, item.ironsword, item.steelsword, { item.grass, 10, 50 } }
spawn_npc(type, x, y, z, name, ai, dialog, kill_script, stats, loot)

This example spawns a Chef NPC at the players cursor, with a custom AI, custom Health and Attack stats, and a custom Loot Table. Name is defaulted to “Chef”. Dialog and kill_script are empty.

        The loot table consists of a chest location of 1,201,2, and three drop items.
        - First drop item is 1 iron sword, 100 percent drop rate.
        - Second item is 1 steel sword, 100 percent drop rate.
        - Third item is 10 grass blocks, 50 percent drop rate.

Incomplete

This documentation is incomplete


back