hallo Leute,
ich hab ein kleines problem mit OOP - CVehicle:destroyVehicle()
Lua
CVehicle = {}
CVehicle.__index = CVehicle
CVehicle.instances = {}
function CVehicle:create()
local id = #CVehicle.instances+1
CVehicle.instances[id] = setmetatable(
{
id = id,
model = nil,
posX = nil,
posY = nil,
posZ = nil,
rotX = nil,
rotY = nil,
rotZ = nil,
numberplate = nil,
vehicle = nil
},
self
)
return CVehicle.instances[id]
end
function CVehicle:setVehicle(model, x,y,z,rx,ry,rz,num)
self.vehicle = createVehicle( model, x,y,z,rx,ry,rz, num )
end
function CVehicle:destroyVehicle()
destroyElement( self.vehicle )
table.remove( CVehicle.instances, tonumber(CVehicle.instances[self.id]) )
end
--
addCommandHandler('create',
function() local x,y,z = getElementPosition(getLocalPlayer())
local obj = CVehicle:create()
CVehicle:setVehicle(411, x+5,y,z,0,0,0,tostring(obj.id))
outputChatBox( "Vehicle hat die ID "..tostring(obj.id).."!", 0, 255, 0 )
end,
false, false)
addCommandHandler("delete",
function( command, ID )
if not tonumber( ID ) then outputChatBox( "Ungueltige ID", 255, 0, 0 ) return end
if CVehicle.instances[tonumber(ID)] then
CVehicle.instances[tonumber(ID)]:destroyVehicle()
else
outputChatBox( "Die angegebene Vehicle existiert nicht!", 255, 0, 0 )
end
end
, false, false )
Alles anzeigen
hilft mir bitte