Skip to content

Instantly share code, notes, and snippets.

@xIvan0ff
Last active January 16, 2023 15:14
Show Gist options
  • Save xIvan0ff/85ee6db154612eba68ddae18e68dfcd0 to your computer and use it in GitHub Desktop.
Save xIvan0ff/85ee6db154612eba68ddae18e68dfcd0 to your computer and use it in GitHub Desktop.
-- Utility
string.startswith = function(self, str)
return self:find('^' .. str) ~= nil
end
function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end
local SpawnMobs = {
defaultRadius = 2,
defaultRespawnTime = 10, -- IN SECONDS! Emulator Default is 300 seconds
tempStayTime = 5 -- IN SECONDS!
}
function SpawnMobs.OnCommand(event, player, command)
if not player or player:GetGMRank() < 3 then
return
end
if command:startswith("spawnmobs") then
local args = split(command)
if #args >= 3 then
local entry = tonumber(args[2])
local count = tonumber(args[3])
local gridSize = tonumber(args[4]) or 1
local position = tostring(args[5]) or 'right'
local save = tostring(args[6]) or 'false'
local o = player:GetO() - math.pi / 2
local responseString = "You have spawned |cffffffff[%i]|r creatures with entry |cffffffff[%i]|r and name |cffffffff[%s]|r."
if position == "left" then
o = player:GetO() + math.pi / 2
end
local doSave = false
if save == "true" then
doSave = true
responseString = responseString .. " The creatures are |cffff0000saved|r to the database."
else
responseString = responseString .. string.format(" The creatures will disappear after |cffffffff[%i]|r seconds.", SpawnMobs.tempStayTime)
end
local g = 0
local i = 0
local exampleName = nil
repeat
local x, y, z, newO = GetPositionRelative(player, o, SpawnMobs.defaultRadius * i, true)
repeat
spawnedCreature = PerformIngameSpawn(1, entry, player:GetMapId(), player:GetInstanceId(), x, y, z, newO, doSave, SpawnMobs.tempStayTime * 1000)
x, y, z, newO = GetPositionRelative(spawnedCreature, spawnedCreature:GetO() - math.pi, SpawnMobs.defaultRadius, true)
if doSave then
spawnedCreature:SetRespawnDelay(SpawnMobs.defaultRespawnTime)
spawnedCreature:SaveToDB()
end
if exampleName == nil then
exampleName = spawnedCreature:GetName()
end
g = g + 1
until g == gridSize
i = i + 1
g = 0
until i == count
player:SendBroadcastMessage(string.format(responseString, count*gridSize, entry, exampleName))
elseif #args < 3 then
player:SendBroadcastMessage('### Usage: .spawnmobs #entryid #count <rows> <position: left/right> <save: true/false>')
end
return false
end
end
RegisterPlayerEvent(42, SpawnMobs.OnCommand)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment