Removing all items of one kind script (torch)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
pandemo
Posts: 10
Joined: Tue Oct 30, 2012 11:18 am

Removing all items of one kind script (torch)

Post 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 :P )

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.
SpoilerShow
--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.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Removing all items of one kind script (torch)

Post 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")
Finished Dungeons - complete mods to play
User avatar
Wolfrug
Posts: 55
Joined: Wed Oct 03, 2012 6:56 pm

Re: Removing all items of one kind script (torch)

Post 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
Try my Mordor: Depths of Dejenol LoG-ification. Feedback much appreciated!
Decayer
Posts: 65
Joined: Sat Oct 13, 2012 3:19 pm

Re: Removing all items of one kind script (torch)

Post by Decayer »

It should be noted that Wolfrug's solution won't affect torches inside containers.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Removing all items of one kind script (torch)

Post 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.
pandemo
Posts: 10
Joined: Tue Oct 30, 2012 11:18 am

Re: Removing all items of one kind script (torch)

Post by pandemo »

SpoilerShow
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 :lol:
Just a question of curiosity, why do I need to link it to itself?

Thanks again

Marcus
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Removing all items of one kind script (torch)

Post 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?!"
"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
  • Message me to join in!
pandemo
Posts: 10
Joined: Tue Oct 30, 2012 11:18 am

Re: Removing all items of one kind script (torch)

Post 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
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Removing all items of one kind script (torch)

Post 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
Finished Dungeons - complete mods to play
User avatar
Wolfrug
Posts: 55
Joined: Wed Oct 03, 2012 6:56 pm

Re: Removing all items of one kind script (torch)

Post 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
Try my Mordor: Depths of Dejenol LoG-ification. Feedback much appreciated!
Post Reply