Posts: 1,162
Threads: 68
Joined: Mar 2013
Thanks: 245
Given 127 thank(s) in 101 post(s)
08-09-2013, 04:27 AM
(This post was last modified: 08-09-2013, 04:28 AM by tonibm19.)
I'm trying to make a plugin that makes sure mobs spawn in the right biome.
Here's the code.
Code: function OnSpawningEntity(World, Entity)
if (Entity:GetClass() == "wolf" and World:GetBiomeAt(Entity:GetPosX(),Entity:GetPosZ()) ~= 4) then
Entity:Destroy()
end
end
It don't works, wolves spawn everywhere.
I don't get any error in console
Posts: 4,636
Threads: 115
Joined: Dec 2011
Thanks: 697
Given 502 thank(s) in 429 post(s)
try some debugging like use to see what it returns etc.
Posts: 1,469
Threads: 57
Joined: Jul 2012
Thanks: 66
Given 128 thank(s) in 109 post(s)
Are there named constants for biomes? If so, you should use them.
Also, wolves can spawn in tundra and forest AFAIK.
Posts: 1,162
Threads: 68
Joined: Mar 2013
Thanks: 245
Given 127 thank(s) in 101 post(s)
08-09-2013, 05:05 AM
(This post was last modified: 08-09-2013, 05:10 AM by tonibm19.)
I tried with this:
Code: function OnSpawningEntity(World, Entity)
print(Entity:GetClass())
if (Entity:GetClass() == "cWolf" and World:GetBiomeAt(Entity:GetPosX(),Entity:GetPosZ()) ~= 4)then
print(Entity:GetClass().." spawning on "..World:GetBiomeAt(Entity:GetPosX(),Entity:GetPosZ()))
Entity:Destroy()
end
end
All works except destroy the entity. I'll try with OnSpawnedEntity, because if entity is not spawned, you can't destroy it
Now it work, but when entity is destroyed, you see it, and can't interact with it. It seems entity is removed from server but not from client.
Code:
Code: function OnSpawnedEntity(World, Entity)
print(Entity:GetClass())
if (Entity:GetClass() == "cWolf" and World:GetBiomeAt(Entity:GetPosX(),Entity:GetPosZ()) ~= 4)then
print(Entity:GetClass().." spawning on "..World:GetBiomeAt(Entity:GetPosX(),Entity:GetPosZ()))
Entity:Destroy()
end
end
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1081 thank(s) in 853 post(s)
Use the OnSpawningEntity() hook and return true if you don't want the entity to spawn.
Also, as Bearbin said, use named constants for biomes: biForest, biTundra etc. Here's a list:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | biOcean = 0,
biPlains = 1,
biDesert = 2,
biExtremeHills = 3,
biForest = 4,
biTaiga = 5,
biSwampland = 6,
biRiver = 7,
biHell = 8,
biNether = 8,
biSky = 9,
biFrozenOcean = 10,
biFrozenRiver = 11,
biIcePlains = 12,
biTundra = 12,
biIceMountains = 13,
biMushroomIsland = 14,
biMushroomShore = 15,
biBeach = 16,
biDesertHills = 17,
biForestHills = 18,
biTaigaHills = 19,
biExtremeHillsEdge = 20,
biJungle = 21,
biJungleHills = 22,
|
Posts: 4,636
Threads: 115
Joined: Dec 2011
Thanks: 697
Given 502 thank(s) in 429 post(s)
But with OnSpawningEntity the entity hasn't spawned yet so he could not get the coords with the cEntity:GetPos() functions.
Posts: 1,469
Threads: 57
Joined: Jul 2012
Thanks: 66
Given 128 thank(s) in 109 post(s)
It seemed to work in his examples above.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1081 thank(s) in 853 post(s)
The entity hasn't spawned, but its coords should already be valid. The hook is supposed to make that available, so that plugins may nudge the entity a bit.
|