Any way to destroy entities?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
wizard341
Posts: 6
Joined: Fri Sep 21, 2012 3:30 am

Any way to destroy entities?

Post by wizard341 »

Looks like we can spawn entities but I don't see any documentation about destroying them. It's not a monster (it's a wall tapestry) so I can't fake the destruction by killing the monster. Anyone have a clever solution?
Whalefish
Posts: 15
Joined: Fri Mar 30, 2012 5:51 pm

Re: Any way to destroy entities?

Post by Whalefish »

No solution, but I want to know also if this is possible. I want to destroy dungeon_lamps to make it dark.
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

Re: Any way to destroy entities?

Post by antti »

There's no way to destroy or remove entities with script at the moment and I can't think of any workarounds right off the top of my head for tapestries either (monsters and items can often be teleported away).
Whalefish wrote:I want to destroy dungeon_lamps to make it dark.
You should be able to deactivate lamps.
Steven Seagal of gaming industry
User avatar
djoldgames
Posts: 107
Joined: Fri Mar 23, 2012 11:28 pm
Contact:

Re: Any way to destroy entities?

Post by djoldgames »

This will be the most awaited editor feature (opposite to spawn()).

For now it is only one choise only for items/monstares by using the teleportere.

- Build in your dungeon inaccesible room for your discarted items
- when specific item is placed on the floor, there must be a trigger (hidden pressure plate) connected to function1
- in function1 you must spawn the teleport (set triggered by item, invisible, silent, target to inaccesible room) if item is the right item
- build function2 connected to timer (1 second)
- in function2 disable the spawned teleport
- and activate them and after activate the counter

I thinig this might be working, but there will be too more spawned teleporters in the dungeon ;-))
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: Any way to destroy entities?

Post by Montis »

There's also a workaround with blockages (you can destroy those). If I have time later, I might post a small tutorial on how to create removable tunnel blockages.

Also, aren't tapestries destroyable anyway? At least the ones from the main game?
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: Any way to destroy entities?

Post by Montis »

Create a destructible tunnel blockage (will only look good from one direction):

add the following to your objects.lua

Code: Select all

cloneObject{
	name = "destructible_cave_in",
	baseObject = "dungeon_cave_in", -- you might want to change this to temple_cave_in or the prison one
	brokenModel = "assets/models/env/floor_dirt.fbx", -- if anyone can find a better standard model for this, give me a shout
	health = 50, -- adjust this to your needs
	evasion = -1000,
	hitEffect = "hit_dust",
	hitSound = "impact_generic",
	onProjectileHit = function()
		return false -- projectiles (arrows and such) shouldn't be able to destroy it
	end,
	onHit = false, -- this is used to negate the "indestructible" property
	onDie = function(self)
		-- when blockage is destroyed, spawn 2-5 rocks
		rocks = math.random(1,4)+1
		for i = 1,rocks do
			spawn("rock", self.level, self.x, self.y, i%4)
		end
	end
}
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
tymur
Posts: 27
Joined: Fri Jan 25, 2013 7:22 pm

Re: Useful scripts repository

Post by tymur »

Montis wrote:Create a destructible tunnel blockage
Will also spawn a random amount of rocks when destroyed.

add the following to your objects.lua
SpoilerShow

Code: Select all

cloneObject{
	name = "destructible_cave_in",
	baseObject = "dungeon_cave_in", -- you might want to change this to temple_cave_in or the prison one
	brokenModel = "assets/models/env/floor_dirt.fbx", -- if anyone can find a better standard model for this, give me a shout
	health = 50, -- adjust this to your needs
	evasion = -1000,
	hitEffect = "hit_dust",
	hitSound = "impact_generic",
	onProjectileHit = function()
		return false -- projectiles (arrows and such) shouldn't be able to destroy it
	end,
	onHit = false, -- this is used to negate the "indestructible" property
	onDie = function(self)
		-- when blockage is destroyed, spawn 2-5 rocks
		rocks = math.random(1,4)+1
		for i = 1,rocks do
			spawn("rock", self.level, self.x, self.y, i%4)
		end
	end
}
Then simply place it in a tunnel.

Notes:
  • This will only look good from one direction. If you want to create a tunnel that is destructible from two sides, you have to add a script in the "onDie" function. Beware of infinite loops though.
-----
original thread for discussion/questions:
viewtopic.php?f=14&t=3357
Is there any possibility set the destruction only by defined weapon (for example pickaxe)?
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: Useful scripts repository

Post by crisman »

tymur wrote:
Is there any possibility set the destruction only by defined weapon (for example pickaxe)?
Yes, there is.
It's a bit complicated but it's doable.
First, you must clone the party with an onAttack hook, like this:

Code: Select all

cloneObject{
	name = "party",
	baseObject = "party",
	onAttack = function (self, weapon)
		return damage.whatWeapon(self, weapon)
	end,
}
Then, clone the object you want to be destroyed by a specific weapon. (I use barrels/crates for example)

Code: Select all

cloneObject{
	name = "barrel",
	baseObject = "barrel_crate_block",
	onDamage = function (self, dmg, dmgType)
		return damage.checkDamage(self, dmg, dmgType)
	end,
	}
In the editor, place a script_entity and rename it as "damage".
then copy these scripts:

Code: Select all

usedWeapon = ""

function checkDamage(self, dmg, dmgType)

	if usedWeapon == "pickaxe" then
		usedWeapon = ""
		return true
	else
		usedWeapon = ""
		return false
	end
	
end

function whatWeapon(self, weapon)

	if weapon then
		usedWeapon = weapon.name
	end
	return true

end
That should do the trick.
tymur
Posts: 27
Joined: Fri Jan 25, 2013 7:22 pm

Re: Useful scripts repository

Post by tymur »

crisman wrote:
tymur wrote:
Is there any possibility set the destruction only by defined weapon (for example pickaxe)?
Yes, there is.
It's a bit complicated but it's doable.
First, you must clone the party with an onAttack hook, like this:

Code: Select all

cloneObject{
	name = "party",
	baseObject = "party",
	onAttack = function (self, weapon)
		return damage.whatWeapon(self, weapon)
	end,
}
Then, clone the object you want to be destroyed by a specific weapon. (I use barrels/crates for example)

Code: Select all

cloneObject{
	name = "barrel",
	baseObject = "barrel_crate_block",
	onDamage = function (self, dmg, dmgType)
		return damage.checkDamage(self, dmg, dmgType)
	end,
	}
In the editor, place a script_entity and rename it as "damage".
then copy these scripts:

Code: Select all

usedWeapon = ""

function checkDamage(self, dmg, dmgType)

	if usedWeapon == "pickaxe" then
		usedWeapon = ""
		return true
	else
		usedWeapon = ""
		return false
	end
	
end

function whatWeapon(self, weapon)

	if weapon then
		usedWeapon = weapon.name
	end
	return true

end
That should do the trick.
Than you very much, it very useful.
Post Reply