Jump to content

[Ajuda] Destruir veiculo quando o player sair


Recommended Posts

Tudo bem? Queria saber como faço para quando o player sair do servidor destruir o veiculo q foi criado quando ele passo pelo marker. Exemplo to fazendo um script de trabalho ai quero q quando o player passa pelo marker vai spawna o veiculo certo? isso eu ja sei fazer mas exemplo a net dele cair so que o veiculo vai fica do servidor ainda entao queria q quando ele sair do sv ia destruir.

Link to comment
10 hours ago, TeixeiraRB said:

Tudo bem? Queria saber como faço para quando o player sair do servidor destruir o veiculo q foi criado quando ele passo pelo marker. Exemplo to fazendo um script de trabalho ai quero q quando o player passa pelo marker vai spawna o veiculo certo? isso eu ja sei fazer mas exemplo a net dele cair so que o veiculo vai fica do servidor ainda entao queria q quando ele sair do sv ia destruir.

function quitcar(player)
local veh = getPedOccupiedVehicle(player) 
destroyElement(veh)
end
addEventHandler ( "onPlayerQuit", getRootElement(), quitcar )

 

  • Like 1
Link to comment
  • Other Languages Moderators
1 hour ago, <~KaMiKaZe~> said:

function quitcar(player)
local veh = getPedOccupiedVehicle(player) 
destroyElement(veh)
end
addEventHandler ( "onPlayerQuit", getRootElement(), quitcar )

 

Vai gerar erro se o jogador que sair não estiver em um veículo. Coloque um verificador para evitar isso.

function quitcar (thePlayer)
    local veh = getPedOccupiedVehicle(thePlayer)
    if veh then
        destroyElement(veh)
    end
end
addEventHandler ("onPlayerQuit", getRootElement(), quitcar)

 

  • Like 1
Link to comment

Ta dando erro Lord Henry  Erro: Markers.lua:18: Bad argument @ 'getPedOccuipedVehicle' [Expected ped at argument 1, got string 'Quit' ]

 

Spawna = createMarker (-314.8583984375, 1546.0322265625, 75.5625 -1, "cylinder", 2, 255 ,0 ,0, 255)

veh = {}
function Pegar(thePlayer)
if isElementWithinMarker(thePlayer, Spawna) then
if hilux and isElement( hilux ) then destroyElement ( hilux )
hilux = nil
end
x,y,z = getElementPosition(thePlayer)
Islamico = true
hilux = createVehicle(422,-282.26953125, 1529.451171875, 75.359375, 0, 0, 61.878692626953)
warpPedIntoVehicle( thePlayer, hilux )
end
end
addEventHandler( "onMarkerHit", Spawna, Pegar )

function sair(thePlayer)
    local hilux = getPedOccupiedVehicle(thePlayer)
    if hilux then
        destroyElement ( hilux )
    end
end
addEventHandler ("onPlayerQuit", getRootElement(), sair)

 

Link to comment
  • Moderators

Parameters

string quitType, string reason, element responsibleElement

O parâmetro tá errado, tire thePlayer e substitua por source.

 

Edit: Você pode usar a variável hilux pra obter o veículo. Ou também esta função:

function destroyPlayerVehicles( p )
	local vehicles = getElementsByType( "vehicle" )
	for _,v in pairs(vehicles) do
		local syncer = getElementSyncer(v)
		if p and syncer == p then
			destroyElement(v)
		end
	end
end

 

Edited by DNL291
Link to comment
  • Other Languages Moderators
21 hours ago, TeixeiraRB said:

Ta dando erro Lord Henry  Erro: Markers.lua:18: Bad argument @ 'getPedOccuipedVehicle' [Expected ped at argument 1, got string 'Quit' ]

Spawna = createMarker (-314.8583984375, 1546.0322265625, 75.5625 -1, "cylinder", 2, 255 ,0 ,0, 255)
veh = {}

function Pegar(hitElement)
    if hitElement and getElementType (hitElement) == "player" then  
        if veh[hitElement] and isElement(veh[hitElement]) then
            destroyElement (veh[hitElement])
            veh[hitElement] = nil
        end
        local x, y, z = getElementPosition (hitElement) -- Isso não tem utilidade.
        Islamico = true -- Isso também não.
        veh[hitElement] = createVehicle(422,-282.26953125, 1529.451171875, 75.359375, 0, 0, 61.878692626953)
        warpPedIntoVehicle(hitElement, veh[hitElement])
    end
end
addEventHandler("onMarkerHit", Spawna, Pegar)

function sair (quitType, reason, responsible)
    local hilux = getPedOccupiedVehicle(source)
    if hilux then
        destroyElement (hilux)
    end
end
addEventHandler ("onPlayerQuit", getRootElement(), sair)

 

Edited by Lord Henry
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...