Jump to content

[AJUDA] getElementType


Recommended Posts

Quando utilizo isso:

function elementType(playerSource)
  
  if getPedOccupiedVehicle(playerSource) then
    local gET = getElementType(playerSource)
    
    outputChatBox("O seu tipo é:"..gET..".", playerSource, 255,255,255, true)
    
    end
  end
addCommandHandler("tipo", elementType)

o resultado sai: player e não vehicle, por quê? Como faço para sair vehicle?

Link to comment
  • Other Languages Moderators

Como vc quer que saia vehicle se vc está obtendo o tipo do playerSource?

function getMyVehType (thePlayer)
	if getPedOccupiedVehicle (thePlayer) then
		outputChatBox ("O seu tipo é: "..getElementType(getPedOccupiedVehicle (thePlayer))..".", thePlayer, 255,255,255)
	end
end
addCommandHandler ("tipo", getMyVehType)

 

  • Thanks 1
Link to comment
  • Moderators
3 hours ago, GM_Goulart said:

Mas é que como o getElementType está abaixo do getPedOccupiedVehicle, eu imaginei que ao pegar o tipo do elemento de playerSource que está dentro do carro o tipo seria vehicle.

'playerSource' será sempre a referência para a qual foi definida, a menos que seja explicitamente alterada código, por exemplo:

function elementType(playerSource)
  
  if getPedOccupiedVehicle(playerSource) then
    playerSource = getPedOccupiedVehicle(playerSource) -- playerSource aqui passa a ser o veículo do jogador
    local gET = getElementType(playerSource)
    
    outputChatBox("O seu tipo é:"..gET..".", playerSource, 255,255,255, true)
    
    end
  end
addCommandHandler("tipo", elementType)

Uma dica é sempre fazer outputs com os valores para entender a lógica e jamais faça o script tentando na sorte, você pode colocar um:

iprint("playerSource", playerSource, "vehicle", getPedOccupiedVehicle(playerSource), "element type", getElementType(playerSource))

 

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