Jump to content

Strings as variables?


TrickyTommy

Recommended Posts

Hi. I am making an interior system, alongside with a siren-system. I noticed, that whenever want to destroy (only just one siren), the other sirens, in other cars stop as well.

The problem's description:
I spawn 2 vehicles, and sound a siren in them, i sit into one of the 2 active sirening vehicles, and i stop the siren of the car i am sitting in, but the siren stops in the 2nd car too.

And i want to make an interior system, already made it's tables, but after i get all the interior entrances from the database, with for k, v and i want to spawn a marker for each interior's entrance, but if i would do it like local interiorEntrance = createMarker (database results) and whenever i want to use it, it will not work correctly, because of the 30 interiors i made so far variable name is the same.

This would be a solution, but it does not work.
"INT:"..interiorID.."" = createMarker (...)

How should i fix it?

Edited by TrickyTommy
Link to comment
  • Moderators

siren-system

Not enough context to help you with this.

 

For the interior.

Use createElement and set it's children.

 

local newElement = createElement("interiorEntrance", "interiorEntrance:" .. interiorID)

for i=1, 30 do
	local marker = createMarker (...)
	setElementParent(marker, newElement)
end

 

destroyElement(newElement) -- will also destroy it's children.

 

 

Syntax createElement:

element createElement ( string elementType, [ string elementID = nil ] )

 

 

Edited by IIYAMA
  • Thanks 1
Link to comment

If you're using the default MTA siren system, there are no siren objects that you need to reference in order to remove them from a vehicle. You just do: 

removeVehicleSirens(source)

If you have your own objects that you attach, you can use the same concept idarrr suggested:

local sirens = {}

addCommandHandler("addsirens", function(p)
    local veh = getPedOccupiedVehicle(p)
    local obj1 = createObject(..)
    local obj2 = createObject(..)
    
    attachElements(obj1, veh)
    attachElements(obj2, veh)
    
    sirens[veh] = { obj1, obj2 }
    
end)

addCommandHandler("removesirens", function(p)
    local veh = getPedOccupiedVehicle(p)
    if sirens[veh] then
      	for k, obj in ipairs(sirens[veh]) do
        	destroyElement(obj)
      	end
      	sirens[veh] = null
    end
end)

 

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...