Hi guys! So, i have started playing around in the editor, and i came up withthis idea. Immediatedly as i saw the pickaxe in-game i thought it had some function like the shovel does, but it doesn't. Is it even possible to make the pickaxe do one of these:
1. Allow it to damage a cave-in
2. By right-clicking it in front of a cave-in, trigger a script.
2 Can also be done by always triggering a script and just checking if the character is in front of + facing a cave-in.
Thanks guys.
Destroying a cave-in with a pickaxe
Re: Destroying a cave-in with a pickaxe
Cool idea. Doesn't sound very hard. Maybe I'll write one this evening.
Re: Destroying a cave-in with a pickaxe
So I gave this a try and came up with this somewhat boilerplaty code (I crindged a little bit writing it)
What I do is, I get the entity in front of the party, check if its go name is a cave_in, if so I destroy it.
You should probably add some fancy effects/sounds or a shovel-dig like fade in/out to smooth that out
So yeah, that's it from me.
//edit: the code is bound to the pickaxe clone/whatever item you wish
//edit2: took the below advice to heart and voilá, somewhat tidier

SpoilerShow
Code: Select all
components = {
{
class="MeleeAttack",
onAttack = function(self)
local facing = party.facing
local level = party.level
local x = party.x
local y = party.y
local foundOne = false
local caveIns
--get entity in front of the party
if facing == 0 then
for e in Dungeon.getMap(level):entitiesAt(x,y-1) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
elseif facing == 1 then
for e in Dungeon.getMap(level):entitiesAt(x+1,y) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
elseif facing ==2 then
for e in Dungeon.getMap(level):entitiesAt(x,y+1) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
elseif facing == 3 then
for e in Dungeon.getMap(level):entitiesAt(x-1,y) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
foundOne = true
caveIns = e
end
end
else
return
end
--if it did find one then destroy it
if foundOne then
caveIns:destroy()
end
end
},
}
You should probably add some fancy effects/sounds or a shovel-dig like fade in/out to smooth that out

So yeah, that's it from me.
//edit: the code is bound to the pickaxe clone/whatever item you wish
//edit2: took the below advice to heart and voilá, somewhat tidier

SpoilerShow
Code: Select all
components = {
{
class="MeleeAttack",
onAttack = function(self)
local facing = party.facing
local level = party.level
local dx, dy = getForward(facing)
local inFrontX = party.x + dx
local inFrontY = party.y + dy
local foundOne = false
local caveIns
--get entity in front of the party
for e in Dungeon.getMap(level):entitiesAt(inFrontX,inFrontY) do
if e.name == "dungeon_cave_in" or e.name == "mine_cave_in" or e.name == "mine_moss_cave_in"then
e:destroy()
end
end
end
},
}
Last edited by swampie on Sun Nov 02, 2014 2:19 am, edited 2 times in total.
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Destroying a cave-in with a pickaxe
@Swampie: A little tip. Instead of doing 4 different cases depending on your facing, you can just do this...
Then you don't have to duplicate the code 4 times (which is generally a bad idea, because it's very easy to change one of the 4 blocks and forget to update the rest!).
Code: Select all
local dx,dy = getForward(facing)
local inFrontX = party.x + dx
local inFrontY = party.y + dy
for e in Dungeon.getMap(level):entitiesAt(inFrontX, inFrontY) do
...
end
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Re: Destroying a cave-in with a pickaxe
MeleeAttackComponent has an "onAttack" hook??? Well, that simplifies things ALOT 
Thank you!

Thank you!
Links to my YouTube playlist of "tutorials" and to my forum thread.
Re: Destroying a cave-in with a pickaxe
@JohnWordsworth Yeah, that's what I meant with boilerplatey
But, wow, I did oversee those two functions... would have made that somewhat easier, thank you.

But, wow, I did oversee those two functions... would have made that somewhat easier, thank you.