Making an entity spawn on server start and respawn after breaking.

I use a mod that has a rock. This rock gives ores and after 10 ores, it depletes and destroys itself.
I would much appreciate it if someone could write or give me some help with a script that forces this entity to spawn and once destroyed, it respawns after five minutes.

Thanks!

The entity’s name is “eof_rock”

take the code that spawns it every 5 minutes, call it when entity is destroyed

He meant he wants it to respawn after 5 minutes after the entity is destroyed not that it already does that.

Use ents.Create for the entity and use a timer to remove the entity after 5 minutes and spawn it again.
Just make a fresh rock.

Timer: http://wiki.garrysmod.com/page/timer/Simple

Remove: http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index92d2.html

I would suggest editing the entity to have two different states such as normal and depleted and have your logic inside of that instead of removing / recreating the entity every time.

I currently have some code but it does not work. Help please ^^


--File for respawning Rocks from the Rock Recycling Facory addon.
--These positons are to be used for rp_evocity_v2d_sexy and only that map
 
function SpawnRocks()
 
        --Spawn Rocks
        local rock1 = ents.Create("eof_rock")
        local rock2 = ents.Create("eof_rock")
        local rock3 = ents.Create("eof_rock")
        local rock4 = ents.Create("eof_rock")
       
        --Set the position of the rocks.
        rock1:setPos(Vector(-6009, 1209, 94))
        rock2:setPos(Vector(4403, -1095, 80))
        rock3:setPos(Vector(-1784, 614, 28))
        rock4:setPos(Vector(1277, -1299, 150))
       
        --Set angle of entities
        rock1:SetAngles(Angle(0,0,0))
        rock2:SetAngles(Angle(0,0,0))
        rock3:SetAngles(Angle(0,0,0))
        rock4:SetAngles(Angle(0,0,0))
       
        --Set owner
        rock1:SetNWString("Owner", "World")
        rock2:SetNWString("Owner", "World")
        rock3:SetNWString("Owner", "World")
        rock4:SetNWString("Owner", "World")
       
        --Spawn the entities.
        rock1:Spawn();
        rock2:Spawn();
        rock3:Spawn();
        rock4:Spawn();
       
        --Activate entities
        rock1:Activate()
        rock2:Activate()
        rock3:Activate()
        rock4:Activate()
       
end
hook.Add("InitPostEntity", "SpawnRocks", SpawnRocks)

BUMP can some one please add the code to make the rocks respawn? I also need this to work on my own server.

Cheers!

Pseudocode
edit eof_rock and add something like this.
[lua]function ENTITY:OnRemove( )
if CLIENT then return end
local pos = self:GetPos()
local newrock = ents.Create(“eof_rock”)
newrock:SetPos(pos)
newrock:SetAngles(Angle(0,0,0))
newrock:SetNWString(“Owner”, “World”)
timer.Simple(60*5, function() newrock:Spawn() newrock:Activate())
end[/lua]

OnRemove would work to have it respawn itself, but you also need to add the code to remove itself ( look at ScaleEntityDamage / OnEntityTakeDamage hooks to see when the entity is damage / destroyed ). When it is destroyed you can add a timer to remove in x time, or remove it right away and have a timer like the OnRemove code above which spawns it in 5 minutes ( although I recommend putting all of the creation code in the timer instead of just the spawn / activate portion ).