[Help] Remove torch from holder script?
- DrMadolite
- Posts: 27
- Joined: Mon Nov 05, 2012 10:26 pm
- Location: Norway
[Help] Remove torch from holder script?
Hey guys, I'm trying to make a script where a torch is removed from its holder when a pressure plate is stepped on. Simple enough, but I'm still fussy on LUA syntax Any help?
Thanks in advance.
Thanks in advance.
Last edited by DrMadolite on Wed Nov 14, 2012 1:41 am, edited 1 time in total.
The torch is your friend.
Re: [Help] Remove torch from holder script?
A clunky workaround might be to destroy the torch holder with the torch in it while simultaneously spawning an empty one?
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
- Message me to join in!
- DrMadolite
- Posts: 27
- Joined: Mon Nov 05, 2012 10:26 pm
- Location: Norway
Re: [Help] Remove torch from holder script?
How do you do that? I'm sorry, I'm a complete newbie.Neikun wrote:A clunky workaround might be to destroy the torch holder with the torch in it while simultaneously spawning an empty one?
The torch is your friend.
Re: [Help] Remove torch from holder script?
You can destroy it with
<your torch name>: destroy()
As for spawning a torch hodler on a wall, I'm a little fuzzier on the details.
<your torch name>: destroy()
As for spawning a torch hodler on a wall, I'm a little fuzzier on the details.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
- Message me to join in!
Re: [Help] Remove torch from holder script?
You'll have to take the coordinates of the torch holder. the script should looks like:
function torches()
torch_holder_i:destroy()
spawn("torch_holder", party.level, x, y, facing, "torch_holder_i")
--gave an ID to the torch holder so you can repeat the script as you wish
end
Ps: this script will only extinguish the torch inside the torch holder. I think its a beautiful effect!!
If you want to actually destroy the torch, well... I'll have to figure it out, because, right now, I don't know
function torches()
torch_holder_i:destroy()
spawn("torch_holder", party.level, x, y, facing, "torch_holder_i")
--gave an ID to the torch holder so you can repeat the script as you wish
end
Ps: this script will only extinguish the torch inside the torch holder. I think its a beautiful effect!!
If you want to actually destroy the torch, well... I'll have to figure it out, because, right now, I don't know
- DrMadolite
- Posts: 27
- Joined: Mon Nov 05, 2012 10:26 pm
- Location: Norway
Re: [Help] Remove torch from holder script?
Ok thanks guys. I decided not to use this event though, as I found another interesting puzzle algorithm. Plus I just wanna be done with my dungeon soon, without spending too much time learning advanced LUA.
Cheers.
Cheers.
The torch is your friend.
Re: [Help] Remove torch from holder script?
Here is some code that I found solved this issue for me. It will remove the old torch holder, any torches, and then spawn a new one. It is um... ugly, but hey it works.
Just updated the code. Should have made it check for torches or items with names like "torch", and not remove everything
Code: Select all
function leftEyeRemoved()
-- cycle through items at my torch holder location
for k in entitiesAt(party.level, 4, 17) do
-- if the items name has "torch" then destroy/remove the item
if string.find(k.name, "torch") then
k:destroy()
end
end
-- Spawn a new torch holder at the exact same location, with the same id. This allows for continued use if desired
spawn("torch_holder", party.level, 4, 17, 3, "eyeTorchLeft")
end
Re: [Help] Remove torch from holder script?
This little trick helped me immensely. I actually set out to do the same thing as the original poster: remove a torch from it's holder. But that torch holder also has about five connectors. After destroying it and replacing it, how can I add the connectors again? I've tried adding lines after the spawn line with "torchholder:addconnector()" but I get this error: "attempt to index global 'torch_holder_10' (a nil value)". Here's my code...crisman wrote:You'll have to take the coordinates of the torch holder. the script should looks like:
Ps: this script will only extinguish the torch inside the torch holder. I think its a beautiful effect!!Code: Select all
function torches() torch_holder_i:destroy() spawn("torch_holder", party.level, x, y, facing, "torch_holder_i") --gave an ID to the torch holder so you can repeat the script as you wish end
If you want to actually destroy the torch, well... I'll have to figure it out, because, right now, I don't know
Code: Select all
-- Starts a timer for function torchSnuffed()
-- extinguishes a torch placed in the holder after 1 second.
function noTorch4U()
if torch_holder_10:hasTorch() == true then
timer_noTorch4U:activate()
end
end
-- appears to snuff out the torch in the holder by destroying
-- the holder and instantly adding a new one.
function torchSnuffed()
torch_holder_10:destroy()
spawn("torch_holder", party.level, 21, 5, 1, "torch_holder__10")
torch_holder_10:addConnector("activate", temple_door_darkness, "close")
end
--gave an ID to the torch holder so you can repeat the script as you wish
- DesperateGames
- Posts: 90
- Joined: Sun Oct 06, 2013 1:54 pm
Re: [Help] Remove torch from holder script?
Have not tested it, but the issue seems to be that the ID of the newly spawned torchholder has a double underscore __ in it:
"torch_holder__10"
This is why you can't attach the connectors because "torch_holder_10" does not exist anymore
Besides this, this procedure should work, I have done a similiar thing in my mod.
"torch_holder__10"
This is why you can't attach the connectors because "torch_holder_10" does not exist anymore
Besides this, this procedure should work, I have done a similiar thing in my mod.
Re: [Help] Remove torch from holder script?
whoooops. Thank you for pointing out that typo. Now the error to the addConnector problem is "bad argument #2 to 'addConnector' (string expected, got table). I wish I knew what that meant. It turned out to be another problem like the typo.
Since I've just been guessing using other people's code from the forum, I sometimes have to experiment with punctuation and syntax. So I tried putting the id of the door in quotes and that seemed to fix my next problem. Works like a charm now! Thanks again!
The corrected code should read (DestroysTorchLight is the name of my script with the following two functions. the connectors could be anything one wants them to be, but mine end up teleporting the party out the door they just came in and unceremoniously slamming it behind them as the torch is snuffed out):
Since I've just been guessing using other people's code from the forum, I sometimes have to experiment with punctuation and syntax. So I tried putting the id of the door in quotes and that seemed to fix my next problem. Works like a charm now! Thanks again!
The corrected code should read (DestroysTorchLight is the name of my script with the following two functions. the connectors could be anything one wants them to be, but mine end up teleporting the party out the door they just came in and unceremoniously slamming it behind them as the torch is snuffed out):
Code: Select all
-- Starts a timer for function torchSnuffed()
-- extinguishes a torch placed in the holder after 1 second.
function noTorch4U()
if torch_holder_10:hasTorch() == true then
timer_noTorch4U:activate()
end
end
-- appears to snuff out the torch in the holder by destroying
-- the holder and instantly adding a new one.
function torchSnuffed()
torch_holder_10:destroy()
spawn("torch_holder", party.level, 21, 5, 1, "torch_holder_10")
torch_holder_10:addConnector("activate", "teleporter_5", "activate")
torch_holder_10:addConnector("activate", "timer_1", "activate")
torch_holder_10:addConnector("activate", "timer_2", "activate")
torch_holder_10:addConnector("activate", "teleporter_9", "activate")
torch_holder_10:addConnector("activate", "DestroysTorchlight", "noTorch4U")
end
--gave an ID to the torch holder so you can repeat the script as you wish