User:RedEnchilada/Lua/Interacting with the map
Note: I forget how Wiki markup works. Also, this is really incomplete and shit. Anyone who wants to work on it is free to.
Introduction. (This tutorial assumes that you have some basic knowledge of Lua scripting. In addition, some concepts from Lua/Custom player ability are referenced and expanded upon, so reading that tutorial may be a good idea.)
Getting started
Um...
The template map
I'll write this later. Final WAD will be [1] (note the back lower textures being set)
Ways of testing
There are three ways to test a script that relies on a WAD to work.
- Open a lump editor and add the script to your WAD, by putting it in a lump with a name starting in LUA_. This is the least convenient method, as it requires you to open up a lump editor every time you make a change to the script.
- Add the WAD and script as separate files. If using a launcher, this is a convenient method to test multiple files.
- Add a "+addfile
script
.lua" section to the custom parameters in your map editor's test settings. This requires no external programs and is good if you're modifying the map and the script a lot at the same time, but an extra WAD file may be needed for assets such as sprites if those are only declared in the Lua script.
Manipulating lines in a sector
Now we need a script to run. Make a new script file and put this in it:
addHook("ThinkFrame", function()
for player in players.iterate do
if player.mo.skin ~= "sonic" then
continue
end
if not (player.cmd.buttons & BT_CUSTOM1) then
player.c1tapready = true
player.c1tapping = false
elseif player.c1tapready then
player.c1tapping = true
player.c1tapready = false
else
player.c1tapping = false
end
if player.c1tapping then
LineManipTest(player) -- Important line
end
end
end)
This code is mostly copy-pasted from the Lua/Custom player ability tutorial. Reference that if you don't understand what's happening.
Note the line marked -- Important line
. We're going to be writing a new function to put our code in, in order to keep the script organized. Save this script somewhere in your SRB2 folder, say, as "playingwithsectors.lua".
Picking a line
There are many ways to choose a particular line to run an effect on. For this example, we'll demonstrate one method that may come in handy to people; picking the line in the object's sector that the object in question is facing. Begin by adding these two empty functions above your ThinkFrame hook:
local function MessWithLine(line)
end
local function LineManipTest(player)
end
We'll make LineManipTest call MessWithLine later. The purpose of this is to separate different parts of code; if you want to MessWithLine in other conditions, it's easier when it's a separate function you can call. Add the following to LineManipTest:
local function LineManipTest(player)
local sector = player.mo.subsector.sector
for line in lines.iterate do
if line.frontsector ~= sector and line.backsector ~= sector then
continue
end
end
end
(explanation goes here) I'm bored, I'll work more on this later