Page 1 of 1

Any way to destroy entities?

Posted: Tue Sep 25, 2012 5:03 am
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?

Re: Any way to destroy entities?

Posted: Tue Sep 25, 2012 9:12 am
by Whalefish
No solution, but I want to know also if this is possible. I want to destroy dungeon_lamps to make it dark.

Re: Any way to destroy entities?

Posted: Tue Sep 25, 2012 9:30 am
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.

Re: Any way to destroy entities?

Posted: Tue Sep 25, 2012 9:42 am
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 ;-))

Re: Any way to destroy entities?

Posted: Tue Sep 25, 2012 10:23 am
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?

Re: Any way to destroy entities?

Posted: Tue Sep 25, 2012 12:01 pm
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
}

Re: Useful scripts repository

Posted: Thu Feb 07, 2013 1:46 pm
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)?

Re: Useful scripts repository

Posted: Thu Feb 07, 2013 3:46 pm
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.

Re: Useful scripts repository

Posted: Thu Feb 07, 2013 4:20 pm
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.