OnSpawningEntity
#1
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
Reply
Thanks given by:
#2
try some debugging like use
print(Entity:GetClass())
to see what it returns etc.
Reply
Thanks given by:
#3
Are there named constants for biomes? If so, you should use them.

Also, wolves can spawn in tundra and forest AFAIK.
Reply
Thanks given by:
#4
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
Reply
Thanks given by:
#5
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:
biOcean            = 0,
biPlains           = 1,
biDesert           = 2,
biExtremeHills     = 3,
biForest           = 4,
biTaiga            = 5,
biSwampland        = 6,
biRiver            = 7,
biHell             = 8,  // same as Nether
biNether           = 8,
biSky              = 9,
biFrozenOcean      = 10,
biFrozenRiver      = 11,
biIcePlains        = 12,
biTundra           = 12,  // same as Ice Plains
biIceMountains     = 13,
biMushroomIsland   = 14,
biMushroomShore    = 15,
biBeach            = 16,
biDesertHills      = 17,
biForestHills      = 18,
biTaigaHills       = 19,
biExtremeHillsEdge = 20,
biJungle           = 21,
biJungleHills      = 22,
Reply
Thanks given by:
#6
But with OnSpawningEntity the entity hasn't spawned yet so he could not get the coords with the cEntity:GetPos() functions.
Reply
Thanks given by:
#7
It seemed to work in his examples above.
Reply
Thanks given by:
#8
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.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)