I'd like to make a puzzle where the player has to protect some sort of object. Let's just say a health crystal for talking point.
Basically the health crystal would be in the middle of the room and enemies would head towards the crystal instead of the party. When they reach it they start attacking it. (Health crystal would of course need a health value which I've already done in a previous dungeon.)
Any ideas for the code for the enemies? Also would they be able to handle more than one Health Crystal? Would I be able to add in like 2 or 3 of them in the room so they would have to pay attention to where all the mobs are compared to the crystals?
Second question is any ideas on how to do the following:
Basically I'd like to make a special poison cloud that when the player touch's it their screen turns slightly green and they have (x) seconds to reach a special spot in a room to remove the status effect or they die.
Enemies attacked to object/Curse Party
- zimberzimber
- Posts: 432
- Joined: Fri Feb 08, 2013 8:06 pm
Re: Enemies attacked to object/Curse Party
1) You'll have to write a custom brain for the monsters you'll be using for the invasion, where they will move towards the crystal (or a point from which they can hit it), and if the crystal is in distance for one of the attacks, execute that attack.
The attack definition will require to either spawn a tile damage to deal damager to the objective, or to directly alter its health. (I suggest using a tile damager)
I think you'll find this link very helpful - [link]
You can use multiples objectives, but that will require some extra work. You'll have to make the brain find the closest objective (or a specific one) and have it go towards. Can be done by comparing the objectives location in comparison to the monster, then telling it to go towards the closest one.
Something like...
There's probably a better way to do this, but that's what I could come up with right now. Just so you know, this method is not versatile at all.
2) You can make something like that, yeah.
Have the poison cloud apply a custom condition when it deals damage to a champion
Set the conditions time to the time you want to give the party to reach the safe spot
Have the condition deal 999 'pure' damage to the champion through its onStop function
Give the safe spot a hidden floor trigger that will remove the condition with champion:removeCondition() (this doesn't trigger onStop())
For the screen effect, you can have the tile damager apply a screen effect, but only if no champions are afflicted by the custom condition. (to prevent it re-starting)
Since telling the game to play a screen effect stops the previous one, you can play a screen effect that does nothing. (Or one that is like the previous one, but fades out instead)
Keep in mind that using teleporters, getting hit by some projectiles, and firebursting a wall(thus hitting yourself) will also remove the effect.
Since I was planning to add to my dungeon something similar to what you requested, I have a ready particle that I'm willing to share!
(Some numbers are exaggerated for testing purposes)
The image file:

EDIT: Changed distance formula to Taxicab, as suggested by minmay.
The attack definition will require to either spawn a tile damage to deal damager to the objective, or to directly alter its health. (I suggest using a tile damager)
I think you'll find this link very helpful - [link]
You can use multiples objectives, but that will require some extra work. You'll have to make the brain find the closest objective (or a specific one) and have it go towards. Can be done by comparing the objectives location in comparison to the monster, then telling it to go towards the closest one.
Something like...
Code: Select all
local mx, my = self.go:getWorldPosition().x, self.go:getWorldPosition().y
local ax,ay = objective_1:getWorldPosition().x, objective_1:getWorldPosition().y
local bx,by = objective_2:getWorldPosition().x, objective_2:getWorldPosition().y
local cx,cy = objective_3:getWorldPosition().x, objective_3:getWorldPosition().y
local aDist = math.abs(ax - mx) + math.abs(ay - my) -- distance formula
local bDist = math.abs(bx - mx) + math.abs(by - my)
local cDist = math.abs(cx - mx) + math.abs(cy - my)
if aDist < bDist and aDist < cDist then
-- go towards objective_1
elseif bDist < aDist and bDist < cDist then
-- go towards objective_2
else
-- go towards objective_3
end
2) You can make something like that, yeah.
Have the poison cloud apply a custom condition when it deals damage to a champion
Set the conditions time to the time you want to give the party to reach the safe spot
Have the condition deal 999 'pure' damage to the champion through its onStop function
Give the safe spot a hidden floor trigger that will remove the condition with champion:removeCondition() (this doesn't trigger onStop())
For the screen effect, you can have the tile damager apply a screen effect, but only if no champions are afflicted by the custom condition. (to prevent it re-starting)
Since telling the game to play a screen effect stops the previous one, you can play a screen effect that does nothing. (Or one that is like the previous one, but fades out instead)
Keep in mind that using teleporters, getting hit by some projectiles, and firebursting a wall(thus hitting yourself) will also remove the effect.
Since I was planning to add to my dungeon something similar to what you requested, I have a ready particle that I'm willing to share!

(Some numbers are exaggerated for testing purposes)
Code: Select all
defineParticleSystem{
name = "toxic_screen",
emitters = {
{
spawnBurst = true,
emissionRate = 1,
emissionTime = 0,
maxParticles = 1,
boxMin = {0,0,1},
boxMax = {0,0,1},
sprayAngle = {0,30},
velocity = {0,0},
texture = "mod_assets/textures/particles/glow_inverted.tga",
lifetime = {999*999, 999*999},
colorAnimation = false,
color0 = {0.1, 3, 0.1},
opacity = 0.6,
fadeIn = 60,
fadeOut = 5,
size = {3, 3},
gravity = {0,0,0},
airResistance = 1,
rotationSpeed = 0.5,
blendMode = "Translucent",
objectSpace = true,
}
}
}

EDIT: Changed distance formula to Taxicab, as suggested by minmay.
Last edited by zimberzimber on Thu Dec 22, 2016 1:02 pm, edited 1 time in total.
Re: Enemies attacked to object/Curse Party
For finding the closest target you should use Taxicab distance (xdist+ydist) instead of Euclidean distance (sqrt(xdist+ydist)), since monsters, the party, and most projectiles in Grimrock all move in Taxicab space.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
- zimberzimber
- Posts: 432
- Joined: Fri Feb 08, 2013 8:06 pm
Re: Enemies attacked to object/Curse Party
Full formula would be like this?minmay wrote:For finding the closest target you should use Taxicab distance (xdist+ydist) instead of Euclidean distance (sqrt(xdist+ydist)), since monsters, the party, and most projectiles in Grimrock all move in Taxicab space.
Code: Select all
math.abs(ax - bx) + math.abs(ay - by)
Re: Enemies attacked to object/Curse Party
Yes, exactly.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.