Jump to content

Recommended Posts

alguém poderia explicar porque as funções 'entrando' e 'saindo' não estão funcionando? pls




local aSavePlaces = 
{
	{1587.1513671875, -1152.365234375,245, 160};  -- BOSS LS
	{2372.2763671875, 1836.701171875,150, 160};  -- BOSS LV
	{-2140.8330078125, 124.470703125,150, 185};  -- BOSS SF
}

local aRadarAreaPlaces = 
{

	{1587.1513671875, -1152.365234375,245, 160,255,0,0,100};  -- BOSS LS
	{2372.2763671875, 1836.701171875,150, 160,255,0,0,100};  -- BOSS LV
	{-2140.8330078125, 124.470703125,150, 185,255,0,0,100};  -- BOSS SF
}


function criandoareas( )

for _, a in ipairs( aRadarAreaPlaces ) do
				pRadarArea = createRadarArea ( unpack( a ) )
				setElementData( pRadarArea, "zombieProof", true )
			end	

for _, b in ipairs( aSavePlaces ) do
		        zona = createColRectangle ( unpack( b ) )				
			end		
			
addEventHandler ( "onColShapeHit", zona ,entrando) 			
addEventHandler ( "onColShapeLeave", zona , saindo)

end
addEventHandler ( "onResourceStart", resourceRoot,criandoareas)

							
function entrando( pHitElement )
	if getElementType( pHitElement ) == 'player' then	     
		 outputChatBox("[BOSS] - Você entrou em área BOSS.", pHitElement, 0, 145, 0, true)
	elseif getElementData(pHitElement,"zombie") and getElementType( pHitElement ) == 'ped' then
	    killPed(pHitElement)                          	
	end				
end


				
function saindo( pHitElement ) 
	if getElementType( pHitElement ) == 'player' then
     outputChatBox("[BOSS] - Você saiu da área BOSS.", pHitElement, 145, 0, 0, true)	
	elseif getElementData(pHitElement,"zombie") and getElementType( pHitElement ) == 'ped' then
	    killPed(pHitElement) 
	end
end

 

Link to comment

Teste assim: 

 

local aSavePlaces = 
{
	{1587.1513671875, -1152.365234375,245, 160};  -- BOSS LS
	{2372.2763671875, 1836.701171875,150, 160};  -- BOSS LV
	{-2140.8330078125, 124.470703125,150, 185};  -- BOSS SF
}

local aRadarAreaPlaces = 
{

	{1587.1513671875, -1152.365234375,245, 160,255,0,0,100};  -- BOSS LS
	{2372.2763671875, 1836.701171875,150, 160,255,0,0,100};  -- BOSS LV
	{-2140.8330078125, 124.470703125,150, 185,255,0,0,100};  -- BOSS SF
}


function criandoareas( )

for _, a in ipairs( aRadarAreaPlaces ) do
				pRadarArea = createRadarArea ( unpack( a ) )
				setElementData( pRadarArea, "zombieProof", true )
			end	

for _, b in ipairs( aSavePlaces ) do
		        zona = createColRectangle ( unpack( b ) )				
			end		
end
addEventHandler ( "onResourceStart", resourceRoot,criandoareas)

							
function entrando( pHitElement )
	if getElementType( pHitElement ) == 'player' then	     
		 outputChatBox("[BOSS] - Você entrou em área BOSS.", pHitElement, 0, 145, 0, true)
	elseif getElementData(pHitElement,"zombie") and getElementType( pHitElement ) == 'ped' then
	    killPed(pHitElement)                          	
	end				
end
addEventHandler ( "onColShapeHit", zona, entrando) 	

				
function saindo( pHitElement ) 
	if getElementType( pHitElement ) == 'player' then
     outputChatBox("[BOSS] - Você saiu da área BOSS.", pHitElement, 145, 0, 0, true)	
	elseif getElementData(pHitElement,"zombie") and getElementType( pHitElement ) == 'ped' then
	    killPed(pHitElement) 
	end
end		
addEventHandler ( "onColShapeLeave", zona, saindo)

 

 

  • Like 1
Link to comment

Cara como vc coloca uma elseif se nao tiver uma else antes ?..

 

If variavel then

Code.....

Else

Code.....

End

Posso estar viajando. Mais posso dizer que nunca vi isso nos codigos em que andei lendo.... mais a todo caso sempre tem a sua primeira vez.... a todo caso teste assim. Pode funcionar

If variavel then

Code..

Else

Linha em branco

Elseif variavel then

Code.......

End

function saindo( pHitElement ) 
	if getElementType( pHitElement ) == 'player' then
     outputChatBox("[BOSS] - Você saiu da área BOSS.", pHitElement, 145, 0, 0, true)
    else
    --linha em branco
	elseif getElementData(pHitElement,"zombie") and getElementType( pHitElement ) == 'ped' then
	    killPed(pHitElement) 
	end
end		
addEventHandler ( "onColShapeLeave", zona, saindo)

 

  • Like 1
Link to comment
  • Other Languages Moderators

Na verdade elseif sempre vem antes do else.

if condition then -- Se for isso, então:
  --code
elseif condition then -- Senão se for isso, então:
  --code2
else -- Senão:
  return false
end

O else sozinho indica uma condição de escape final, se não entrar em nenhuma condição anterior, ele vai entrar obrigatoriamente nesse else pois ele não tem condição.

O elseif nada mais é do que um segundo if, que será verificado somente se não entrar no if anterior (ou elseif anterior). Se o if anterior for verdadeiro, ele não vai entrar neste elseif.

Também é possível colocar if seguido de outro if, para casos específicos onde você quer que sejam executadas as duas condições simultaneamente. Para fazer isso é necessário fechar o escopo do if anterior para abrir o outro.

if condition then
  --code
end

if condition then
  --code2
end

Se colocar elseif sem ter um if anterior em aberto, está errado.
Se colocar um else sem ter pelo menos um if anterior em aberto, está errado. Pode não ter elseif anterior.
Se colocar qualquer condição após um else em aberto, está errado pois ele nunca irá entrar nesta condição. Exceto se a condição estiver dentro do escopo do else.
Se colocar condição no else, está errado.
Se fechar o escopo de um if antes do elseif ou else, está errado pois eles precisam de um if em aberto para ter else. O if só deve ser fechado após os elses.
Os elses são fechados automaticamente ao fechar o primeiro if. Ou seja, apenas um end para todos eles já basta.

--------------------------------------------------------

A propósito @Marcos^v7, não use nomes iguais de parâmetros diferentes para funções diferentes. Na sua função de saída, você está chamando o mesmo elemento de entrada, isso pode causar conflito. Substitua o parâmetro pHitElement por pLeaveElement.

function saindo (pLeaveElement) 
  if getElementType (pLeaveElement) == 'player' then
    outputChatBox ("[BOSS] - Você saiu da área BOSS.", pLeaveElement, 145, 0, 0, true)
  elseif getElementData (pLeaveElement, "zombie") and getElementType (pLeaveElement) == 'ped' then
    killPed (pLeaveElement)
  end
end

 

Edited by Lord Henry
  • Like 2
Link to comment

Porque a função não está pegando?  :oops:

Alguém ajude por favor.



-- Formato: {x = 0, y = 0, width = 0, height = 0},
local aSavePlaces = 
{
	{x = 1587.1513671875, y = -1152.365234375, width = 245, height = 160},  -- BOSS LS
	{x = 2372.2763671875, y = 1836.701171875, width = 150, height = 160},  -- BOSS LV
	{x = -2140.8330078125, y = 124.470703125, width = 150, height = 185},  -- BOSS SF
}

local aRadarAreaPlaces = 
{

	{1587.1513, -1152.3652,245, 160,255,0,0,100},  -- BOSS LS
	{2372.2763, 1836.7011,150, 160,255,0,0,100},  -- BOSS LV
	{-2140.8330, 124.4707,150, 185,255,0,0,100},  -- BOSS SF
}


function criandoareas( )
--local display = textCreateDisplay () 
--local text = textCreateTextItem("Em Zona Segura!", 0.9, 0.7, "high", 0, 255, 0, 255, 2, "right", "bottom") 
--textDisplayAddText(display, text) 
						
for _, a in ipairs( aRadarAreaPlaces ) do
			
				pRadarArea = createRadarArea ( unpack( a ) )
				setElementData( pRadarArea, "zombieProof", true )
			    	
            
end

for _, b in ipairs( aSavePlaces ) do				
    if b then 
	outputChatBox("@b: "..tostring(b))
	    if b.x and b.y and b.width and b.height then
		outputChatBox("@b.x: "..tostring(b.x))
		outputChatBox("@b.y: "..tostring(b.y))
		outputChatBox("@b.width: "..tostring(b.width))
		outputChatBox("@b.height: "..tostring(b.height))
				 zona = createColRectangle (b.x, b.y, b.width, b.height)
         outputChatBox("@zona: "..tostring(zona))				 
        end
	end		
end		
			
		addEventHandler ( "onColShapeHit", zona ,
			function ( pHitElement )
	if getElementType( pHitElement ) == 'player' then	  
	    --textDisplayAddObserver(display, pHitElement) 
     	outputChatBox("@pHitElement: "..tostring(pHitElement))
		outputChatBox("[BOSS] - Você entrou em área BOSS.", pHitElement, 0, 145, 0, true)	
	end
	
	if getElementData(pHitElement,"zombie") and getElementType( pHitElement ) == 'ped' then
	    killPed(pHitElement)                          	
	end				
end
		) 
            
			
		addEventHandler ( "onColShapeLeave", zona , 			
function (pLeaveElement) 
   if getElementType (pLeaveElement) == 'player' then
	    --textDisplayRemoveObserver(display, pLeaveElement) 
        outputChatBox ("[BOSS] - Você saiu da área BOSS.", pLeaveElement, 145, 0, 0, true)
   end
	  
	  if getElementData (pLeaveElement, "zombie") and getElementType (pLeaveElement) == 'ped' then
        killPed (pLeaveElement)
      end
end
      	)

end 
addEventHandler ( "onResourceStart", resourceRoot,criandoareas)
@b: table: 06EDE618
@b.x: 1587.1513671875
@b.y: -1152.365234375
@b.width: 245
@b.height: 160
@zona: userdata: 000010CE
----
@b: table: 06EDE5F0
@b.x: 2372.2763671875
@b.y: 1836.701171875
@b.width: 150
@b.height: 160
@zona: userdata: 000010CF
----
@b: table: 06EDE6B8
@b.x: -2140.8330078125
@b.y: 124.470703125
@b.width: 150
@b.height: 185
@zona: userdata: 000010D0

Sem erros no debugscript 3

Edited by Marcos^v7
Link to comment
  • Moderators

Esqueceram o x da questão :| O problema é que você usa uma variável pra criar todos retângulos de colisão num loop, mas oque fica, é a última col da tabela.

Apenas coloque resourceRoot, no lugar de 'zona' em onColShapeHit/Leave. E sobre a váriável zona, você pode tirar ela. E pRadarArea deixe local.

  • Like 1
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...