Szerző Téma: MTA \"Egyedi\" Duda  (Megtekintve 1219 alkalommal)

Nem elérhető Tarack

  • 177
    • Profil megtekintése
MTA \"Egyedi\" Duda
« Dátum: 2017. Január 07. - 12:00:37 »
0
Sziasztok. Egyedi Dudát szeretnék készíteni. És ebből csak a hanglejátszásnál akadtam meg. Ha Client-ről triggerelem a PlaySound-ot serverre,akkor mindenki hallja,de mindenkinek aki kocsiban ül dudálni fog a kocsija. Ezt hogy tudnám kiküszöbölni hogy csak annak játszódjon le aki megnyomta a gombot,de viszont hallja mindenki aki körülötte van.
 
Előre is köszönöm a válaszaitokat! :) 
 
 

Nem elérhető id100

  • 903
    • Profil megtekintése
MTA \"Egyedi\" Duda
« Válasz #1 Dátum: 2017. Január 07. - 13:28:02 »
0
playSound? :D és triggerClientEvent, triggerServerEvent. átpasszintod a koordinátákat az eventbe, lejátszod a hangot minden embernek. Ha extrát is akarsz csak annak triggereld aki x koordinátán belül van a playerhez, de ez +számolás szerveroldalon, vagy teljesen mindegy ha már eljutott a kliensig.

Nem elérhető Live

  • 507
    • Profil megtekintése
MTA \"Egyedi\" Duda
« Válasz #2 Dátum: 2017. Január 07. - 14:48:06 »
0
Triggerelni is fölösleges, elég az elementData + onClientElementDataChange.
 

local vehiclesWithCustomHorns = {}
local previewingHorn = nil
bindKey(\"f2\", \"down\", -- Egyedi random duda beszerelés a kocsiba
function()
   local vehicle = getPedOccupiedVehicle(localPlayer)
   
   if vehicle then
      if getVehicleOccupant(vehicle, 0) == localPlayer then
         setElementData(vehicle, \"tuning.customHorn\", math.random(1, 10))
      end
   end
end
)
bindKey(\"f3\", \"down\", -- Egyedi duda eltávolítása a kocsiból
function()
   local vehicle = getPedOccupiedVehicle(localPlayer)
   
   if vehicle then
      if getVehicleOccupant(vehicle, 0) == localPlayer then
         setElementData(vehicle, \"tuning.customHorn\", nil)
      end
   end
end
)
bindKey(\"h\", \"down\",
function()
   local vehicle = getPedOccupiedVehicle(localPlayer)
   
   if vehicle then
      if getVehicleOccupant(vehicle, 0) == localPlayer then
         local customHorn = getElementData(vehicle, \"tuning.customHorn\") or nil
         
         if customHorn then
            toggleControl(\"horn\", false)
            setElementData(vehicle, \"customHorn.state\", true)
         else
            toggleControl(\"horn\", true)
         end
      end
   end
end
)
bindKey(\"h\", \"up\",
function()
   local vehicle = getPedOccupiedVehicle(localPlayer)
   
   if vehicle then
      if getVehicleOccupant(vehicle, 0) == localPlayer then
         local customHorn = getElementData(vehicle, \"tuning.customHorn\") or nil
         
         if customHorn then
            toggleControl(\"horn\", false)
            setElementData(vehicle, \"customHorn.state\", false)
         else
            toggleControl(\"horn\", true)
         end
      end
   end
end
)
addEventHandler(\"onClientElementDataChange\", root,
function(data)
   if getElementType(source) == \"vehicle\" then
      if data == \"tuning.customHorn\" then
         local customHorn = getElementData(source, \"tuning.customHorn\") or nil
         
         if not customHorn then
            if vehiclesWithCustomHorns[source] then
               if isElement(vehiclesWithCustomHorns[source]) then
                  stopSound(vehiclesWithCustomHorns[source])
               end
               
               vehiclesWithCustomHorns[source] = nil
            end
         end
      elseif data == \"customHorn.state\" then
         if isElementStreamedIn(source) then
            local hornState = getElementData(source, \"customHorn.state\") or false
            
            if hornState then
               local customHorn = getElementData(source, \"tuning.customHorn\") or nil
               
               if customHorn then
                  local vehicleX, vehicleY, vehicleZ = getElementPosition(source)
         
                  vehiclesWithCustomHorns[source] = playSound3D(\"horns/\" .. customHorn .. \".mp3\", vehicleX, vehicleY, vehicleZ, true)
                  
                  setSoundMaxDistance(vehiclesWithCustomHorns[source], 50)
                  attachElements(vehiclesWithCustomHorns[source], source)
                  
                  outputDebugString(\"[custom horn]: driver: \" .. getPlayerName(getVehicleOccupant(source, 0)))
               end
            else
               if vehiclesWithCustomHorns[source] then
                  if isElement(vehiclesWithCustomHorns[source]) then
                     stopSound(vehiclesWithCustomHorns[source])
                  end
                  
                  vehiclesWithCustomHorns[source] = nil
               end
            end
         end
      end
   end
end
)
addEventHandler(\"onClientElementStreamIn\", root,
function()
   if getElementType(source) == \"vehicle\" then
      local customHorn = getElementData(source, \"tuning.customHorn\") or nil
      
      if customHorn then
         local hornState = getElementData(source, \"customHorn.state\") or false
         
         if hornState then
            local vehicleX, vehicleY, vehicleZ = getElementPosition(source)
      
            vehiclesWithCustomHorns[source] = playSound3D(\"horns/\" .. customHorn .. \".mp3\", vehicleX, vehicleY, vehicleZ, true)
            
            setSoundMaxDistance(vehiclesWithCustomHorns[source], 50)
            attachElements(vehiclesWithCustomHorns[source], source)
            
            outputDebugString(\"[stream in] [custom horn]: driver: \" .. getPlayerName(getVehicleOccupant(source, 0)))
         end
      end
   end
end
)
addEventHandler(\"onClientElementStreamOut\", root,
function()
   if getElementType(source) == \"vehicle\" then
      local customHorn = getElementData(source, \"tuning.customHorn\") or nil
      
      if customHorn then
         if vehiclesWithCustomHorns[source] then
            if isElement(vehiclesWithCustomHorns[source]) then
               stopSound(vehiclesWithCustomHorns[source])
            end
            
            vehiclesWithCustomHorns[source] = nil
            outputDebugString(\"[stream out] [custom horn]: driver: \" .. getPlayerName(getVehicleOccupant(source, 0)))
         end
      end
   end
end
)
addEventHandler(\"onClientVehicleStartExit\", root,
function(_, seat)
   if seat == 0 then
      local customHorn = getElementData(source, \"tuning.customHorn\") or nil
      
      if customHorn then
         toggleControl(\"horn\", false)
         setElementData(source, \"customHorn.state\", false)
      else
         toggleControl(\"horn\", true)
      end
   end
end
)
addEventHandler(\"onClientElementDestroy\", root,
function()
   if getElementType(source) == \"vehicle\" then
      local customHorn = getElementData(source, \"tuning.customHorn\") or nil
      
      if customHorn then
         if vehiclesWithCustomHorns[source] then
            if isElement(vehiclesWithCustomHorns[source]) then
               stopSound(vehiclesWithCustomHorns[source])
            end
            
            vehiclesWithCustomHorns[source] = nil
         end
      end
   end
end
)
function previewHorn(horn)
if horn then
   if fileExists(\"horns/\" .. horn .. \".mp3\") then
      if isElement(previewingHorn) then
         stopSound(previewingHorn)
      end
   
      previewingHorn = playSound(\"horns/\" .. horn .. \".mp3\", false)
   else
      if isElement(previewingHorn) then
         stopSound(previewingHorn)
      end
   
      previewingHorn = nil
   end
else
   if isElement(previewingHorn) then
      stopSound(previewingHorn)
   end
   
   previewingHorn = nil
end
end

 
 

Nem elérhető Tarack

  • 177
    • Profil megtekintése
MTA \"Egyedi\" Duda
« Válasz #3 Dátum: 2017. Január 07. - 15:22:26 »
0
Köszönöm szépen,már megoldottam. Ez egy kicsit bonyolult. :D

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal