summaryrefslogtreecommitdiff
path: root/example/scripts/monster/testmonster.lua
blob: 21b6a7b2a523addf62cac703307c7784c639a0d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--[[

 Example monster script.

 Makes the monster boost about his abilities and makes both the monster and
 the player talkative during battle.

--]]

local function update(mob)
    local r = math.random(0, 200);
    if r == 0 then
        mob:say("Roar! I am a boss")
    end
end

local function strike(mob, victim, hit)
    if hit > 0 then
        mob:say("Take this! "..hit.." damage!")
        victim:say("Oh Noez!")
    else
        mob:say("Oh no, my attack missed!")
        victim:say("Whew...")
    end
end

local maggot = get_monster_class("maggot")
maggot:on_update(update)
local attacks = maggot:attacks();
for i, attack in ipairs(attacks) do
    attack:on_attack(strike)
end