Page 1 of 1
Spawn a lot of torches
Posted: Tue Oct 02, 2012 7:18 pm
by Dinasty
Hello all, i'm very noob on scripting but I'm working on my custom dungeon.
Please, i need that when the players place the "red gem" on the altar, all the torches spawns in the room (only once, and only where there aren't torches).
is this possible?
(sorry for bad english, but i'm italian

)
Re: Spawn a lot of torches
Posted: Tue Oct 02, 2012 9:44 pm
by Komag
yeah, that can be done, no problem, although it might be a little complex if you're new to scripting.
Basically, run a check on each torch holder whether it has a torch in it or not:
if it does, then you will do nothing. if it doesn't, then you'll add a torch to it:
and finally, you will set the whole script to only run once. one way to do that is to connect the trigger event (red gem on altar) to a counter with the count of 1, and link the counter to the script. The first time the gem is placed, the counter will reach 0 and trigger the script, but subsequent gem placements will only further reduce the counter and it will never hit 0 again.
Re: Spawn a lot of torches
Posted: Wed Oct 03, 2012 11:07 am
by Dinasty
There is a way to use 2 function in a single one?
I read this "
http://www.grimrock.net/modding/how-to- ... ve-puzzle/" and i want that "When you place red fragment on the altar all the torches spawns in the room".
I try this but it doesn t work
Code: Select all
function itemPuzzle()
-- Test Altar and Torches
for i in altar_sud:containedItems() do
if i.name == "red_fragment" then
for i in allEntities(party.level) do
if i.name == "torch_holder" then
i:addTorch()
end
end
end
end
end
end
Can someone post me the right code please? Thanks!
Re: Spawn a lot of torches
Posted: Wed Oct 03, 2012 11:31 am
by Blichew
Dinasty wrote:
Code: Select all
function itemPuzzle()
-- Test Altar and Torches
for i in altar_sud:containedItems() do
if i.name == "red_fragment" then
for i in allEntities(party.level) do
if i.name == "torch_holder" then
i:addTorch()
end
end
end
end
end
end
Can someone post me the right code please? Thanks!
I think you can't use another for loop with the same variable ("i") inside another loop.
Also: you have too many "end"s.
So, try this:
Code: Select all
function itemPuzzle()
-- Test Altar and Torches
for altarItem in altar_sud:containedItems() do
if altarItem.name == "red_fragment" then
for i in allEntities(party.level) do
if i.name == "torch_holder" then
i:addTorch()
end
end
end
end
end
Re: Spawn a lot of torches
Posted: Wed Oct 03, 2012 12:21 pm
by Dinasty
Very thanks! It works

but...
How can i run it only once? I try to deselect "Activate Always" from the Altar, but every time i put the red gem on the altar he play the sound i have set!
Re: Spawn a lot of torches
Posted: Wed Oct 03, 2012 12:29 pm
by Komag
involve a counter in the script
Code: Select all
mycounter = 1
function itemPuzzle()
for altarItem in altar_sud:containedItems() do
if altarItem.name == "red_fragment" then
if mycounter == 1 then
for i in allEntities(party.level) do
if i.name == "torch_holder" then
i:addTorch()
mycounter = 0
end
end
end
end
end
end
Re: Spawn a lot of torches
Posted: Wed Oct 03, 2012 12:50 pm
by Blichew
You could also check if i:hasTorch() returns false, if so - i:addTorch().
This won't prevent the script from running a loop until it checks all entities.
Code: Select all
function itemPuzzle()
-- Test Altar and Torches
for altarItem in altar_sud:containedItems() do
if altarItem.name == "red_fragment" then
for i in allEntities(party.level) do
if i.name == "torch_holder" and i:hasTorch() == false then
i:addTorch()
end
end
end
end
end
Re: Spawn a lot of torches
Posted: Wed Oct 03, 2012 2:02 pm
by Dinasty
very thanks to all! i just complete my first level of my custom dungeon *_*