Create Darkness Zone
extinguish torch held by the party and prevent the light spell to be cast
I heavily based this idea on the
"Anti-Magic Zone" proposed by
Grimwold with contributions from
JohnWordsworth and
Wolfrug.
The idea is the create a zone or a room where the party cannot use torches or the light spell.
This can still be improved because at the moment the player can still use a torch stored in the party inventory while standing still, but if the party moves the torch is extinguished.
Also the light effect of the Orb of radiance is not affected by this script, I really don't know how to affect it...
- Add required custom objects to objects.lua to signify the spaces where darkness prevails and create an empty torch to handle the extinguished torch effect.
I just followed the exemple of the anti magic zone here, and added the empty torch that will replace any torch the party is actually holding.
Code: Select all
cloneObject{
name = "darkness_zone",
baseObject = "pressure_plate_hidden",
editorIcon = 96,
}
cloneObject{
name = "torch_extinguished",
baseObject = "torch",
fuel = 0,
}
- Create a clone of the party in init.lua to add an onCastSpell hook and an onMove hook (or add the hooks to an existing party clone if you use one)
Same here, I just followed existing exemple to add custom hooks to the party clone.
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onCastSpell = function(caster, spell)
return darkness_script.CheckDarkness(caster, spell)
end,
onMove = function(party,direction)
return darkness_script.CheckParty()
end,
}
- (Optional but recommended) - Add custom sound effect simulating a torch beeing extinguished in the sounds.lua from your scripts folder.
Search for a royalty free sound effect a fire, a cigarette or a match beeing extinguished on the internet and place the file in the sounds folder of your dungeon.
I have found one here : http://www.freesound.org/
If you use the sound be sure to uncomment the lines referring to playing the sound in the next step (i.e the lines : playSound("extinguish_torch"))
Code: Select all
defineSound{
name = "extinguish_torch",
filename = "mod_assets/sounds/extinguish.wav",
loop = false,
volume = 0.2,
minDistance = 1,
maxDistance = 1,
}
- In your dungeon create a script entity called darkness_script and add the following functions
Code: Select all
function CheckDarkness(caster, spell)
if spell == "light" then
for entity in entitiesAt(party.level,party.x,party.y) do
if entity.name == "darkness_zone" then
hudPrint(caster:getName() .. "'s spell fizzles because of the surrounding darkness")
return false
end
end
end
return true
end
function CheckParty()
for entity in entitiesAt(party.level,party.x,party.y) do
if entity.name == "darkness_zone" then
CheckTorch(party,direction)
end
end
return true
end
function CheckTorch()
local currentItem
local champion
local printMessage = false
for champID=1,4 do
champion = party:getChampion(champID)
currentItem = champion:getItem(7)
if currentItem ~= nil then
if currentItem.name == "torch"
or currentItem.name == "torch_everburning" then
champion:removeItem(7)
champion:insertItem(7,spawn("torch_extinguished"))
printMessage = true
--playSound("extinguish_torch")
end
end
currentItem = champion:getItem(8)
if currentItem ~= nil then
if currentItem.name == "torch"
or currentItem.name == "torch_everburning" then
champion:removeItem(8)
champion:insertItem(8,spawn("torch_extinguished"))
printMessage = true
--playSound("extinguish_torch")
end
end
end
if printMessage then
hudPrint("the party's torch is suddenly extinguished by some unknown force")
end
end
- Place your newly defined darkness_zone objects on your map in the places where you want to prevent the party to use the light spell and torches.
When a player attempts to cast the
light spell while stood on one of the darkness tiles the spell will fail and a message will be printed to the hud saying why the spell fizzled.
When the party move one tile in any direction from a darkness tile to another, all torches held by any champion in either hand will be replaced by an extinguished version of the torch.
For a better atmosphere boost in this part of your dungeon remove any light source near the darness zone and add a few silent monsters here and there...
---------------------------
by Wanderer » Fri Jan 18, 2013 2:39 pm
Hi, refering to the posting "Creating Darkness Zones" I have found a workaround to prevent the player to use Torches even when the player stands still.
Here is how I did it: While I have changed nothing to the functions etc. listet in the posting, I have created a Timer wich is activated when entering the darkness-zone-object in the dungeon (through connector) with a interval of 0. As long as the player stand on the Zone-object the timer checks the three main functions in the scriptentity (lua) of the Darknesszone Object.
(like it also be checked when entering the object by the object itself). But instead of only checking the three functions at once by entering (checkdarkness(), checkparty(), checktorch() ), the timer checks it as long as the player stand on the darkness-zone. When the player leaves the darkness-field the timer is deactivated and the player can use a torch again (or cast a light spell).
I have testet this now for a while and stepped through several darknessobjects in a 3x3 room, and it works really very well for me. Even before the player make a attempt to give someone a torch, the torch extinguishes.
The only line what could be added to this thing is, to cast a darkness-spell also on the party (in case the party already has a Light-Spell casted before).
lg Wanderer