Jump to content

Destroying a group of objects


Jeremy15

Recommended Posts

Hello community,

I am having some trouble with destroying a little group of objects.
I have managed to create a few billboards in 1 group but when i try to trigger the command to remove all of them. it just removes 1 object instead of them all

bill = {
[1] = {x = 4308.484375, y = -1278.0102539063, z = 354.45336914063, rotX = 0, rotY = 0, rotZ = 254.53720092773, Scale = 0.80000001};
[2] = {x = 4661.1708984375, y = -1298.7310791016, z = 157.84288024902, rotX = 0, rotY = 0, rotZ = 254.51000976563, Scale = 1.75};
[3] = {x = 4402.3256835938, y = 604.70196533203, z = 53.522163391113, rotX = 0, rotY = 0, rotZ = 270, Scale = 1.5};
[4] = {x = 6365.841796875, y = 2818.9069824219, z = 44.355319976807, rotX = 0, rotY = 0, rotZ = 0, Scale = 2};
[5] = {x = 1899.8275146484, y = 3626.1596679688, z = 62.15608215332, rotX = 0, rotY = 0, rotZ = 295.78491210938, Scale = 2.5};
[6] = {x = 3041.55078125, y = 3309.5639648438, z = 63.786605834961, rotX = 348, rotY = 0, rotZ = 20, Scale = 1};
[7] = {x = 7046.5922851563, y = 848.14624023438, z = 101.83802032471, rotX = 0, rotY = 0, rotZ = 215.10675048828, Scale = 2};
[8] = {x = 13.697020530701, y = -3669.009765625, z = 104.45007324219, rotX = 0, rotY = 0, rotZ = 180, Scale = 1.2};
[9] = {x = -367.28112792969, y = -4859.8872070313, z = 92.081260681152, rotX = 0, rotY = 0, rotZ = 90, Scale = 2.5};
}
bills = {}

stateMode = 0
function toggleBillboard(cmd)
	if isElement(getLocalPlayer()) then
		if stateMode == 0 then
			stateMode = stateMode + 1
			for i, bill in ipairs(bill) do
				object = createObject(7911, bill.x, bill.y, bill.z, bill.rotX, bill.rotY, bill.rotZ)
					setElementCollisionsEnabled(object, false)
					setElementFrozen(object, true)
					setObjectScale(object, bill.Scale)
				table.insert(bills, i)
			end
		else
			stateMode = 0
			for i, b in ipairs(bills) do
				destroyElement(b)
			end
		end
	end
end
addCommandHandler("toggleBills", toggleBillboard)

i don't know what i am doing wrong and i really need to get this done.

Link to comment

First loop is wrong. You're not actually storing the object in the table.

It should be like this:

for i, bill in ipairs(bill) do
	bills[i] = createObject(7911, bill.x, bill.y, bill.z, bill.rotX, bill.rotY, bill.rotZ)
	setElementCollisionsEnabled(bills[i], false)
	setElementFrozen(bills[i], true)
	setObjectScale(bills[i], bill.Scale)
end

 

Link to comment

Yes, what pa3ck said as well, I should've mentioned that, sorry. This is just the way I prefer to do it usually and it's also faster especially within a render. Usually I'd  write something like this:

for i=1,#bill do
	local bill = bill[i]
	bills[i] = createObject(7911, bill.x, bill.y, bill.z, bill.rotX, bill.rotY, bill.rotZ)
	setElementCollisionsEnabled(bills[i], false)
	setElementFrozen(bills[i], true)
	setObjectScale(bills[i], bill.Scale)
end

 

Edited by Tails
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...