Page 1 of 2
Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 11:34 am
by pandemo
Hi all,
Been following and reading on these forums for some time now and have had lots of help from you guys. Thanks!
However I have now run in to two problems that I can not solve.
1. I want the party, as they step on a hidden pressure plate to lose all torches in their inventory. Either by swapping them for burned out ones or by simply destroying them.
At the same time I want a hudPrint message to be displayed, one for "if" and one for "else". I simply can not make this work (al tough it was kinda late last night
)
I tried so many different things I managed to break my script completely last night and here are the remains. I shall have a closer look again once I get back home from uni.
--TRASIGT SKRIPT!!
function RemoveInventoryTorch()
for RemoveTorch() do
then removeItem("torch")
hudPrint("Your torches fizzle and dies,
--no matter what they refuse to burn")
hudPrint("fuuuc")
else hudPrint("you already wonder in darkness")
end
end
end
2. I want a secret door to be connected to a button on the wall. As you press the button a timer starts that will close the door. The player will not be able to run to the door in time before it closes but must take a secret teleporter to get there in time.
I just can't make the damn timer to start and I don't understand what I am doing wrong to be honest.
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 11:40 am
by Komag
That script is a mess, but I'm also not quite sure how to handle taking/replacing torches, so I can't really answer it fully. But about printing messages, it would be something like this:
Code: Select all
if blahblah() then
hudPrint("Your torches fizzle and die,\nno matter what they refuse to burn")
hudPrint("Nooooo!")
else
hudPrint("you already wander in darkness")
end
for the button/timer:
- connect your button to the door (to open it)
- also connect your button to the timer with Event - "toggle" --> Action - "activate"
- connect the timer to the door (to close it)
- connect the timer to itself (to deactivate itself)("activate" --> "deactivate")
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 11:59 am
by Wolfrug
Code: Select all
function removeTorches()
local hastorches = false
for i=1,4 do
for v=1,31 do
if party:getChampion(i):getItem(v).name == "torch" then party:getChampion(i):getItem(v):destroy() hastorches = true end
end
end
if hastorches then hudPrint ("All your torches fizzle and die") else hudPrint ("Since you have no torches, none of them fizzle and die lol") end
end
Might work. Not sure if you can put that many :'s in a row, but if you can't you just need to add another step to it.
-Wolfrug
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 1:00 pm
by Decayer
It should be noted that Wolfrug's solution won't affect torches inside containers.
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 1:10 pm
by Grimwold
Decayer wrote:It should be noted that Wolfrug's solution won't affect torches inside containers.
Yeah, at present there is no solution for items in containers. The developers are aware of this and I believe it is on their to-do list.
You may be able to find a way round that by denying the player from putting torches in containers.. though I have not investigated this myself.
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 1:14 pm
by pandemo
Wolfrug wrote:Code: Select all
function removeTorches()
local hastorches = false
for i=1,4 do
for v=1,31 do
if party:getChampion(i):getItem(v).name == "torch" then party:getChampion(i):getItem(v):destroy() hastorches = true end
end
end
if hastorches then hudPrint ("All your torches fizzle and die") else hudPrint ("Since you have no torches, none of them fizzle and die lol") end
end
Might work. Not sure if you can put that many :'s in a row, but if you can't you just need to add another step to it.
-Wolfrug[/quote]
Wow thanks for the quick answers
When I try the code from Wolfrug I get an error "attempt to index a nil value"
I want this script to activate when walking over a hidden pressure plate.
Thank you Komag! I sat and changed activate, deactivate so many time last night I thought I would smash my keyboard
Just a question of curiosity, why do I need to link it to itself?
Thanks again
Marcus
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 1:15 pm
by Neikun
Grimwold wrote:Decayer wrote:It should be noted that Wolfrug's solution won't affect torches inside containers.
Yeah, at present there is no solution for items in containers. The developers are aware of this and I believe it is on their to-do list.
You may be able to find a way round that by denying the player from putting torches in containers.. though I have not investigated this myself.
When they try, be like "Who puts a torch in a box?!"
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 1:16 pm
by pandemo
EDIT: It is not a problem for containers since the player will not have more than 1 max 2 torches by this stage. One which most certainly have burned out.
also Komag, I thought the exact thing last night but my problem is I can not select an activate status for the counter... And I just realised I have been using a counter and not a timer...
Pandemo
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 1:43 pm
by Komag
timer Events are only activate, counter Events are activate, deactivate, any. Don't mix up Event and Action.
You have the timer connect to itself and Action deactivate so that it doesn't forever repeatedly try to close the door every so-many-seconds
Re: Removing all items of one kind script (torch)
Posted: Tue Oct 30, 2012 3:53 pm
by Wolfrug
pandemo wrote:
When I try the code from Wolfrug I get an error "attempt to index a nil value"
Ah right. Stupid Lua. It's because you're not carrying something in every slot, so it returns nil. Let's see:
Code: Select all
function removeTorches()
local hastorches = false
for i=1,4 do
for v=1,31 do
if party:getChampion(i):getItem(v) ~= nil then
if party:getChampion(i):getItem(v).name == "torch" then party:getChampion(i):getItem(v):destroy() hastorches = true
end
end
end
end
if hastorches then hudPrint ("All your torches fizzle and die") else hudPrint ("Since you have no torches, none of them fizzle and die lol") end
end
Try that instead? (haven't got LoG here to test it)
-Wolfrug