//ShowEffect(src.loc,'Effects.dmi',"HollowHide")
if(istype(src,/mob/Pets)) src.loc=null
else
src.loc=locate(rand(2,199),rand(2,199),30)
spawn(rand(30,60))//300,600
if(!src.RespawnZ)
for(var/atom/x in src.Cache) del x
del src;return
if(istype(src,/mob/Enemy)) src:LevelShift(initial(src.Level))
src.loc=locate(src.RespawnX+rand(-1,1),src.RespawnY+rand(-1,1),src.RespawnZ)
//ShowEffect(src.loc,'Effects.dmi',"EnergyBall")
Problem description:
This code I have causes usage to go up. If I killed 100 mobs at a time, the usage will go upto 60%-80%. What would be a better way to respawn mobs where lots of them can be killed without causing extreme usage. I could understand if it's upto 10%. But if a single player is killing 100 mobs that cause 60% usage, then if there's 10 players all killing 1000 mobs, the usage will be even higher, which can cause players to freeze up.
On top of your Respawn() function, just add
sleep(rand(5, 50))
Edit the values as you like. But beside adding some time to the whole thing, you'd spread the load over more time, thus reduce CPU use.
Enabling background on your Respawn function in addition to this could also help.