Jump to content

Help with command, it's works but WARNING in console


Mikhail

Recommended Posts

Spoiler

barreratbl = {}
 
 function consoleCreateObject ( player, commandName )
 if exports.factions:isPlayerInFaction(player, 1) then
      local x, y, z = getElementPosition ( player ) -- get the player's position
      -- create a Object next to the player:
      obb = createObject ( 1228, x + 2, y , z, 0, 0, 0 )
	  table.insert (barreratbl, obb)
	  if (obb) then
			outputChatBox("Barrier created",player,0,255,0)
		else
			outputChatBox("Barrier not created",player,255,0,0)
		end
		
else 
outputChatBox("You aren't FCPD!!",player,255,0,0)
end
end
addCommandHandler ( "barrera", consoleCreateObject )



 function consoleCreateObject ( player, commandName )
 if exports.factions:isPlayerInFaction(player, 1) then
		for i, v in pairs (barreratbl) do
		destroyElement ( v )-- check if the Obeject was created successfully
      	end
		outputChatBox("The object was removed!!",player,0,255,0)
else 
outputConsole ( "you aren't FCPD!!", player )
   end
end

 

 

 when i put the comand many times and created more than 1 barrier..

and put "/sacarbarrera"  they are removed but with 1 problems..

1-  WARNING: com\com.lua:138: Bad argument @ 'destroyElement' [Expected element at argument 1]  [DUP x4]

 

please help! im new in scripting..

Edited by Mikhail
Link to comment

Or you can check that are there any element exist before destroy it.

 
barreratbl = {}
 
function consoleCreateObject ( player, commandName )
    if exports.factions:isPlayerInFaction(player, 1) then
      local x, y, z = getElementPosition ( player ) -- get the player's position
        -- create a Object next to the player:
        obb = createObject ( 1228, x + 2, y , z, 0, 0, 0 )
	    table.insert (barreratbl, obb)
	    if (obb) then
			outputChatBox("Barrier created",player,0,255,0)
		else
			outputChatBox("Barrier not created",player,255,0,0)
		end
	else 
        outputChatBox("You aren't FCPD!!",player,255,0,0)
    end
end
addCommandHandler ( "barrera", consoleCreateObject )



function consoleCreateObject ( player, commandName )
    if exports.factions:isPlayerInFaction(player, 1) then
	  for i, v in pairs (barreratbl) do
               if isElement( v ) then
		        destroyElement ( v )-- check if the Obeject was created successfully
			outputChatBox("The object was removed!!",player,0,255,0)
               end
          end
    else 
        outputConsole ( "you aren't FCPD!!", player )
   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...