Slime Bursters

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Slime Bursters

Post by Grimfan »

I have a type of slime that spawns a shockburst when it attacks a target. However, I now realize that the slime can attack in any direction, even into an area it's not facing (I think that might be a feature of the slime brain). Therefore the script I have below means that the shockburst only occasionally hits its target. How do I change the script below so that the shockburst activates into any square the slime is attacking (I assuming using getForward is not the way to go)?

Code: Select all

onAttack = function(self)
        local dx,dy = getForward(self.facing)
        local x,y = self.x + dx, self.y + dy
		spawn("shockburst", self.level, self.x + dx, self.y + dy, self.facing)
Thanks for any help guys (though this actually may be trickier than my usual requests). ;)
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Slime Bursters

Post by JohnWordsworth »

You can actually get two parameters from the onAttack script, which should help to give you the answer you are looking for...

Code: Select all

cloneObject {
	name = "sparky_slime",
	baseObject = "green_slime",
	onAttack = function(monster, attack_name) 
	  local attackFacing = monster.facing;   -- The default facing for normal attacks

	  if ( attack_name == "attackLeft" ) then attackFacing = (attackFacing - 1) % 4; 
	  elseif ( attack_name == "attackRight" ) then attackFacing = (attackFacing + 1) % 4; 
	  elseif ( attack_name == "attackBack" ) then attackFacing = (attackFacing + 2) % 4; 
	  end
	
	  local dx,dy = getForward(attackFacing);
	  spawn("shockburst", monster.level, monster.x + dx, monster.y + dy, attackFacing);
	end
}
The attack facing variable starts off in the direction that the monster is facing. However, the second parameter tells us if we are using an attack animation that means that the monster is attacking to the side / back. In this case, we have to shift the facing parameter by 1 or 2 steps left or right. The % 4 bit means "modulo 4", which means that the result is limited to (0, 1, 2 or 3) and will basically 'cycle' around if it your value goes outside of this set of values.

So, if facing is 3 and we see attack_name == "attack_back" then facing = 3 + 2 = 5. But 5 is not a valid value, but after '%4' it becomes 1 - which is valid.

This is untested - so there might be some errors above!
Last edited by JohnWordsworth on Sat Mar 23, 2013 9:14 pm, edited 4 times in total.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Slime Bursters

Post by Grimfan »

Unfortunately when I put this script in I get the warning that there is an "unexpected symbol next to { " and my dungeon won't open. When I take the curly brackets out (just to see whether the editor opes up) the editor starts up but as soon as the slime attacks the editor crashes ( I expected as much). It seems that the symbol that the curly brackets are having problems with is actually the word "then". :?

By the way, I can see what your script is trying to do. Pity I'm currently unable to execute it. :(
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Slime Bursters

Post by JohnWordsworth »

Sorry, it's meant to be 'then' followed by 'end', I fell back to curly-braces as I was programming in a different language at the same time as writing that. Lol. I've updated the post - that should work now!

I figured I would actually test it in the engine - the above code should work now :)
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: Slime Bursters

Post by Xanathar »

I fell back to curly-braces as I was programming in a different language
Happens to me. Every. Freaking. Time. :D
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Slime Bursters

Post by Grimfan »

This is working beautifully now. Thanks John! :D

And I never even knew that attack_name was a parameter. :o I do have a small question however. Your script uses semi-colons, yet I haven't seen them being used in any other script I can recall. What function do they serve?
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Slime Bursters

Post by JohnWordsworth »

Semi-colons are used in many programming languages to mark the end of a statement. They are actually completely optional in Lua, so they are only there for style purposes. I think the general convention with Lua is to omit them normally, unless you are putting multiple statements on a single line. I'm just in the habit of typing them, as I like the way that they explicitly say "this is the end of the command".

For instance, you can do...
a = 10 b = 2*a

And that is completely valid in Lua, but it's much easier to see that the above is actually two commands on one line (the first setting a to 10, and the second setting b to twice a) when there is a semi-colon;
a = 10; b = 2*a;

Granted, there isn't much use when you only have one statement per line - I just prefer the way it looks.
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Post Reply