Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Configuration ]]
- --[[ Temps en secondes entre chaque nouveau spawn ]]
- local delay = 5
- -- [[ Nombre d'exécution de spawn ( 0 = infini ) ]]
- local repetitions = 0
- --[[ Classe de l'entité à faire spawn ]]
- local entityClass = "gmod_button"
- -- [[ Point de spawn ( ne pas modifier 'use = false' )]]
- local pos = {
- [1] = {
- pos = Vector(0, 0, 0),
- use = false
- },
- [2] = {
- pos = Vector(1, 1, 1),
- use = false
- },
- [3] = {
- pos = Vector(2, 2, 2),
- use = false
- },
- [4] = {
- pos = Vector(3, 3, 3),
- use = false
- },
- [5] = {
- pos = Vector(4, 4, 4),
- use = false
- }
- }
- --[[ Fin de la configuration ]]
- local oldEnt
- local function getSpawnPos()
- local posUtilisable = {}
- -- On garde uniquement les positions non utilisés dans le cycle
- for _, data in ipairs( pos ) do
- if ( !data.use ) then
- table.insert(posUtilisable, data.pos)
- end
- end
- -- Si aucune position n'est disponible alors on commence un nouveau cycle
- if ( #posUtilisable <= 0 ) then
- for _, data in ipairs( pos ) do
- data.use = false
- end
- return getSpawnPos()
- end
- -- On récupère de façon aléatoire le point de spawn
- local spawnPos = posUtilisable[math.Rand(1, #posUtilisable)]
- -- On retient que ce point de spawn est désormais utilisé dans le cycle
- for _, data in ipairs( pos ) do
- if ( data.pos == spawnPos ) then
- date.use = true
- break
- end
- end
- -- On transmet le point de spawn
- return spawnPos
- end
- timer.Create("RespawnMyEnt", delay, repetitions, function()
- local myEnt = ents.Create(entityClass)
- myEnt:SetPos(getSpawnPos())
- myEnt:Spawn()
- if ( IsValid( oldEnt ) ) then
- oldEnt:Remove()
- end
- oldEnt = myEnt
- end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement