Spider Eggs

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Spider Eggs

Post by Mysterious »

Hi I am truing to make a spider egg object that when it die it spawn a poison cloud on the party. I tried this and it crashes lol. I am not sure if the poison_cloud_medium is correct. Any ideas on this??

Code: Select all

defineObject {
	name = "spider_eggs_hatching_poison",
	baseObject = "spider_eggs",
	components = {
	{
	class = "Health",
	health = 60,

onDie = function(self)
	spawn("poison_cloud_medium", self.level, self.x, self.y,0,0)
		party.party:shakeCamera(0.6,1)
end

      }
	  }
	  }
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Spider Eggs

Post by petri »

"self" refers to the Health component in this case, and components do not have properties such as x, y and level. Either use self.go to access the game object, or even better use the gameobject to spawn the poison cloud at the location of the egg:

Code: Select all

self.go:spawn("poison_cloud_medium")
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Spider Eggs

Post by Mysterious »

Hi. so I don't need to use this (spawn("poison_cloud_medium", self.level, self.x, self.y,0,0) just self.go:spawn("poison_cloud_medium") awesome thxs for the reply :)

EDIT: Ok I did what you said and sorry it still crashed :(

Code: Select all

defineObject {
	name = "spider_eggs_hatching_poison",
	baseObject = "spider_eggs",
	components = {
	{
	class = "Health",
	health = 60,

onDie = function(self)
	self.go:spawn("poison_cloud_medium")
		party.party:shakeCamera(0.6,1)
end

      }
	  }
	  }
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Spider Eggs

Post by Doridion »

Could it be better like that ?

Code: Select all

defineObject {
   name = "spider_eggs_hatching_poison",
   baseObject = "spider_eggs",
   components = {
      {
      class = "Health",
      health = 60,
      onDie = function(self)
         self.go:spawn("poison_cloud_medium", party.level, party.x, party.y, 0, party.elevation)
         party.party:shakeCamera(0.6,1)
      end
      }
   }
}
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Spider Eggs

Post by Prozail »

It might be the same problem as in this: viewtopic.php?f=22&t=8142

Edit: Yup.. was the same problem.. onDie keeps calling itself recursivly if you do it like that.
Try this.

Code: Select all


defineObject {
	name = "spider_eggs_hatching_poison",
	baseObject = "spider_eggs",
	components = {
	{
		class = "Health",
		health = 60,
		onDie = function(self)
			if self.done then return end
			self.go:spawn("poison_cloud_medium")
			party.party:shakeCamera(0.6,1)
			self.done = 1
		end
		}
	}
}

User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Spider Eggs

Post by JKos »

User defined component properties are not serialized to save games. In this case it's not a problem but I just thought to share this info.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Spider Eggs

Post by Mysterious »

Hi thxs for the code guys :) awesome.

Prozail yours works very well. Although the cloud does not hit the party as intended, but still awesome man :) I tried your code Doridion, but it crashed. At least it works thxs.

Now I have the following:

Spider egg: Poison cloud. (thxs to you guys).
Spider egg: Spawns a big spider onDie
Spider egg: Spawns those cute little spiders running around.

Barrels that give random food: Here is the code it works, but the food is spawned in one position (0) I would like the food to spawn in all 4 directions eg 0 ,1,2,3. I know it's not the best code, I am not good at coding thattts why I ask questions lol. I am going to make more barrels that spawn othere items eg: bullets etc..

Code: Select all

defineObject{
name = "breakable_food_barrel",
baseObject = "barrel_crate_block",
components = {
{

class = "Health",
health = 15,

onDie = function(self)
local foodList = {"ice_lizard_steak", "baked_maggot", "boiled_beetle", "rat_shank", "pitroot_bread", "herder_cap"}
local many = math.random(1, 4)
local facing = (party.facing + 2)%4

for i = 1, many do
spawn(foodList[math.random(1, #foodList)], self.go.level, self.go.x, self.go.y, 0, self.go.elevation)

end
	end

}
}
}
User avatar
melierax
Posts: 29
Joined: Sat Oct 27, 2012 2:08 am
Location: Quebec, Canada

Re: Spider Eggs

Post by melierax »

Hello Mysterious

Change your 0 for math.random(0, 3) work for me :)

Bye
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: Spider Eggs

Post by Mysterious »

melierax wrote:Hello Mysterious

Change your 0 for math.random(0, 3) work for me :)

Bye
Do you mean:

spawn(foodList[math.random(1,3 #foodList)], self.go.level, self.go.x, self.go.y, 0, self.go.elevation)
User avatar
melierax
Posts: 29
Joined: Sat Oct 27, 2012 2:08 am
Location: Quebec, Canada

Re: Spider Eggs

Post by melierax »

No

Change this

spawn(foodList[math.random(1, #foodList)], self.go.level, self.go.x, self.go.y, 0, self.go.elevation)

for this

spawn(foodList[math.random(1, #foodList)], self.go.level, self.go.x, self.go.y, math.random(0, 3), self.go.elevation)

Bye
Post Reply