local NewObject_mt = {}
NewObject_mt.__index = NewObject_mt
function NewObject_mt:Delete()
for k, v in ipairs(Object.Pool) do
if v.Handle == self.Handle then
table.remove(Object.Pool, k)
end
end
deleteObject(self.Handle)
end
function NewObject_mt:SetHeading(angle)
setObjectHeading(self.Handle, angle)
end
function NewObject_mt:SetRotation(rotationVector)
setObjectRotation(self.Handle, rotationVector.x, rotationVector.y, rotationVector.z)
end
function NewObject_mt:GetPos()
local result, x, y, z = getObjectCoordinates(self.Handle)
return result and Vec3(x, y, z) or Vec3(0, 0, 0)
end
local Object_mt = {}
Object_mt.__index = Object_mt
setmetatable(Object, Object_mt)
function Object_mt:Add(Tag, modelId, pos, scale, rotate, heading, nocollision)
local Result, Handle = pcall(createObject, modelId, pos.x, pos.y, pos.z)
assert(Result, 'Error creating object with tag "'..Tag..'": '..Handle)
if Result then
if scale then setObjectScale(Handle, scale) end
if rotate then setObjectRotation(Handle, rotate.x or 0, rotate.y or 0, rotate.z or 0) end
if heading then setObjectHeading(Handle, heading) end
if nocollision then setObjectCollision(Handle, not nocollision) end
local NewObject = { Handle = Handle, Tag = Tag or '__none__', Pos = pos }
setmetatable(NewObject, NewObject_mt)
table.insert(Object.Pool, NewObject)
return Object.Pool[#Object.Pool]
else
print('ERROR CREATING OBJECT:', Handle)
end
end
function Object_mt::DestroyAll()
-->> Delete objects
for k, v in ipairs(getAllObjects()) do
for ind, data in ipairs(Object.Pool) do
if v == data.Handle then
table.remove(Object.Pool, ind)
deleteObject(v)
break
end
end
end
-->> Delete bot
if doesCharExist(Map.Bot) then
deleteChar(Map.Bot)
end
end
function Object_mt::GetByTag(tag)
local result = {}
for k, v in ipairs(Object.Pool) do
if v.Tag:find(tag) then
table.insert(result, v)
end
end
return result
end
function Object_mt::GetByFullTag()
local result = {}
for k, v in ipairs(Object.Pool) do
if v.Tag == tag then
return v
end
end
return nil
end