Jump to content

[HELP] I can't destroy this element


joao2235

Recommended Posts

local vehicleElements = {}

allVeh = {510}

local pickupTable = {
{1086.1798095703,-1801.6898193359,13.601690292358},
}

function createPickupOnServerStart ()
    for i, cor in ipairs (pickupTable) do
	    local pickup = createPickup(cor[1], cor[2], cor[3], 3, 1274, 0)
		setElementData(pickup, "pickupArenda", true)
	end
end
addEventHandler("onResourceStart", getResourceRootElement( getThisResource() ), createPickupOnServerStart)

function onResourceStop (veh)
    if isTimer(vehicleElements[veh]) then
        killTimer(vehicleElements[veh])
    end
    --vehicleElements[veh] = destroyElement(veh)
end
addEventHandler("onResourceStop", getResourceRootElement( getThisResource() ), onResourceStop)

function onPickupHit (hit)
    if not getElementData(source, "pickupArenda") or getElementType(hit) ~= "player" and not isPedInVehicle(hit) then return end
    triggerClientEvent(hit, "changeArendaMenuState", hit)
end
addEventHandler("onPickupHit", getRootElement(), onPickupHit)

function onPlayerUseCustomPickup()
	    if getPlayerMoney(source) >= 500 then
	    	local x, y, z = getElementPosition(source)
			local veh = createVehicle(allVeh[math.random(1,#allVeh)],  x, y, z)
			setElementData(veh, "starter_pack", true)
			setElementData(veh, "owner", source)
			warpPedIntoVehicle(source, veh)
			
			takePlayerMoney(source, 500)
            outputChatBox("Bicicleta alugada, bom uso!.", source, 0, 255, 0)
		else
		    outputChatBox("Para alugar uma bicicleta você precisa de >> 500 $$ <<.", source, 255, 0, 0)
		end
end
addEvent("onPlayerUseCustomPickup", true)
addEventHandler("onPlayerUseCustomPickup", getRootElement(), onPlayerUseCustomPickup)

function onPlayerVehicleEnter (veh, seat)
    if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
	end
end
addEventHandler("onPlayerVehicleEnter", getRootElement(), onPlayerVehicleEnter)

function onPlayerVehicleExit (veh, seat)
    if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
		vehicleElements[veh] = setTimer(destroyElement, 300000, 1, veh)
	end
end
addEventHandler("onPlayerVehicleExit", getRootElement(), onPlayerVehicleExit)

function onVehicleStartEnter (player, seat)
    if getElementData(source, "starter_pack") == true and seat == 0 then
	    local owner = getElementData(source, "owner")
		if owner ~= player then
		    cancelEvent()
	        outputChatBox("Você não é dono desta bicicleta, alugue sua bike para poder usá-la.", player, 255, 0, 0)
		end
	end
end
addEventHandler("onVehicleStartEnter", getRootElement(), onVehicleStartEnter)

This is the script to rent bike to a player. The bike is destroyed after 5 minutes, it's ok. But i need to do something that when player is arrasted, die, logout, exit of game the bike be destroyed too.

function DestroyVeiculo (veh, seat)
	if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
		--vehicleElements[veh] = setTimer(destroyElement, 300000, 1, veh)
		vehicleElements[veh] = destroyElement(veh)
	end
end
addEventHandler ("onPlayerLogout", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerQuit", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerWasted", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerBan", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerDie", getRootElement(), DestroyVeiculo)

I tried to do it the way above, but not sucess. Someone can help me ? Thanks! 

Link to comment
  • Scripting Moderators
9 minutes ago, joao2235 said:

local vehicleElements = {}

allVeh = {510}

local pickupTable = {
{1086.1798095703,-1801.6898193359,13.601690292358},
}

function createPickupOnServerStart ()
    for i, cor in ipairs (pickupTable) do
	    local pickup = createPickup(cor[1], cor[2], cor[3], 3, 1274, 0)
		setElementData(pickup, "pickupArenda", true)
	end
end
addEventHandler("onResourceStart", getResourceRootElement( getThisResource() ), createPickupOnServerStart)

function onResourceStop (veh)
    if isTimer(vehicleElements[veh]) then
        killTimer(vehicleElements[veh])
    end
    --vehicleElements[veh] = destroyElement(veh)
end
addEventHandler("onResourceStop", getResourceRootElement( getThisResource() ), onResourceStop)

function onPickupHit (hit)
    if not getElementData(source, "pickupArenda") or getElementType(hit) ~= "player" and not isPedInVehicle(hit) then return end
    triggerClientEvent(hit, "changeArendaMenuState", hit)
end
addEventHandler("onPickupHit", getRootElement(), onPickupHit)

function onPlayerUseCustomPickup()
	    if getPlayerMoney(source) >= 500 then
	    	local x, y, z = getElementPosition(source)
			local veh = createVehicle(allVeh[math.random(1,#allVeh)],  x, y, z)
			setElementData(veh, "starter_pack", true)
			setElementData(veh, "owner", source)
			warpPedIntoVehicle(source, veh)
			
			takePlayerMoney(source, 500)
            outputChatBox("Bicicleta alugada, bom uso!.", source, 0, 255, 0)
		else
		    outputChatBox("Para alugar uma bicicleta você precisa de >> 500 $$ <<.", source, 255, 0, 0)
		end
end
addEvent("onPlayerUseCustomPickup", true)
addEventHandler("onPlayerUseCustomPickup", getRootElement(), onPlayerUseCustomPickup)

function onPlayerVehicleEnter (veh, seat)
    if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
	end
end
addEventHandler("onPlayerVehicleEnter", getRootElement(), onPlayerVehicleEnter)

function onPlayerVehicleExit (veh, seat)
    if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
		vehicleElements[veh] = setTimer(destroyElement, 300000, 1, veh)
	end
end
addEventHandler("onPlayerVehicleExit", getRootElement(), onPlayerVehicleExit)

function onVehicleStartEnter (player, seat)
    if getElementData(source, "starter_pack") == true and seat == 0 then
	    local owner = getElementData(source, "owner")
		if owner ~= player then
		    cancelEvent()
	        outputChatBox("Você não é dono desta bicicleta, alugue sua bike para poder usá-la.", player, 255, 0, 0)
		end
	end
end
addEventHandler("onVehicleStartEnter", getRootElement(), onVehicleStartEnter)

This is the script to rent bike to a player. The bike is destroyed after 5 minutes, it's ok. But i need to do something that when player is arrasted, die, logout, exit of game the bike be destroyed too.


function DestroyVeiculo (veh, seat)
	if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
		--vehicleElements[veh] = setTimer(destroyElement, 300000, 1, veh)
		vehicleElements[veh] = destroyElement(veh)
	end
end
addEventHandler ("onPlayerLogout", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerQuit", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerWasted", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerBan", getRootElement(), DestroyVeiculo)
addEventHandler ("onPlayerDie", getRootElement(), DestroyVeiculo)

I tried to do it the way above, but not sucess. Someone can help me ? Thanks! 

You attach this function to internal MTA events which have completely other parameters than veh and seat. Did u even checked for warnings/errors?

Example which should be helpful:

function destroyVehicle()
	local occupied_seat = getPedOccupiedVehicleSeat(source)
	if occupied_seat and occupied_seat == 0 then
		local occupied_vehicle = getPedOccupiedVehicle(source)
		if occupied_vehicle then
			local element_data = getElementData(occupied_vehicle, "starter_pack") or false
			if element_data then
				-- do your stuff
				end
			end
		end
	end
end

 

Link to comment
  • Scripting Moderators
Just now, joao2235 said:

How I can insert by example:
onPlayerDie ? 

There's no such MTA event, or it's a event created by yourself. If you want attach this function, simply do it as above, you'll just need to complete this by adding missing functions from your code.

https://wiki.multitheftauto.com/wiki/Server_Scripting_Events

Link to comment
  • Scripting Moderators
Just now, joao2235 said:

So, how can i do when the player dies ? 

According to my function:

addEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)

 

Link to comment

Ok, but where I put this in the code ?

function destroyVehicle()
	local occupied_seat = getPedOccupiedVehicleSeat(source)
	if occupied_seat and occupied_seat == 0 then
		local occupied_vehicle = getPedOccupiedVehicle(source)
		if occupied_vehicle then
			local element_data = getElementData(occupied_vehicle, "starter_pack") or false
			if element_data then
				-- HERE ?
				end
			end
		end
	end
end

 

Link to comment
  • Scripting Moderators
1 minute ago, joao2235 said:

Ok, but where I put this in the code ?


function destroyVehicle()
	local occupied_seat = getPedOccupiedVehicleSeat(source)
	if occupied_seat and occupied_seat == 0 then
		local occupied_vehicle = getPedOccupiedVehicle(source)
		if occupied_vehicle then
			local element_data = getElementData(occupied_vehicle, "starter_pack") or false
			if element_data then
				-- HERE ?
				end
			end
		end
	end
end

 

Ye, there you should add your missing code.

Link to comment
function destroyVehicle()
	local occupied_seat = getPedOccupiedVehicleSeat(source)
	if occupied_seat and occupied_seat == 0 then
		local occupied_vehicle = getPedOccupiedVehicle(source)
		if occupied_vehicle then
			local element_data = getElementData(occupied_vehicle, "starter_pack") or false
			if element_data then
			    addEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)
				end
			end
		end
	end
end

This way ?

Sorry, I am a begginer.

Edited by joao2235
Link to comment
  • Scripting Moderators
1 minute ago, joao2235 said:

function destroyVehicle()
	local occupied_seat = getPedOccupiedVehicleSeat(source)
	if occupied_seat and occupied_seat == 0 then
		local occupied_vehicle = getPedOccupiedVehicle(source)
		if occupied_vehicle then
			local element_data = getElementData(occupied_vehicle, "starter_pack") or false
			if element_data then
			    addEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)
				end
			end
		end
	end
end

This way ?

Nope, like this:

function destroyVehicle()
	local occupied_seat = getPedOccupiedVehicleSeat(source)
	if occupied_seat and occupied_seat == 0 then
		local occupied_vehicle = getPedOccupiedVehicle(source)
		if occupied_vehicle then
			local element_data = getElementData(occupied_vehicle, "starter_pack") or false
			if element_data then
				-- destroy vehicle with such element data
				destroyElement(occupied_vehicle)
			end
		end
	end
end
addEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)

 

Link to comment
local vehicleElements = {}

allVeh = {510}

local pickupTable = {
{1086.1798095703,-1801.6898193359,13.601690292358},
}

function createPickupOnServerStart ()
    for i, cor in ipairs (pickupTable) do
	    local pickup = createPickup(cor[1], cor[2], cor[3], 3, 1274, 0)
		setElementData(pickup, "pickupArenda", true)
	end
end
addEventHandler("onResourceStart", getResourceRootElement( getThisResource() ), createPickupOnServerStart)

function onResourceStop (veh)
    if isTimer(vehicleElements[veh]) then
        killTimer(vehicleElements[veh])
    end
    --vehicleElements[veh] = destroyElement(veh)
end
addEventHandler("onResourceStop", getResourceRootElement( getThisResource() ), onResourceStop)

function onPickupHit (hit)
    if not getElementData(source, "pickupArenda") or getElementType(hit) ~= "player" and not isPedInVehicle(hit) then return end
    triggerClientEvent(hit, "changeArendaMenuState", hit)
end
addEventHandler("onPickupHit", getRootElement(), onPickupHit)

function onPlayerUseCustomPickup()
	    if getPlayerMoney(source) >= 500 then
	    	local x, y, z = getElementPosition(source)
			local veh = createVehicle(allVeh[math.random(1,#allVeh)],  x, y, z)
			setElementData(veh, "starter_pack", true)
			setElementData(veh, "owner", source)
			warpPedIntoVehicle(source, veh)
			
			takePlayerMoney(source, 500)
            outputChatBox("Bicicleta alugada, bom uso!.", source, 0, 255, 0)
		else
		    outputChatBox("Para alugar uma bicicleta você precisa de >> 500 $$ <<.", source, 255, 0, 0)
		end
end
addEvent("onPlayerUseCustomPickup", true)
addEventHandler("onPlayerUseCustomPickup", getRootElement(), onPlayerUseCustomPickup)

function onPlayerVehicleEnter (veh, seat)
    if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
	end
end
addEventHandler("onPlayerVehicleEnter", getRootElement(), onPlayerVehicleEnter)

function destroyVehicle()
	local occupied_seat = getPedOccupiedVehicleSeat(source)
	if occupied_seat and occupied_seat == 0 then
		local occupied_vehicle = getPedOccupiedVehicle(source)
		if occupied_vehicle then
			local element_data = getElementData(occupied_vehicle, "starter_pack") or false
			if element_data then
				-- destroy vehicle with such element data
				destroyElement(occupied_vehicle)
			end
		end
	end
end
addEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)

function onPlayerVehicleExit (veh, seat)
    if getElementData(veh, "starter_pack") == true and seat == 0 then
	    if isTimer(vehicleElements[veh]) then
		    killTimer(vehicleElements[veh])
		end
		vehicleElements[veh] = setTimer(destroyElement, 300000, 1, veh)
	end
end
addEventHandler("onPlayerVehicleExit", getRootElement(), onPlayerVehicleExit)

function onVehicleStartEnter (player, seat)
    if getElementData(source, "starter_pack") == true and seat == 0 then
	    local owner = getElementData(source, "owner")
		if owner ~= player then
		    cancelEvent()
	        outputChatBox("Você não é dono desta bicicleta, alugue sua bike para poder usá-la.", player, 255, 0, 0)
		end
	end
end
addEventHandler("onVehicleStartEnter", getRootElement(), onVehicleStartEnter)

I added it, but does not working...

Link to comment
  • Scripting Moderators
4 minutes ago, joao2235 said:

local vehicleElements = {}allVeh = {510}local pickupTable = {{1086.1798095703,-1801.6898193359,13.601690292358},}function createPickupOnServerStart ()    for i, cor in ipairs (pickupTable) do	    local pickup = createPickup(cor[1], cor[2], cor[3], 3, 1274, 0)		setElementData(pickup, "pickupArenda", true)	endendaddEventHandler("onResourceStart", getResourceRootElement( getThisResource() ), createPickupOnServerStart)function onResourceStop (veh)    if isTimer(vehicleElements[veh]) then        killTimer(vehicleElements[veh])    end    --vehicleElements[veh] = destroyElement(veh)endaddEventHandler("onResourceStop", getResourceRootElement( getThisResource() ), onResourceStop)function onPickupHit (hit)    if not getElementData(source, "pickupArenda") or getElementType(hit) ~= "player" and not isPedInVehicle(hit) then return end    triggerClientEvent(hit, "changeArendaMenuState", hit)endaddEventHandler("onPickupHit", getRootElement(), onPickupHit)function onPlayerUseCustomPickup()	    if getPlayerMoney(source) >= 500 then	    	local x, y, z = getElementPosition(source)			local veh = createVehicle(allVeh[math.random(1,#allVeh)],  x, y, z)			setElementData(veh, "starter_pack", true)			setElementData(veh, "owner", source)			warpPedIntoVehicle(source, veh)						takePlayerMoney(source, 500)            outputChatBox("Bicicleta alugada, bom uso!.", source, 0, 255, 0)		else		    outputChatBox("Para alugar uma bicicleta você precisa de >> 500 $$ <<.", source, 255, 0, 0)		endendaddEvent("onPlayerUseCustomPickup", true)addEventHandler("onPlayerUseCustomPickup", getRootElement(), onPlayerUseCustomPickup)function onPlayerVehicleEnter (veh, seat)    if getElementData(veh, "starter_pack") == true and seat == 0 then	    if isTimer(vehicleElements[veh]) then		    killTimer(vehicleElements[veh])		end	endendaddEventHandler("onPlayerVehicleEnter", getRootElement(), onPlayerVehicleEnter)function destroyVehicle()	local occupied_seat = getPedOccupiedVehicleSeat(source)	if occupied_seat and occupied_seat == 0 then		local occupied_vehicle = getPedOccupiedVehicle(source)		if occupied_vehicle then			local element_data = getElementData(occupied_vehicle, "starter_pack") or false			if element_data then				-- destroy vehicle with such element data				destroyElement(occupied_vehicle)			end		end	endendaddEventHandler("onPlayerWasted", getRootElement(), destroyVehicle)function onPlayerVehicleExit (veh, seat)    if getElementData(veh, "starter_pack") == true and seat == 0 then	    if isTimer(vehicleElements[veh]) then		    killTimer(vehicleElements[veh])		end		vehicleElements[veh] = setTimer(destroyElement, 300000, 1, veh)	endendaddEventHandler("onPlayerVehicleExit", getRootElement(), onPlayerVehicleExit)function onVehicleStartEnter (player, seat)    if getElementData(source, "starter_pack") == true and seat == 0 then	    local owner = getElementData(source, "owner")		if owner ~= player then		    cancelEvent()	        outputChatBox("Você não é dono desta bicicleta, alugue sua bike para poder usá-la.", player, 255, 0, 0)		end	endendaddEventHandler("onVehicleStartEnter", getRootElement(), onVehicleStartEnter)

I added it, but does not working...

What exactly doesn't work? Any errors, warnings?

Link to comment

I Solved it, but now I have other problem, follow my code:
 

MarkerBike = createMarker(1086.3326416016,-1802.1416015625,12.60143661499, "cylinder", 1.5, 255,255,255,50)
BlipLS = createBlipAttachedTo(MarkerBike, 33)
setBlipVisibleDistance(BlipLS, 800)
--local Veiculos = {510} -- IDs dos Veículos.
Rumpo = {}
AparecerBike = Rumpo[source]
function spawn (source)
    if isElementWithinMarker(source, MarkerBike) then 
        if getPlayerMoney(source) >= 500 then 
            takePlayerMoney (source, 500)
            if AparecerBike and isElement(AparecerBike) then
                destroyElement(AparecerBike)
            end
            AparecerBike = createVehicle (510, 1091.2088623047,-1796.9704589844,13.606305122375)   
            setElementData(AparecerBike, "kart.race", true)  
            setElementData(source, "owner", AparecerBike) 
            setElementData(AparecerBike, "conta.tempo", false)                                
            setElementRotation(AparecerBike,0,0,0)
            fadeCamera ( source, false, 0, 0, 0, 0 )   
            setTimer ( fadeCamera, 500, 1, source , true, 0.5 )
            setTimer ( setCameraTarget, 500, 1, source )
            outputChatBox ("#FF0000✘ #ffffffINFO #FF0000✘➺ #FF0000Bicicleta Alugada com sucesso, faça bom uso!", source, 255, 255, 255, true)
            warpPedIntoVehicle (source, AparecerBike)
        else
            outputChatBox("#FF0000✘ #ffffffINFO #FF0000✘➺ #FF0000Você não tem dinheiro suficiente para alugar uma bike!", source, 255,255,255,true)
        end
    end
end
addCommandHandler("alugar", spawn)

function enterVehicle ( player, seat, jacked ) 
    if getElementData(source, "kart.race") == true and seat == 0 then 
	   local owner = getElementData(source, "owner")
	   else
         cancelEvent()
        outputChatBox ( "Você não é dono desta bicicleta, alugue sua bike para poder usá-la.", player )
    end
  end
addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) 


function destroyVehicle(vehicle)
   local check=false
   for i,player in ipairs(getElementsByType("player")) do
       if getPedOccupiedVehicle(player)==vehicle then
           check=true
       end
   end
   if check==false then
       destroyElement(AparecerBike)
   end
end
 
local minutos = 1

function exitVehicle(AparecerBike, seat)
    if getElementData(AparecerBike, "kart.race") == true and seat == 0 then
        if isTimer(Rumpo[AparecerBike]) then
            killTimer(Rumpo[AparecerBike])
        end
        Rumpo[AparecerBike] = setTimer(destroyVehicle,5000*minutos,0,AparecerBike)
    end
end
addEventHandler("onPlayerVehicleExit",getRootElement(),exitVehicle)

function onPlayerVehicleEnter (AparecerBike, seat)
    if getElementData(AparecerBike, "kart.race") == true and seat == 0 then
	    if isTimer(Rumpo[AparecerBike]) then
		    killTimer(Rumpo[AparecerBike])
		end
	end
end
addEventHandler("onPlayerVehicleEnter", getRootElement(), onPlayerVehicleEnter)

function onResourceStop (AparecerBike)
    if isTimer(Rumpo[AparecerBike]) then
        killTimer(Rumpo[AparecerBike])
    end
end
addEventHandler("onResourceStop", getResourceRootElement( getThisResource() ), onResourceStop)

function DestroyVeiculo ()
    if getElementData(source, "kart.race") then
        setElementData(source, "kart.race", false)
        destroyElement (AparecerBike)
        killTimer(Rumpo[AparecerBike])
    end
end
addEventHandler ("onPlayerLogout", root, DestroyVeiculo)
addEventHandler ("onPlayerQuit", root, DestroyVeiculo)
addEventHandler ("onPlayerWasted", root, DestroyVeiculo)
addEventHandler ("onPlayerBan", root, DestroyVeiculo)
addEventHandler ("onResourceStop", root, DestroyVeiculo)

When player bike exit start a timer, so the bike is destroyed, ok! But after this the timer does not stop. Look line 56.

Link to comment
  • Scripting Moderators
1 hour ago, joao2235 said:

I Solved it, but now I have other problem, follow my code:
 


MarkerBike = createMarker(1086.3326416016,-1802.1416015625,12.60143661499, "cylinder", 1.5, 255,255,255,50)BlipLS = createBlipAttachedTo(MarkerBike, 33)setBlipVisibleDistance(BlipLS, 800)--local Veiculos = {510} -- IDs dos Veículos.Rumpo = {}AparecerBike = Rumpo[source]function spawn (source)    if isElementWithinMarker(source, MarkerBike) then         if getPlayerMoney(source) >= 500 then             takePlayerMoney (source, 500)            if AparecerBike and isElement(AparecerBike) then                destroyElement(AparecerBike)            end            AparecerBike = createVehicle (510, 1091.2088623047,-1796.9704589844,13.606305122375)               setElementData(AparecerBike, "kart.race", true)              setElementData(source, "owner", AparecerBike)             setElementData(AparecerBike, "conta.tempo", false)                                            setElementRotation(AparecerBike,0,0,0)            fadeCamera ( source, false, 0, 0, 0, 0 )               setTimer ( fadeCamera, 500, 1, source , true, 0.5 )            setTimer ( setCameraTarget, 500, 1, source )            outputChatBox ("#FF0000✘ #ffffffINFO #FF0000✘➺ #FF0000Bicicleta Alugada com sucesso, faça bom uso!", source, 255, 255, 255, true)            warpPedIntoVehicle (source, AparecerBike)        else            outputChatBox("#FF0000✘ #ffffffINFO #FF0000✘➺ #FF0000Você não tem dinheiro suficiente para alugar uma bike!", source, 255,255,255,true)        end    endendaddCommandHandler("alugar", spawn)function enterVehicle ( player, seat, jacked )     if getElementData(source, "kart.race") == true and seat == 0 then 	   local owner = getElementData(source, "owner")	   else         cancelEvent()        outputChatBox ( "Você não é dono desta bicicleta, alugue sua bike para poder usá-la.", player )    end  endaddEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) function destroyVehicle(vehicle)   local check=false   for i,player in ipairs(getElementsByType("player")) do       if getPedOccupiedVehicle(player)==vehicle then           check=true       end   end   if check==false then       destroyElement(AparecerBike)   endend local minutos = 1function exitVehicle(AparecerBike, seat)    if getElementData(AparecerBike, "kart.race") == true and seat == 0 then        if isTimer(Rumpo[AparecerBike]) then            killTimer(Rumpo[AparecerBike])        end        Rumpo[AparecerBike] = setTimer(destroyVehicle,5000*minutos,0,AparecerBike)    endendaddEventHandler("onPlayerVehicleExit",getRootElement(),exitVehicle)function onPlayerVehicleEnter (AparecerBike, seat)    if getElementData(AparecerBike, "kart.race") == true and seat == 0 then	    if isTimer(Rumpo[AparecerBike]) then		    killTimer(Rumpo[AparecerBike])		end	endendaddEventHandler("onPlayerVehicleEnter", getRootElement(), onPlayerVehicleEnter)function onResourceStop (AparecerBike)    if isTimer(Rumpo[AparecerBike]) then        killTimer(Rumpo[AparecerBike])    endendaddEventHandler("onResourceStop", getResourceRootElement( getThisResource() ), onResourceStop)function DestroyVeiculo ()    if getElementData(source, "kart.race") then        setElementData(source, "kart.race", false)        destroyElement (AparecerBike)        killTimer(Rumpo[AparecerBike])    endendaddEventHandler ("onPlayerLogout", root, DestroyVeiculo)addEventHandler ("onPlayerQuit", root, DestroyVeiculo)addEventHandler ("onPlayerWasted", root, DestroyVeiculo)addEventHandler ("onPlayerBan", root, DestroyVeiculo)addEventHandler ("onResourceStop", root, DestroyVeiculo)

When player bike exit start a timer, so the bike is destroyed, ok! But after this the timer does not stop. Look line 56.

Rumpo[AparecerBike] = setTimer(destroyVehicle, 5000 * minutos, 0, AparecerBike)

5000 * minutos, - change 0 to 1, otherwise this will never stop.

Besides, code, it's badly optimized. No need for ipairs loop, use int loop instead.

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