joao2235 Posted September 5, 2019 Share Posted September 5, 2019 (edited) 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]) -- killTimer does not work. end Rumpo[AparecerBike] = setTimer(destroyVehicle,5000*minutos,0,AparecerBike) -- This timer does not stop... 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) Console returns: server.Lua:50: Bad argument @ 'destroyElement' [Expected element at argument 1] The function destroys the Element but does not stop the timer. I can't stop this timer (descripton on the code), someone can help me ? Thanks! Edited September 5, 2019 by joao2235 Link to comment
Ceeser Posted September 5, 2019 Share Posted September 5, 2019 Hey, a timer is also a kind of userdata, so you need to pass the timer 'link' somewhere. Maybe you can set the timers as elementDatas on the vehicle, otherwise store the vehicle + timers belonging to it in a table Link to comment
joao2235 Posted September 5, 2019 Author Share Posted September 5, 2019 I don't now how I can do this. Link to comment
Ceeser Posted September 5, 2019 Share Posted September 5, 2019 (edited) 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] -- EDIT tblBikes = {}; -- /EDIT 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 ) -- EDIT tblBikes[AparecerBike] = {}; tblBikes[AparecerBike].fadeTimer = setTimer ( fadeCamera, 500, 1, source , true, 0.5 ) tblBikes[AparecerBike].targetTimer = setTimer ( setCameraTarget, 500, 1, source ) -- /EDIT 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 -- EDIT if (tblBikes[AparecerBike]) then for _, timer in pairs(tblBikes[AparecerBike]) do if (isTimer(timer) then killTimer(timer) timer = nil end end end -- /EDIT 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]) -- killTimer does not work. end Rumpo[AparecerBike] = setTimer(destroyVehicle,5000*minutos,0,AparecerBike) -- This timer does not stop... 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) Dunno what this "Rumpo" stuff is, so i just made an example in the destroyVehicle function, hope you get what im on about, marked all changes with --EDIT and --/EDIT Edited September 5, 2019 by Ceeser Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now