Rangel 0 Posted January 12, 2020 Share Posted January 12, 2020 (edited) Boa noite a todos, eu sou bem leigo em Lua, e toda vez que venho aqui fico feliz com a maneira que vocês fazem a gente entender pelo menos o minimo dos scripts que estamos tentando alterar, isso é sensacional. enfim. Hoje eu to com um problema em um sistema de spawn de vtr por acl. Queria que se possível me ajudassem a alterar o que quero nele. Spawn1 = createMarker(-65.258903503418, -343.11831665039, 5.4296875 -1,"cylinder", 1.9, 0, 0, 200, 40) Destroy = createMarker(-65.258903503418, -371.39807128906, 5.4296875 -2,"cylinder", 5.0, 128, 0, 0, 99) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end veh = {} function spawnvtr ( thePlayer, comando, nick ) setElementHealth (veh, 200000) if veh[thePlayer] and isElement( veh[thePlayer] ) then destroyElement ( veh[thePlayer] ) veh[thePlayer] = nil end local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "BOMBEIROS") ) then veh[thePlayer] = createVehicle(529, -61.04016494751, -303.79797363281, 5.3578243255615, 0, 0, 270 ) warpPedIntoVehicle ( thePlayer, veh[thePlayer] ) --exports._infobox:addNotification(thePlayer, "", "success") else outputChatBox("#FFFFFF| #E10000BOMBEIROS #FFFFFF| Somente #E10000BOMBEIROS #FFFFFFPodem Pegar Este Veiculo.",thePlayer,255,255,255, true) end end addEventHandler("onMarkerHit", Spawn1, spawnvtr) function destroyvtr ( thePlayer ) if veh[thePlayer] and isElement(veh[thePlayer]) then destroyElement (veh[thePlayer]) --exports._infobox:addNotification(thePlayer, "", "success") else end end addEventHandler("onMarkerHit", Destroy, destroyvtr) Ele é bem simples, você passa em cima de um marker ele cria um determinado veiculo, e em cima de outro marker e ele destrói. Mas tem 2 poréns eu queria que um único player conseguisse spawnar quantos veículos ele quisesse, e quando ele spawna outro veículo, o anterior some. E o outro problema é que quando o player spawna o veículo e sai do server, ele não consegue mais desespawnar. Alguém pode me ajudar a resolver? Grato a Atenção Edited January 12, 2020 by Rangel Link to post
NeoGM 1 Posted January 12, 2020 Share Posted January 12, 2020 25 minutes ago, Rangel said: Boa noite a todos, eu sou bem leigo em Lua, e toda vez que venho aqui fico feliz com a maneira que vocês fazem a gente entender pelo menos o minimo dos scripts que estamos tentando alterar, isso é sensacional. enfim. Hoje eu to com um problema em um sistema de spawn de vtr por acl. Queria que se possível me ajudassem a alterar o que quero nele. Spawn1 = createMarker(-65.258903503418, -343.11831665039, 5.4296875 -1,"cylinder", 1.9, 0, 0, 200, 40) Destroy = createMarker(-65.258903503418, -371.39807128906, 5.4296875 -2,"cylinder", 5.0, 128, 0, 0, 99) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end veh = {} function spawnvtr ( thePlayer, comando, nick ) setElementHealth (veh, 200000) if veh[thePlayer] and isElement( veh[thePlayer] ) then destroyElement ( veh[thePlayer] ) veh[thePlayer] = nil end local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "BOMBEIROS") ) then veh[thePlayer] = createVehicle(529, -61.04016494751, -303.79797363281, 5.3578243255615, 0, 0, 270 ) warpPedIntoVehicle ( thePlayer, veh[thePlayer] ) --exports._infobox:addNotification(thePlayer, "", "success") else outputChatBox("#FFFFFF| #E10000BOMBEIROS #FFFFFF| Somente #E10000BOMBEIROS #FFFFFFPodem Pegar Este Veiculo.",thePlayer,255,255,255, true) end end addEventHandler("onMarkerHit", Spawn1, spawnvtr) function destroyvtr ( thePlayer ) if veh[thePlayer] and isElement(veh[thePlayer]) then destroyElement (veh[thePlayer]) --exports._infobox:addNotification(thePlayer, "", "success") else end end addEventHandler("onMarkerHit", Destroy, destroyvtr) Ele é bem simples, você passa em cima de um marker ele cria um determinado veiculo, e em cima de outro marker e ele destrói. Mas tem 2 poréns eu queria que um único player conseguisse spawnar quantos veículos ele quisesse, e quando ele spawna outro veículo, o anterior some. E o outro problema é que quando o player spawna o veículo e sai do server, ele não consegue mais desespawnar. Alguém pode me ajudar a resolver? Grato a Atenção Rangel, posso te dar uma opinião. Se caso alguém consiga entrar na base que não seja da corporação ou gang etc, ela pode bugar todo seu servidor com o spawn. Ela pode spawnar vários veículos na base. 1 Link to post
Rangel 0 Posted January 12, 2020 Author Share Posted January 12, 2020 1 hour ago, NeoGM said: Rangel, posso te dar uma opinião. Se caso alguém consiga entrar na base que não seja da corporação ou gang etc, ela pode bugar todo seu servidor com o spawn. Ela pode spawnar vários veículos na base. Opa brother, tranquilo? Então. Como foi dito acima o sistema é por ACL, ou seja, somente os jogadores que estiverem com os logins adicionados a tal ACL (no caso a de "BOMBEIROS" terão como spawnar o veiculo) Fora as proteçoes quem tambem tem na base. Mas muito obrigado NeoGM, foi uma otima observação. Link to post
Rangel 0 Posted January 12, 2020 Author Share Posted January 12, 2020 Só escrevendo aqui para o post n ser esquecido, boa tarde. Link to post
Angelo Pereira 115 Posted January 12, 2020 Share Posted January 12, 2020 (edited) Spawn1 = createMarker(-65.258903503418, -343.11831665039, 5.4296875 -1,"cylinder", 1.9, 0, 0, 200, 40) Destroy = createMarker(-65.258903503418, -371.39807128906, 5.4296875 -2,"cylinder", 5.0, 128, 0, 0, 99) veh = {} function spawnvtr ( hitElement ) if getElementType(hitElement) == "player" and not isPedInVehicle(hitElement) then -- Adicionado if isElement( veh[hitElement] ) then destroyElement ( veh[hitElement] ) end local accName = getAccountName ( getPlayerAccount ( hitElement ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "BOMBEIROS") ) then veh[hitElement] = createVehicle(529, -61.04016494751, -303.79797363281, 5.3578243255615, 0, 0, 270 ) warpPedIntoVehicle ( hitElement, veh[hitElement] ) --exports._infobox:addNotification(hitElement, "", "success") else outputChatBox("#FFFFFF| #E10000BOMBEIROS #FFFFFF| Somente #E10000BOMBEIROS #FFFFFFPodem Pegar Este Veiculo.",hitElement,255,255,255, true) end end end addEventHandler("onMarkerHit", Spawn1, spawnvtr) function destroyvtr ( hitElement ) if isElement(veh[hitElement]) then destroyElement (veh[hitElement]) --exports._infobox:addNotification(thePlayer, "", "success") end end addEventHandler("onMarkerHit", Destroy, destroyvtr) Tente isso Edited January 12, 2020 by Angelo Pereira 1 Link to post
Rangel 0 Posted January 12, 2020 Author Share Posted January 12, 2020 Não Funcionou brother Link to post
Angelo Pereira 115 Posted January 12, 2020 Share Posted January 12, 2020 4 minutes ago, Rangel said: Não Funcionou brother Mostra algum erro no debugscript3? eu testei aqui é funcionou, verifique a ACL se está criada no seu GRUPO de ACLs 1 Link to post
Developer. 25 Posted January 12, 2020 Share Posted January 12, 2020 (edited) Observações: o seu código inicial @Rangel funciona! Mesmo tendo coisas sem sentidos como "comando" e "nick" em um addEventHandler e demais coisas, funciona sim! A unica coisa que não ocorre é o player poder destruir depois de ter saído do servidor! já o código do @Angelo Pereira é totalmente funcional e melhorado inclusive ( meus parabéns) Dito isso vamos lá, você tem 2 formas de fazer este Spawn de viaturas: Sistema 1 Para Criar a Vtr: local tableVehicle = {} local ACL = "BOMBEIROS" function spawnvtr ( mkr, dim ) if (dim) then -- verifica a dimensão if mkr == Spawn1 then -- verifica se a marker hitada é a de spawn. Se for então: local accName = getAccountName ( getPlayerAccount ( source ) ) -- pega a account do player if not isObjectInACLGroup ("user."..accName, aclGetGroup ( ACL) ) then -- se ele não for bombeiro ( não estiver na acl) então: outputChatBox("#FFFFFF| #E10000BOMBEIROS #FFFFFF| Somente #E10000BOMBEIROS #FFFFFFPodem Pegar Este Veiculo.", source,255,255,255, true) -- envia essa mensagem return -- termina a função, por precaução eu costumo fazer isto para evitar bug's! Poderia também usar um else no lugar do return! end -- se eu usar else, esse end aqui deveria ficar embaixo do warpPed! if tableVehicle[source] then -- se existir um valor na tableVehicle destroyElement ( tableVehicle[source] ) -- destroi oq esta na tableVehicle tableVehicle[source] = nil -- coloca tableVehicle como nil (anti-bug) end tableVehicle[source] = createVehicle(529, -2410.876, -600.848, 132.619, 0, 0, 270 ) -- cria o veículo e insere ele na tableVehicle setElementHealth (tableVehicle[source] , 200000) -- não entendi o porque de 200.000 de vida mas ok... warpPedIntoVehicle ( source, tableVehicle[source]) -- coloca o player dentro do veículo criado end end end addEventHandler("onPlayerMarkerHit", getRootElement(), spawnvtr) -- Obs: é de boa pratica sempre fazer as verificações negativas antes! Ex: -- Se o player não tiver isto ou não tiver aquilo então a função para de ser executada ou retorna! -- isto muitas das vezes evita bug :) Para destruir a Vtr: function destroyvtr ( mkr, dim ) if (dim) then if mkr == Destroy then local accName = getAccountName ( getPlayerAccount ( source ) ) if not isObjectInACLGroup ("user."..accName, aclGetGroup (ACL) ) then outputChatBox("#FFFFFF| #E10000BOMBEIROS #FFFFFF| Somente #E10000BOMBEIROS #FFFFFFPodem Destruir Este Veiculo.", source,255,255,255, true) return end if tableVehicle[source] then destroyElement (tableVehicle[source]) tableVehicle[source] = nil end end end end addEventHandler("onPlayerMarkerHit", getRootElement(), destroyvtr) Para quando o player sair do servidor: function onQuit() for _, player in ipairs(getElementsByType("player")) do -- faz um loop nos players online if tableVehicle[player] and isElement(tableVehicle[player]) then -- se o player possuia uma viatura antes de sair então: destroyElement (tableVehicle[player]) -- destroi a viatura tableVehicle[player] = nil end end end addEventHandler("onPlayerQuit", getRootElement(), onQuit) ______________________________________________________________________________________________________________________________________________________________________________________ Sistema 2 Para Criar a Vtr (mesmo código do outro sistema!): Obs: caso o player destrua a vtr, dará um erro no debug, mas nada grave! local tableVehicle = {} local ACL = "BOMBEIROS" function spawnvtr ( mkr, dim ) if (dim) then -- verifica a dimensão if mkr == Spawn1 then -- verifica se a marker hitada é a de spawn. Se for então: local accName = getAccountName ( getPlayerAccount ( source ) ) -- pega a account do player if not isObjectInACLGroup ("user."..accName, aclGetGroup (ACL) ) then -- se ele não for bombeiro ( não estivar na acl) então: outputChatBox("#FFFFFF| #E10000BOMBEIROS #FFFFFF| Somente #E10000BOMBEIROS #FFFFFFPodem Pegar Este Veiculo.", source,255,255,255, true) -- envia essa mensagem return -- termina a função, por precaução eu costumo fazer isto para evitar bug's! Poderia também usar um else no lugar do return! end -- se eu usar else, esse end aqui deveria ficar embaixo do warpPed! if tableVehicle[source] then -- se existir um valor na tableVehicle destroyElement ( tableVehicle[source] ) -- destroi oq esta na tableVehicle tableVehicle[source] = nil -- coloca tableVehicle como nil (anti-bug) end tableVehicle[source] = createVehicle(529, -2410.876, -600.848, 132.619, 0, 0, 270 ) -- cria o veículo e insere ele na tableVehicle setElementHealth (tableVehicle[source] , 200000) -- não entendi o porque de 200.000 de vida mas ok... warpPedIntoVehicle ( source, tableVehicle[source]) -- coloca o player dentro do veículo criado end end end addEventHandler("onPlayerMarkerHit", getRootElement(), spawnvtr) Para destruir a Vtr: function destruir(mkr, dim ) if (dim) then if mkr == Destroy then local accName = getAccountName ( getPlayerAccount ( source ) ) if not isObjectInACLGroup ("user."..accName, aclGetGroup (ACL) ) then outputChatBox("#FFFFFF| #E10000BOMBEIROS #FFFFFF| Somente #E10000BOMBEIROS #FFFFFFPodem Destruir Este Veiculo.", source,255,255,255, true) return end local vehicle = getPedOccupiedVehicle(source) -- retorna o veiculo que o player tá local modelo = getElementModel(vehicle) -- pega o modelo do veículo (id) local idViatura = {529, 429} -- tabela onde tem os id's que podem ser destruidos! for _, veiculo in ipairs(idViatura) do -- loop if (isElement(vehicle)) and (getElementType(vehicle)=="vehicle") and (modelo == veiculo) then -- se o que hitou a marker for um veículo e, o modelo(id) dele esta na tabela então: destroyElement (vehicle) -- destroi o veículo! end end end end end addEventHandler("onPlayerMarkerHit", getRootElement(), destruir) No sistema 2 não será necessário a parte do player sair do servidor pois qualquer pessoa que POSSUA a TAG, poderá destruir a viatura. Só para meio de conhecimento ainda há outras formas, uma delas é com o executeSQLQuery (database interna)! Caso tenha alguma duvida só pergunta! Obs: tenha certeza q a ACL "BOMBEIROS" esta criada, e que você esta nela!! Edited January 12, 2020 by Developer. 2 Link to post
Rangel 0 Posted January 13, 2020 Author Share Posted January 13, 2020 Ok, o sistema funcionou sim, eu que tinha colocado errado, muito obg a todos, só uma duvida como faço para um unico player conseguir pegar quantas vtr ele quiser e dps destruir uma a uma? Link to post
Angelo Pereira 115 Posted January 13, 2020 Share Posted January 13, 2020 Você removendo as linha onde destrói o veiculo quando pega outro veiculo, irá poder pegar além de 1 viatura, nos respectivos exemplos : if isElement( veh[hitElement] ) then destroyElement ( veh[hitElement] ) end --------------- OR ------------------- if tableVehicle[source] then -- se existir um valor na tableVehicle destroyElement ( tableVehicle[source] ) -- destroi oq esta na tableVehicle tableVehicle[source] = nil -- coloca tableVehicle como nil (anti-bug) end 1 1 Link to post
Rangel 0 Posted January 13, 2020 Author Share Posted January 13, 2020 Muito Obg, Tudo funcionando do jeito que eu queria e com debugscript 3 limpo !! Vcs sao DMS Link to post
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