Modding:Tutorial/Constructing a Map/Source

From DoomRL Wiki

Jump to: navigation, search
--module.lua file
 
module = {
    id          = "blank",
    name        = "A Blank Map",
    author      = "DoomRL Mod Team",
    webpage     = "http://doom.chaosforge.org/wiki/",
    version     = {0,1,0},
    drlver      = {0,9,9,5},
    type        = "single",
    description = "This is an example mod, intended to be altered by anyone wanting " ..
                  "to test things using the DoomRL base set.",
    difficulty  = true,
}
--main.lua file
 
core.declare("blank", {} )
 
function blank.OnEnter()
    ui.msg("Hello world!")
 
    --give the man a shotty
    player.inv:add("shotgun")
    --create shotgun shell item with a modified amount of ammo
    local pack = item.new("shell")
    pack.ammo = 50
    player.inv:add(pack)
end
 
--local variables not within a loop are local to the file itself
--for global variables (across all files), you want to use core.declare()
--always remember to declare things before they are called somewhere else!
local countdown = 600
local minute = 0
local exit_check = true
 
function blank.OnTick()
    --keeps track of game minutes
    if countdown == 0 then
        countdown = 600
        minute = minute + 1
        ui.msg("Number of minutes passed: ".. minute)
    end
    countdown = countdown - 1
 
    --warns player if they are on stairs
    if player:get_position() == coord.new(45,10) and exit_check then
        ui.msg("Leaving already?")
        exit_check = false
    end
    if player:get_position() ~= coord.new(45,10) and not exit_check then
        exit_check = true
    end
end
 
local killCount = 0
 
function blank.OnKill()
    killCount = killCount + 1
 
    --display messages dependent on kills
    if killCount == 1 then
        ui.msg("You have killed 1 enemy.")
    else ui.msg("You have killed " .. killCount .. " enemies.")
    end
    if killCount == 10 then
        ui.msg("Wow, killing spree!")
    end
end
 
function blank.OnKillAll()
    --more enemies are added whenever all are defeated
    Level.summon("former",5)
    ui.msg("They just keep coming!!")
 
    --as a compensation, you are healed to 100% each time
    player.hp = player.hpmax
end
 
function blank.OnExit()
    ui.msg_enter("Goodbye world!")
end
 
--Personally I like to add this at the end, but these hooks can be placed in any order.
function blank.run()
    Level.name = "Blank Map"
    Level.name_number = 0
    Level.fill("wall")
 
    local translation = {
    ["."] = "floor",
    ["#"] = "wall",
    [">"] = "stairs",
    ["h"] = {"floor", being = "former"},                 --places cell with being on top
    ["]"] = {"floor", item = "garmor"},                  --places cell with item on top
    ["k"] = {"floor", being = "former", item = "phase"}, --places cell with both
    }
 
    local map = [[
##############################################################################
#............................................................................#
#............................................................................#
#............................................................................#
#............................................................................#
#...................................................h........................#
#............................................................................#
#......................................................h.....................#
#............................................................................#
#......................................]....>........h.....k.................#
#............................................................................#
#......................................................h.....................#
#............................................................................#
#...................................................h........................#
#............................................................................#
#............................................................................#
#............................................................................#
#............................................................................#
#............................................................................#
##############################################################################
]]
    Level.place_tile(translation,map,1,1)
    Generator.set_permanence( area.FULL )
    Level.player(39,10)
end
Personal tools