Jump to content

[HELP] Tables


Recommended Posts

Hello community,,

i need help in how to create a table and store blips on it. bec i made a hit system and i need when the player dies all the blips get destroyed not only the last one who used the command .. here is the code i want to add tables on it.

function consoleCreateObject ( thePlayer, commandName, id ) 
  if ( thePlayer ) then 
  teamElement = getPlayerTeam( thePlayer ) 
  if getTeamName(teamElement) == "Camorra" then 
      local x, y, z = getElementPosition ( thePlayer ) 
      object = createObject ( tonumber(id), x, y, z, 0, 0, 0 ) 
      if ( object ) then 
         outputChatBox ( "Created Your Camorra group object",thePlayer,0,255,0, false ) 
      else 
      if not ( object ) then 
      outputChatBox ( "Error Wrong Element ID",thePlayer,255,0,0, false ) 
      else 
      if getTeamName(teamElement) ~= "Camorra" then 
         outputChatBox ( "You have to be in Camorra group to use this command",thePlayer,255,0,0, false ) 
      end 
   end 
end 
end 
end 
end 
addCommandHandler ( "create", consoleCreateObject ) 
  
function fady ( thePlayer, commandName ) 
 if ( thePlayer ) then 
  teamElement = getPlayerTeam( thePlayer ) 
  if getTeamName(teamElement) == "Camorra" then 
  destroyElement ( object ) 
  outputChatBox ( "You have destroyed objects that you create",thePlayer,0,255,0, false ) 
  else 
  cancelEvent () 
  end 
  end 
  end 
  addCommandHandler ( "destroyobjects", fady ) 

i want when i do /destroyobjects, then all objects get destroyed not onlt the last object as it did now ..

Link to comment

http://www.lua.org/pil/2.5.html

blips = { } -- Defines a table called 'blips' with no elements in it. 
  
function consoleCreateObject ( thePlayer, commandName, id ) 
    if ( thePlayer ) then 
        teamElement = getPlayerTeam( thePlayer ) 
            if getTeamName(teamElement) == "Camorra" then 
                local x, y, z = getElementPosition ( thePlayer ) 
                local object = createObject ( tonumber(id), x, y, z, 0, 0, 0 ) -- You want it to be local so you can only use the variable in this function. 
                table.insert( blips, object ) -- Insert the object into a table here. Read more on the LUA programming reference about tables. 
                if ( object ) then 
                    outputChatBox ( "Created Your Camorra group object",thePlayer,0,255,0, false ) 
                else 
                    if not ( object ) then 
                        outputChatBox ( "Error Wrong Element ID",thePlayer,255,0,0, false ) 
                    else 
                        if getTeamName(teamElement) ~= "Camorra" then 
                            outputChatBox ( "You have to be in Camorra group to use this command",thePlayer,255,0,0, false ) 
                        end 
                    end 
                end 
            end 
    end 
end 
  
function destroyEverything( ) 
    for key, object in ipairs( blips ) do -- We loop through the entire blips table.. 
        destroyElement( object ) -- ..and destroy all objects. 
    end 
end 
addCommandHandler( "destroyobjects", getRootElement( ), destroyEverything ) 

Script is untested.

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