Page 1 of 2
Spider Eggs
Posted: Sat Nov 08, 2014 3:32 pm
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
}
}
}
Re: Spider Eggs
Posted: Sat Nov 08, 2014 3:35 pm
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")
Re: Spider Eggs
Posted: Sat Nov 08, 2014 3:39 pm
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
}
}
}
Re: Spider Eggs
Posted: Sat Nov 08, 2014 6:46 pm
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
}
}
}
Re: Spider Eggs
Posted: Sat Nov 08, 2014 8:08 pm
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
}
}
}
Re: Spider Eggs
Posted: Sat Nov 08, 2014 10:05 pm
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.
Re: Spider Eggs
Posted: Sat Nov 08, 2014 10:32 pm
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
}
}
}
Re: Spider Eggs
Posted: Sat Nov 08, 2014 10:46 pm
by melierax
Hello Mysterious
Change your 0 for math.random(0, 3) work for me
Bye
Re: Spider Eggs
Posted: Sat Nov 08, 2014 11:01 pm
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)
Re: Spider Eggs
Posted: Sat Nov 08, 2014 11:11 pm
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