joao2235 Posted September 5, 2019 Share Posted September 5, 2019 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 --[[function DestroyVeiculo (AparecerBike, seat) if getElementData(AparecerBike, "kart.race") == true and seat == 0 then setElementData(AparecerBike, "kart.race", false) destroyElement (AparecerBike) killTimer(Rumpo[AparecerBike]) end end addEventHandler ("onPlayerLogout", getRootElement(), DestroyVeiculo) addEventHandler ("onPlayerQuit", getRootElement(), DestroyVeiculo) addEventHandler ("onPlayerWasted", getRootElement(), DestroyVeiculo) addEventHandler ("onPlayerBan", getRootElement(), DestroyVeiculo) addEventHandler ("onResourceStop", getRootElement(), DestroyVeiculo)]]-- addEventHandler( "onPlayerQuit", root, function() if getElementData(AparecerBike, "kart.race") then setElementData(AparecerBike, "kart.race", false) destroyElement (AparecerBike) end end) addEventHandler( "onPlayerWasted", root, function() if getElementData(AparecerBike, "kart.race") then setElementData(AparecerBike, "kart.race", false) destroyElement (AparecerBike) end end) addEventHandler( "onPlayerLogout", root, function() if getElementData(AparecerBike, "kart.race") then setElementData(AparecerBike, "kart.race", false) destroyElement (AparecerBike) end end) addEventHandler( "onResourceStop", root, function() if getElementData(AparecerBike, "kart.race") then setElementData(AparecerBike, "kart.race", false) destroyElement (AparecerBike) end end) addEventHandler( "onPlayerBan", root, function() if getElementData(AparecerBike, "kart.race") then setElementData(AparecerBike, "kart.race", false) 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,60000*minutos,1,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) server.Lua:50: Bad argument @ 'getElementData' [Expected element at argument 1] Link to comment
joao2235 Posted September 6, 2019 Author Share Posted September 6, 2019 Descobri testando com um amigo o seguinte, se eu alugo uma bike e ele aluga após eu ter alugado a minha bike some, alguém tem ideia do que posso fazer para resolver ? Link to comment
Other Languages Moderators Lord Henry Posted September 6, 2019 Other Languages Moderators Share Posted September 6, 2019 (edited) 17 hours ago, joao2235 said: Descobri testando com um amigo o seguinte, se eu alugo uma bike e ele aluga após eu ter alugado a minha bike some, alguém tem ideia do que posso fazer para resolver ? Crie uma table vazia onde todas as bikes vão ficar. E indexe as bikes aos jogadores. Não use source como parâmetro de função. E aquela sua linha 6 não faz sentido. Edited September 6, 2019 by Lord Henry Link to comment
joao2235 Posted September 7, 2019 Author Share Posted September 7, 2019 (edited) Irmão, tem o código do script original que peguei da net, mas não consegui fazer com que bike seja destruída quando o "onPlayerWasted". Segue o código original: SERVER-SIDE 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 usa-la.", player, 255, 0, 0) end end end addEventHandler("onVehicleStartEnter", getRootElement(), onVehicleStartEnter) CLIENT-SIDE --------------------------------------------[Устройство] local entradaB = createMarker(1086.4340820313,-1803.6898193359,14.602746963501, "cylinder", 1, 255, 255, 255, 0) local myBlip = createBlip( 1085.6364746094,-1800.0280761719,13.626179695129, 44, 0, 0, 0, 255, myPlayer ) addEventHandler( "onClientRender", root, function() local x, y, z = getElementPosition( entradaB ) local Mx, My, Mz = getCameraMatrix( ) if ( getDistanceBetweenPoints3D( x, y, z, Mx, My, Mz ) <= 15 ) then local WorldPositionX, WorldPositionY = getScreenFromWorldPosition( x, y, z +1, 0.07 ) if ( WorldPositionX and WorldPositionY ) then dxDrawText("Aluguel de bicicletas", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(0, 0, 0, 255), 2.52, "default-bold", "center", "center", false, false, false, false, false) dxDrawText("Aluguel de bicicletas", WorldPositionX - 1, WorldPositionY + 1, WorldPositionX - 1, WorldPositionY + 1, tocolor(255, 255, 255, 255), 2.50, "default-bold", "center", "center", false, false, false, false, false) end end end ) --------------------------------------------- function centerWindow(center_window) local screenW,screenH=guiGetScreenSize() local windowW,windowH=guiGetSize(center_window,false) local x,y = (screenW-windowW)/2,(screenH-windowH)/2 guiSetPosition(center_window,x,y,false) end wndArenda = guiCreateWindow(0,0,500,150,"Aluguel de bicicletas",false) centerWindow(wndArenda) guiSetVisible(wndArenda,false) label1 = guiCreateLabel(0,30,490,480, "Você pode alugar uma bicicleta para passear ou trabalhar por\n500 $$ \ncaso você saia da bicicleta por 5 minutos ela\nvai ser devolvida!!", false, wndArenda) guiSetFont(label1, "default-bold-small") guiLabelSetHorizontalAlign(label1, "center", false) local btn1 = guiCreateButton(20,100,200,35,"Alugar",false,wndArenda) local btn2 = guiCreateButton(280,100,200,35,"Sair",false,wndArenda) addEventHandler('onClientGUIClick',wndArenda,function() if source == btn1 then triggerServerEvent("onPlayerUseCustomPickup", localPlayer) guiSetVisible(wndArenda,false) showCursor(false) elseif source == btn2 then guiSetVisible(wndArenda,false) showCursor(false) end end) function changeArendaMenuState() guiSetVisible(wndArenda,true) showCursor(true) end addEvent("changeArendaMenuState", true) addEventHandler("changeArendaMenuState", getRootElement(), changeArendaMenuState) Edited September 7, 2019 by joao2235 Link to comment
Other Languages Moderators Lord Henry Posted September 7, 2019 Other Languages Moderators Share Posted September 7, 2019 Tópico duplicado, continuar neste: Link to comment
Recommended Posts