Jump to content

[DUVIDA]] Objeto invisivel para outro jogador


Recommended Posts

  • Moderators

Alguns scripts o ideal é ficar no lado client.

Lado server: Coisas importantes relativas à segurança e tudo mais o que não puder ser feito no cliente, como funções que irão sincronizar entre os players.

Lado Cliente: Coisas que demanda uso de performance; tudo o que não se aplicar acima. Se você jugar como algo voltado ao cliente e que não comprometa a segurança então certamente se aplica ao lado do cliente.

Evitar o lado server também ajuda na performance do servidor.

Quanto ao seu caso, dá pra adaptar o código funcionando apenas para um jogador com a função mencionada, se puder mostre seu código aqui.

Link to comment
local Marker_Start = createMarker (-111.1279296875, -4.025390625, 3.1171875 -1, "cylinder", 1.5, 20, 70, 230, 80 )
Blip_Start = createBlipAttachedTo(Marker_Start, 42)

Plantas = {
   [1] = {-129.10345458984,44.776748657227,3.1171875},
   [2] = {-140.21569824219,35.499088287354,3.1171875},
   [3] = {-138.20004272461,22.663047790527,3.1171875},
   [4] = {-148.60707092285,14.514667510986,3.1171875},
   [5] = {-145.90365600586,3.4965758323669,3.1171875},
   [6] = {-156.54542541504,-6.012909412384,3.1171875},
   [7] = {-154.13597106934,-17.593681335449,3.1171875},
   [8] = {-164.40188598633,-27.394626617432,3.1171875},
   [9] = {-162.29643249512,-39.118156433105,3.1171875},
   [10] = {-171.7504119873,-45.86404800415,3.1171875},
}

local Veh_Trator = {}
local Coronas_Plantas = {}
local Obj_Plantas = {}
local Letra = "K"

function jobStart(theJogador)
   if getElementType(theJogador) == "player" then
      if not getPedOccupiedVehicle(theJogador) and not Coronas_Plantas[theJogador] then
         exports.Scripts_OnMarkerMsgs_:delete(theJogador)
         jobStop()
         local x, y, z = unpack (Plantas[1])
         Coronas_Plantas[theJogador] = createMarker (x, y, z -1, "corona", 2, 0, 255, 0, 80, theJogador)
         setElementData (Coronas_Plantas[theJogador], "DnO_Coronas", theJogador)
         setElementData (Coronas_Plantas[theJogador], "Plantas", 1)
         Obj_Plantas[theJogador] = createObject(804, x, y, z)
         setElementData(Obj_Plantas[theJogador], "DnO_Obj", theJogador)
         setObjectScale(Obj_Plantas[theJogador], 1.0)
         setElementCollisionsEnabled (Obj_Plantas[theJogador], false)
         setPedSkin(theJogador, 158)
         Veh_Trator[theJogador] = createVehicle(531, -123.7235625, 64.36328125, 3.3815598964391, 0, 0, 156)
         setElementData(Veh_Trator[theJogador], "DnO_Trator", theJogador)
         warpPedIntoVehicle( theJogador, Veh_Trator[theJogador])
         exports.Scripts_Dxmessages:outputDx (theJogador,"Colher todas as Plantas!!", "info")
         addEventHandler ("onMarkerHit", Coronas_Plantas[theJogador], Hit_Coronas)
      end
   end
end

function emarker(marker,md) 
   if (md) then
     if isPedInVehicle ( source ) then return end
      if marker == Marker_Start then
          if getElementData ( source, "Emprego" ) == "Fazendeiro" then
            exports.Scripts_OnMarkerMsgs_:create(source,"Aperte 'K' Para se Demitir do Emprego de Fazendeiro")
            bindKey ( source, Letra, "down", jobStop )
         else
            exports.Scripts_OnMarkerMsgs_:create(source,"Aperte 'K' Para Aceitar o Emprego de Fazendeiro")
            bindKey ( source, Letra, "down", jobStart )
         end
      end
   end   
end
addEventHandler("onPlayerMarkerHit",getRootElement(),emarker)

function emarker2(marker,md) 
   if (md) then
     if isPedInVehicle ( source ) then return end
      if marker == Marker_Start then
         exports.Scripts_OnMarkerMsgs_:delete(source)
         unbindKey ( source, Letra, "down", jobStart )
         unbindKey ( source, Letra, "down", jobStop )
      end
   end   
end
addEventHandler("onPlayerMarkerLeave",getRootElement(),emarker2)

function Hit_Coronas(thePlayer)
   if (thePlayer == getElementData (source, "DnO_Coronas")) then
      if isPedInVehicle ( thePlayer ) then
         if (getElementData (source, "Plantas") < #Plantas) then
            exports.Scripts_Dxmessages:outputDx(thePlayer, "Você colheu a Planta. Siga para a próxima.("..getElementData(source, "Plantas").."/"..#Plantas..")", "success")
            setElementData (source, "Plantas", getElementData (source, "Plantas") + 1)
            local x, y, z = unpack(Plantas[getElementData(source, "Plantas")])
            setElementPosition(source, x, y, z -1)
            setElementPosition(Obj_Plantas[thePlayer], x, y, z)
         else
            removeEventHandler ("onMarkerHit", Coronas_Plantas[thePlayer], Hit_Coronas)
            if isElement(Veh_Trator[thePlayer]) then destroyElement(Veh_Trator[thePlayer]) end
            if isElement(Coronas_Plantas[thePlayer]) then destroyElement(Coronas_Plantas[thePlayer]) end
            if isElement(Obj_Plantas[thePlayer]) then destroyElement(Obj_Plantas[thePlayer]) end
            exports.Scripts_Dxmessages:outputDx (thePlayer,"Você terminou de Colher Todas as Plantas bom Trabalho!!", "success")
         end
      end
   end
end

function jobStop(source)
   if isElement(Veh_Trator[source]) then destroyElement(Veh_Trator[source]) end
   if isElement(Coronas_Plantas[source]) then destroyElement(Coronas_Plantas[source]) end
   if isElement(Obj_Plantas[source]) then destroyElement(Obj_Plantas[source]) end
end

function resourceStartNotify ( resourcename )
   if ( resourcename == getThisResource() ) then
      outputDebugString ( "Script " .. getResourceName(resourcename) .. " carregado." )
   end
end
addEventHandler( "onResourceStart", getRootElement(), resourceStartNotify )

 

Link to comment
  • Moderators

Na verdade não vai funcionar com objects:

Quote

This function can change an element's visibility. This does not work with all entities - vehicles, players and objects are exempt. This is because these objects are required for accurate sync (they're physical objects that contribute to the physics engine). This function is particularly useful for changing the visibility of markers, radar blips and radar areas.

Então nesse caso você precisa criar o object no lado cliente.

Fiz poucas mudanças no código, como uma verificação com isElementVisibleTo no onMarkerHit e limpar a tabela quando o player sair.

local Marker_Start = createMarker (-111.1279296875, -4.025390625, 3.1171875 -1, "cylinder", 1.5, 20, 70, 230, 80)
local Blip_Start = createBlipAttachedTo(Marker_Start, 42)

local Plantas = {
   [1] = {-129.10345458984,44.776748657227,3.1171875},
   [2] = {-140.21569824219,35.499088287354,3.1171875},
   [3] = {-138.20004272461,22.663047790527,3.1171875},
   [4] = {-148.60707092285,14.514667510986,3.1171875},
   [5] = {-145.90365600586,3.4965758323669,3.1171875},
   [6] = {-156.54542541504,-6.012909412384,3.1171875},
   [7] = {-154.13597106934,-17.593681335449,3.1171875},
   [8] = {-164.40188598633,-27.394626617432,3.1171875},
   [9] = {-162.29643249512,-39.118156433105,3.1171875},
   [10] = {-171.7504119873,-45.86404800415,3.1171875},
}

local Veh_Trator = {}
local Coronas_Plantas = {}
local Obj_Plantas = {}
local Letra = "K"

function jobStart(theJogador)
   if getElementType(theJogador) == "player" then
      if not getPedOccupiedVehicle(theJogador) and not Coronas_Plantas[theJogador] then
         exports.Scripts_OnMarkerMsgs_:delete(theJogador)
         jobStop()
         local x, y, z = unpack (Plantas[1])
         Coronas_Plantas[theJogador] = createMarker (x, y, z -1, "corona", 2, 0, 255, 0, 80, theJogador)
         setElementData (Coronas_Plantas[theJogador], "DnO_Coronas", theJogador)
         setElementData (Coronas_Plantas[theJogador], "Plantas", 1)
         Obj_Plantas[theJogador] = createObject(804, x, y, z)
         setElementData(Obj_Plantas[theJogador], "DnO_Obj", theJogador)
         setObjectScale(Obj_Plantas[theJogador], 1.0)
         setElementCollisionsEnabled (Obj_Plantas[theJogador], false)
         setElementModel(theJogador, 158) -- use esta função já que setPedSkin é obsoleta
         Veh_Trator[theJogador] = createVehicle(531, -123.7235625, 64.36328125, 3.3815598964391, 0, 0, 156)
         setElementData(Veh_Trator[theJogador], "DnO_Trator", theJogador)
         warpPedIntoVehicle( theJogador, Veh_Trator[theJogador])
         exports.Scripts_Dxmessages:outputDx (theJogador,"Colher todas as Plantas!!", "info")
         addEventHandler ("onMarkerHit", Coronas_Plantas[theJogador], Hit_Coronas)
      end
   end
end

function emarker(marker,md) 
   if (md) then
     if isPedInVehicle ( source ) then return end
      if marker == Marker_Start then
          if getElementData ( source, "Emprego" ) == "Fazendeiro" then
            exports.Scripts_OnMarkerMsgs_:create(source,"Aperte 'K' Para se Demitir do Emprego de Fazendeiro")
            bindKey ( source, Letra, "down", jobStop )
         else
            exports.Scripts_OnMarkerMsgs_:create(source,"Aperte 'K' Para Aceitar o Emprego de Fazendeiro")
            bindKey ( source, Letra, "down", jobStart )
         end
      end
   end   
end
addEventHandler("onPlayerMarkerHit",getRootElement(),emarker)

function emarker2(marker,md) 
   if (md) then
     if isPedInVehicle ( source ) then return end
      if marker == Marker_Start then
         exports.Scripts_OnMarkerMsgs_:delete(source)
         unbindKey ( source, Letra, "down", jobStart )
         unbindKey ( source, Letra, "down", jobStop )
      end
   end   
end
addEventHandler("onPlayerMarkerLeave",getRootElement(),emarker2)

function Hit_Coronas(thePlayer)
	if (thePlayer == getElementData (source, "DnO_Coronas")) and isElementVisibleTo(source, thePlayer) then
      if isPedInVehicle ( thePlayer ) then
         if (getElementData (source, "Plantas") < #Plantas) then
            exports.Scripts_Dxmessages:outputDx(thePlayer, "Você colheu a Planta. Siga para a próxima.("..getElementData(source, "Plantas").."/"..#Plantas..")", "success")
            setElementData (source, "Plantas", getElementData (source, "Plantas") + 1)
            local x, y, z = unpack(Plantas[getElementData(source, "Plantas")])
            setElementPosition(source, x, y, z -1)
            setElementPosition(Obj_Plantas[thePlayer], x, y, z)
         else
            removeEventHandler ("onMarkerHit", Coronas_Plantas[thePlayer], Hit_Coronas)
            jobStop( source )
            exports.Scripts_Dxmessages:outputDx (thePlayer,"Você terminou de Colher Todas as Plantas bom Trabalho!!", "success")
         end
      end
   end
end

-- limpar as tabelas quando o jogador sair
addEventHandler("onPlayerQuit", root, function()
	jobStop( source )
end)

function jobStop(source)
	if Obj_Plantas[source] then
		if isElement(Obj_Plantas[source]) then destroyElement(Obj_Plantas[source]) end
		Obj_Plantas[source] = nil
	end
	if Veh_Trator[source] then
		if isElement(Veh_Trator[source]) then destroyElement(Veh_Trator[source]) end
		Veh_Trator[source] = nil
	end
	if Coronas_Plantas[source] then
		if isElement(Coronas_Plantas[source]) then destroyElement(Coronas_Plantas[source]) end
		Coronas_Plantas[source] = nil
	end
end

function resourceStartNotify ( resourcename )
  outputDebugString ( "Script " .. getResourceName(resourcename) .. " carregado." )
end
addEventHandler( "onResourceStart", resourceRoot, resourceStartNotify ) -- use resourceRoot para o evento acionar só pra este resource

 

  • Thanks 1
Link to comment
54 minutes ago, Lord Henry said:

Pensei em fazer. Mas fiquei com mais preguiça do que a preguiça do cara do post em tentar por conta própria.

Tentando eu to so que nao consigo aprender pelo wiki as vezes consigo.

 

local Marker_Start = createMarker (-122.4150390625, 43.732421875, 3.1171875 -1, "cylinder", 2, 20, 70, 230, 80)
local Blip_Start = createBlipAttachedTo(Marker_Start, 42)

local Plantas = {
   [1] = {-129.10345458984,44.776748657227,3.1171875},
   [2] = {-140.21569824219,35.499088287354,3.1171875},
   [3] = {-138.20004272461,22.663047790527,3.1171875},
   [4] = {-148.60707092285,14.514667510986,3.1171875},
   [5] = {-145.90365600586,3.4965758323669,3.1171875},
   [6] = {-156.54542541504,-6.012909412384,3.1171875},
   [7] = {-154.13597106934,-17.593681335449,3.1171875},
   [8] = {-164.40188598633,-27.394626617432,3.1171875},
   [9] = {-162.29643249512,-39.118156433105,3.1171875},
   [10] = {-171.7504119873,-45.86404800415,3.1171875},
}

local Coronas_Plantas = {}
local Obj_Plantas = {}

function jobStart(theJogador)
   if getElementType(theJogador) == "player" then
      if not getPedOccupiedVehicle(theJogador) and not Coronas_Plantas[theJogador] then
         local x, y, z = unpack (Plantas[1])
         Coronas_Plantas[theJogador] = createMarker (x, y, z -1, "corona", 2, 0, 255, 0, 80, theJogador)
         setElementData (Coronas_Plantas[theJogador], "DnO_Coronas", theJogador)
         setElementData (Coronas_Plantas[theJogador], "Plantas", 1)
         Obj_Plantas[theJogador] = createObject(804, x, y, z)
         setElementData(Obj_Plantas[theJogador], "DnO_Obj", theJogador)
         setObjectScale(Obj_Plantas[theJogador], 1.0)
         setElementCollisionsEnabled (Obj_Plantas[theJogador], false)
         addEventHandler ("onClientMarkerHit", Coronas_Plantas[theJogador], Hit_Coronas)
      end
   end
end
addEventHandler ("onClientMarkerHit", Marker_Start, jobStart)

function Hit_Coronas(thePlayer)
   if (thePlayer == getElementData (source, "DnO_Coronas")) then
         if (getElementData (source, "Plantas") < #Plantas) then
            setElementData (source, "Plantas", getElementData (source, "Plantas") + 1)
            local x, y, z = unpack(Plantas[getElementData(source, "Plantas")])
            setElementPosition(source, x, y, z -1)
            setElementPosition(Obj_Plantas[thePlayer], x, y, z)
         else
            removeEventHandler ("onClientMarkerHit", Coronas_Plantas[thePlayer], Hit_Coronas)
       end
   end
endlocal Marker_Start = createMarker (-122.4150390625, 43.732421875, 3.1171875 -1, "cylinder", 2, 20, 70, 230, 80)
local Blip_Start = createBlipAttachedTo(Marker_Start, 42)

local Plantas = {
   [1] = {-129.10345458984,44.776748657227,3.1171875},
   [2] = {-140.21569824219,35.499088287354,3.1171875},
   [3] = {-138.20004272461,22.663047790527,3.1171875},
   [4] = {-148.60707092285,14.514667510986,3.1171875},
   [5] = {-145.90365600586,3.4965758323669,3.1171875},
   [6] = {-156.54542541504,-6.012909412384,3.1171875},
   [7] = {-154.13597106934,-17.593681335449,3.1171875},
   [8] = {-164.40188598633,-27.394626617432,3.1171875},
   [9] = {-162.29643249512,-39.118156433105,3.1171875},
   [10] = {-171.7504119873,-45.86404800415,3.1171875},
}

local Coronas_Plantas = {}
local Obj_Plantas = {}

function jobStart(theJogador)
   if getElementType(theJogador) == "player" then
      if not getPedOccupiedVehicle(theJogador) and not Coronas_Plantas[theJogador] then
         local x, y, z = unpack (Plantas[1])
         Coronas_Plantas[theJogador] = createMarker (x, y, z -1, "corona", 2, 0, 255, 0, 80, theJogador)
         setElementData (Coronas_Plantas[theJogador], "DnO_Coronas", theJogador)
         setElementData (Coronas_Plantas[theJogador], "Plantas", 1)
         Obj_Plantas[theJogador] = createObject(804, x, y, z)
         setElementData(Obj_Plantas[theJogador], "DnO_Obj", theJogador)
         setObjectScale(Obj_Plantas[theJogador], 1.0)
         setElementCollisionsEnabled (Obj_Plantas[theJogador], false)
         addEventHandler ("onClientMarkerHit", Coronas_Plantas[theJogador], Hit_Coronas)
      end
   end
end
addEventHandler ("onClientMarkerHit", Marker_Start, jobStart)

function Hit_Coronas(thePlayer)
   if (thePlayer == getElementData (source, "DnO_Coronas")) then
         if (getElementData (source, "Plantas") < #Plantas) then
            setElementData (source, "Plantas", getElementData (source, "Plantas") + 1)
            local x, y, z = unpack(Plantas[getElementData(source, "Plantas")])
            setElementPosition(source, x, y, z -1)
            setElementPosition(Obj_Plantas[thePlayer], x, y, z)
         else
            removeEventHandler ("onClientMarkerHit", Coronas_Plantas[thePlayer], Hit_Coronas)
       end
   end
end

Essa parte refiz no client-side mas ainda o objeto aparece para outro jogador não sei quais partes eu errei.

Obs:Nenhum erro no debug

Link to comment
  • Moderators

Client

local Marker_Start = createMarker (-111.1279296875, -4.025390625, 3.1171875 -1, "cylinder", 1.5, 20, 70, 230, 80)
local Blip_Start = createBlipAttachedTo(Marker_Start, 42)

local Plantas = {
   [1] = {-129.10345458984,44.776748657227,3.1171875},
   [2] = {-140.21569824219,35.499088287354,3.1171875},
   [3] = {-138.20004272461,22.663047790527,3.1171875},
   [4] = {-148.60707092285,14.514667510986,3.1171875},
   [5] = {-145.90365600586,3.4965758323669,3.1171875},
   [6] = {-156.54542541504,-6.012909412384,3.1171875},
   [7] = {-154.13597106934,-17.593681335449,3.1171875},
   [8] = {-164.40188598633,-27.394626617432,3.1171875},
   [9] = {-162.29643249512,-39.118156433105,3.1171875},
   [10] = {-171.7504119873,-45.86404800415,3.1171875},
}

local Coronas_Plantas
local Obj_Plantas
local Letra = "K"

function onClientMarkerHitFunc(hitPlayer, md)
	if localPlayer ~= hitPlayer or not (md) then return end
	
	if not getPedOccupiedVehicle(hitPlayer) then
		if getElementData ( hitPlayer, "Emprego" ) == "Fazendeiro" then
			exports.Scripts_OnMarkerMsgs_:create("Aperte 'K' Para se Demitir do Emprego de Fazendeiro")
			bindKey ( Letra, "down", jobStop, true )
		else
			exports.Scripts_OnMarkerMsgs_:create("Aperte 'K' Para Aceitar o Emprego de Fazendeiro")
			bindKey ( Letra, "down", jobStart )
		end
	end 
end
addEventHandler("onClientMarkerHit",Marker_Start,onClientMarkerHitFunc)

function emarker2(p,md) 
	if localPlayer ~= p or not (md) then return end
	if not getPedOccupiedVehicle(p) then
		exports.Scripts_OnMarkerMsgs_:delete(source)
		unbindKey ( Letra, "down", jobStart )
		unbindKey ( Letra, "down", jobStop )
	end
end
addEventHandler("onClientMarkerLeave",Marker_Start,emarker2)

function jobStart()
	if not getPedOccupiedVehicle(localPlayer) then
		exports.Scripts_OnMarkerMsgs_:delete(localPlayer)
		jobStop()
		local x, y, z = unpack (Plantas[1])
		
		Coronas_Plantas = createMarker (x, y, z -1, "corona", 2, 0, 255, 0, 80)
		setElementData (Coronas_Plantas, "Plantas", 1)
		addEventHandler ("onClientMarkerHit", Coronas_Plantas, Hit_Coronas)
		
		Obj_Plantas = createObject(804, x, y, z)
		setElementData(Obj_Plantas, "DnO_Obj", localPlayer)
		setObjectScale(Obj_Plantas, 1.0)
		setElementCollisionsEnabled (Obj_Plantas, false)
		
		triggerServerEvent( "Fazendeiro:onRequestGivePlayerVehicle", localPlayer )
			
		unbindKey ( Letra, "down", jobStart )
		unbindKey ( Letra, "down", jobStop )
	end
end

function Hit_Coronas(hitPlayer, md)
	if getPedOccupiedVehicle(hitPlayer) then
		local plantas = getElementData (source, "Plantas")
		if plantas and (plantas < #Plantas) then
			exports.Scripts_Dxmessages:outputDx( "Você colheu a Planta. Siga para a próxima.("..tostring(plantas).."/"..#Plantas..")", "success")
			setElementData (source, "Plantas", plantas + 1)
			local x, y, z = unpack(Plantas[plantas])
			setElementPosition(source, x, y, z -1)
			setElementPosition(Obj_Plantas, x, y, z)
		else
			removeEventHandler ("onClientMarkerHit", Coronas_Plantas, Hit_Coronas)
			exports.Scripts_Dxmessages:outputDx ("Você terminou de Colher Todas as Plantas bom Trabalho!!", "success")
		end
	end
end

function jobStop( removeFromJob )
	if Obj_Plantas then
		if isElement(Obj_Plantas) then destroyElement(Obj_Plantas) end
		Obj_Plantas = nil
	end
	if Coronas_Plantas then
		if isElement(Coronas_Plantas) then destroyElement(Coronas_Plantas) end
		Coronas_Plantas = nil
	end
	if removeFromJob then
		setElementData ( localPlayer, "Emprego", "N/A" )
	end
end

Server


local Veh_Trator = {}

addEvent( "Fazendeiro:onRequestGivePlayerVehicle", true )
addEventHandler( "Fazendeiro:onRequestGivePlayerVehicle", root, function()
	
	if source ~= client then return end
	if Veh_Trator[client] then
		if isElement(Veh_Trator[client]) then destroyElement(Veh_Trator[client]) end
		Veh_Trator[client] = nil
	end
	setElementModel(client, 158)
	Veh_Trator[client] = createVehicle(531, -123.7235625, 64.36328125, 3.3815598964391, 0, 0, 156)
	warpPedIntoVehicle( client, Veh_Trator[client])
	setElementData(Veh_Trator[client], "DnO_Trator", client)
	setElementData ( client, "Emprego", "Fazendeiro" )
	
	exports.Scripts_Dxmessages:outputDx (client, "Colher todas as Plantas!!", "info")
end )

addEventHandler( "onPlayerQuit", root, function()
	if Veh_Trator[source] then
		if isElement(Veh_Trator[source]) then destroyElement(Veh_Trator[source]) end
		Veh_Trator[source] = nil
	end
end )

Não testado.

Obs: revise as funções exportadas, eu removi o player do argumento e deve existir uma versão client side exportada.

  • Like 1
Link to comment
  • Moderators

Tente:

local Marker_Start = createMarker (-111.1279296875, -4.025390625, 3.1171875 -1, "cylinder", 1.5, 20, 70, 230, 80)
local Blip_Start = createBlipAttachedTo(Marker_Start, 42)

local Plantas = {
   [1] = {-129.10345458984,44.776748657227,3.1171875},
   [2] = {-140.21569824219,35.499088287354,3.1171875},
   [3] = {-138.20004272461,22.663047790527,3.1171875},
   [4] = {-148.60707092285,14.514667510986,3.1171875},
   [5] = {-145.90365600586,3.4965758323669,3.1171875},
   [6] = {-156.54542541504,-6.012909412384,3.1171875},
   [7] = {-154.13597106934,-17.593681335449,3.1171875},
   [8] = {-164.40188598633,-27.394626617432,3.1171875},
   [9] = {-162.29643249512,-39.118156433105,3.1171875},
   [10] = {-171.7504119873,-45.86404800415,3.1171875},
}

local Coronas_Plantas
local Obj_Plantas
local Letra = "K"

function onClientMarkerHitFunc(hitPlayer, md)
	if localPlayer ~= hitPlayer or not (md) then return end
	
	if Coronas_Plantas and source == Coronas_Plantas and getElementData(hitPlayer, "Emprego") == "Fazendeiro" then
		if not getPedOccupiedVehicle(hitPlayer) then return end
		
		local _plantas = getElementData (source, "Plantas") or 1
		if _plantas and (_plantas < #Plantas) then
			_plantas = _plantas + 1
			exports.Scripts_Dxmessages:outputDx( "Você colheu a Planta. Siga para a próxima.("..tostring(_plantas).."/"..#Plantas..")", "success")
			setElementData (source, "Plantas", _plantas)
			local x, y, z = unpack(Plantas[_plantas])
			setElementPosition(source, x, y, z -1)
			setElementPosition(Obj_Plantas, x, y, z)
		else
			jobStop()
			exports.Scripts_Dxmessages:outputDx ("Você terminou de Colher Todas as Plantas bom Trabalho!!", "success")
			triggerServerEvent( "Fazendeiro:onRequestRemovePlayerVehicle", localPlayer )
		end
		return
	end
	if source == Marker_Start and not getPedOccupiedVehicle(hitPlayer) then
		if getElementData ( hitPlayer, "Emprego" ) == "Fazendeiro" then
			exports.Scripts_OnMarkerMsgs_:create("Aperte 'K' Para se Demitir do Emprego de Fazendeiro")
			bindKey ( Letra, "down", jobStop, true )
		else
			exports.Scripts_OnMarkerMsgs_:create("Aperte 'K' Para Aceitar o Emprego de Fazendeiro")
			bindKey ( Letra, "down", jobStart )
		end
	end 
end
addEventHandler("onClientMarkerHit",resourceRoot,onClientMarkerHitFunc)

function emarker2(p,md) 
	if localPlayer ~= p or not (md) then return end
	if not getPedOccupiedVehicle(p) then
		exports.Scripts_OnMarkerMsgs_:delete(source)
		unbindKey ( Letra, "down", jobStart )
		unbindKey ( Letra, "down", jobStop )
	end
end
addEventHandler("onClientMarkerLeave",Marker_Start,emarker2)

function jobStart()
	if not getPedOccupiedVehicle(localPlayer) then
		exports.Scripts_OnMarkerMsgs_:delete(localPlayer)
		jobStop()
		local x, y, z = unpack (Plantas[1])
		
		Coronas_Plantas = createMarker (x, y, z -1, "corona", 2, 0, 255, 0, 80)
		setElementData (Coronas_Plantas, "Plantas", 1)
		
		Obj_Plantas = createObject(804, x, y, z)
		setElementData(Obj_Plantas, "DnO_Obj", localPlayer)
		setObjectScale(Obj_Plantas, 1.0)
		setElementCollisionsEnabled (Obj_Plantas, false)
		
		triggerServerEvent( "Fazendeiro:onRequestGivePlayerVehicle", localPlayer )
			
		unbindKey ( Letra, "down", jobStart )
		unbindKey ( Letra, "down", jobStop )
	end
end

addEventHandler( "onClientPlayerWasted", localPlayer, function()
	if getElementData(source, "Emprego") == "Fazendeiro" then
		if Coronas_Plantas then
			jobStop( )
		end
	end
end )

function jobStop( removeFromJob )
	if Obj_Plantas then
		if isElement(Obj_Plantas) then destroyElement(Obj_Plantas) end
		Obj_Plantas = nil
	end
	if Coronas_Plantas then
		if isElement(Coronas_Plantas) then destroyElement(Coronas_Plantas) end
		Coronas_Plantas = nil
	end
	if removeFromJob then
		setElementData ( localPlayer, "Emprego", "N/A" )
	end
end
addEvent( "Fazendeiro:jobStop", true )
addEventHandler( "Fazendeiro:jobStop", root, jobStop )

server

local Veh_Trator = {}

addEvent( "Fazendeiro:onRequestGivePlayerVehicle", true )
addEventHandler( "Fazendeiro:onRequestGivePlayerVehicle", root, function()
	
	if source ~= client then return end
	if Veh_Trator[client] then
		if isElement(Veh_Trator[client]) then destroyElement(Veh_Trator[client]) end
		Veh_Trator[client] = nil
	end
	setElementModel(client, 158)
	Veh_Trator[client] = createVehicle(531, -123.7235625, 64.36328125, 3.3815598964391, 0, 0, 156)
	warpPedIntoVehicle( client, Veh_Trator[client])
	setElementData(Veh_Trator[client], "DnO_Trator", client)
	setElementData ( client, "Emprego", "Fazendeiro" )
	
	local thePlayer = source
	addEventHandler( "onVehicleExplode", Veh_Trator[source], function()
	
		exports.Scripts_Dxmessages:outputDx (thePlayer, "Seu veículo do trabalho explodiu!", "info")
		triggerClientEvent( thePlayer, "Fazendeiro:jobStop", thePlayer )
		destroyElement(source)
		Veh_Trator[thePlayer] = nil
	end )
	
	exports.Scripts_Dxmessages:outputDx (client, "Colher todas as Plantas!!", "info")
end )

addEvent( "Fazendeiro:onRequestRemovePlayerVehicle", true )
addEventHandler( "Fazendeiro:onRequestRemovePlayerVehicle", root, function()
	
	if Veh_Trator[client] then
		if isElement(Veh_Trator[client]) then destroyElement(Veh_Trator[client]) end
		Veh_Trator[client] = nil
	end
end )

addEventHandler( "onPlayerQuit", root, function()
	if Veh_Trator[source] then
		if isElement(Veh_Trator[source]) then destroyElement(Veh_Trator[source]) end
		Veh_Trator[source] = nil
	end
end )

 

  • Thanks 1
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...