Jump to content

[Ayuda] callClientFunction


Platin

Recommended Posts

Hola gente, desde hace una hora intento crear este resource pero mi cerebro no es capaz de comprender que pasa. La idea es la siguiente, crear un resource que cuando le hagas un Headshot a un zombie haga un efecto de sonido de Headshot, con 3 disponibles.

client.lua

function headshotsound () 
    local sound = playSound("sounds/headshot1.mp3") or playSound("sounds/headshot2.mp3") or playSound("sounds/headshot3.mp3") 
    setSoundVolume(sound, 0.5) 
end 
  
function callClientFunction(nombreFuncion, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do arg[key] = tonumber(value) or value end 
    end 
    loadstring("return "..nombreFuncion)()(unpack(arg)) 
end 
addEvent("onServerCallsClientFunction", true) 
addEventHandler("onServerCallsClientFunction", resourceRoot, callClientFunction) 
  

server.lua

function headshotKill ( bodypart ) 
    if bodypart == 9 then 
        callClientFunction(source, "headshotsound") 
    end 
end 
addEvent("onZombieWasted",true) 
addEventHandler ("OnZombieWasted", root, headshotKill) 
  
function callClientFunction(cliente, nombreFuncion, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do 
            if (type(value) == "number") then arg[key] = tostring(value) end 
        end 
    end 
    triggerClientEvent(cliente, "onServerCallsClientFunction", resourceRoot, nombreFuncion, unpack(arg or {})) 
end 

meta.xml

<meta> 
    <info author="Platin" type="script" name="Headshot Sounds" description="Simple Headshot Sound Producer" version="1.0.0" /> 
    <script src="server.lua" type="server" /> 
    <script src="client.lua" type="client" /> 
        <file src="sounds/headshot1.mp3" /> 
        <file src="sounds/headshot2.mp3" /> 
        <file src="sounds/headshot3.mp3" /> 
</meta> 

Necesitaría algo de ayuda ya que, no me sale ningún error, pero el resource no hace absolutamente nada, desde ya, ¡gracias!

Link to comment

no entendi muy bien lo que quieres hacer

si lo que quieres hacer es que salga un sonido al hazar de 3 opciones cada ves que matas un zombies

es halgo tan simple como esto

client.lua

local sounds = {"sounds/headshot1.mp3","sounds/headshot2.mp3","sounds/headshot3.mp3",} 
function Sound() 
         playSound(sounds[math.random(1, #sounds)]) 
end 
addEvent( "zombiedead", true ) 
addEventHandler( "zombiedead", root, Sound) 
  
  
  

server.lua

function zombiewasted (ammo, attacker, weapon, bodypart ) 
if (getElementType ( attacker ) == "player") and (bodypart == 9 ) then 
         triggerClientEvent( "zombiedead", attacker ) 
  end 
end 
addEvent("onZombieWasted",true) 
addEventHandler ("OnZombieWasted", root,  zombiewasted) 

Link to comment

Mucho más simple.

  
local sounds = {"sounds/headshot1.mp3","sounds/headshot2.mp3","sounds/headshot3.mp3",} 
addEventHandler("onClientPedWasted",root,function(killer,_,bodypart) 
if bodypart == 9 and getElementData(source,"zombie") and localPlayer == killer then 
sound = sounds[math.random(1, #sounds)]) 
playSound(sound) 
end 
end 
) 
  

Link to comment
no entendi muy bien lo que quieres hacer

si lo que quieres hacer es que salga un sonido al hazar de 3 opciones cada ves que matas un zombies

es halgo tan simple como esto

client.lua

local sounds = {"sounds/headshot1.mp3","sounds/headshot2.mp3","sounds/headshot3.mp3",} 
function Sound() 
         playSound(sounds[math.random(1, #sounds)]) 
end 
addEvent( "zombiedead", true ) 
addEventHandler( "zombiedead", root, Sound) 
  
  
  

server.lua

function zombiewasted (ammo, attacker, weapon, bodypart ) 
if (getElementType ( attacker ) == "player") and (bodypart == 9 ) then 
         triggerClientEvent( "zombiedead", attacker ) 
  end 
end 
addEvent("onZombieWasted",true) 
addEventHandler ("OnZombieWasted", root,  zombiewasted) 

Lo edité para que sea cuando le doy en la cabeza, no sirvió. Lo intente dejar para la idea que tuviste tu, solo con matarlo, tampoco funciono.

¿Alguna idea?

EDIT

Mucho más simple.
  
local sounds = {"sounds/headshot1.mp3","sounds/headshot2.mp3","sounds/headshot3.mp3",} 
addEventHandler("onClientPedWasted",root,function(killer,_,bodypart) 
if bodypart == 9 and getElementData(source,"zombie") and localPlayer == killer then 
sound = sounds[math.random(1, #sounds)]) 
playSound(sound) 
end 
end 
) 
  

No comprendo tu idea.

Link to comment

que parte no comprendes

local sounds = {"sounds/headshot1.mp3","sounds/headshot2.mp3","sounds/headshot3.mp3",} 
function Sound(killer,_,bodypart) 
       if bodypart == 9 and getElementData(source,"zombie") and localPlayer == killer then -- aca comprueba que la muerte sea por headshot , que el ped sea un zombies y que el que mato al ped sea el jugador local  
          sound = sounds[math.random(1, #sounds)])  -- aca se escoje el sonido al azar de todas las opciones del inicio 
          playSound(sound) 
        end 
end 
addEventHandler("onClientPedWasted",root, Sound) 

Link to comment
que parte no comprendes
local sounds = {"sounds/headshot1.mp3","sounds/headshot2.mp3","sounds/headshot3.mp3",} 
function Sound(killer,_,bodypart) 
       if bodypart == 9 and getElementData(source,"zombie") and localPlayer == killer then -- aca comprueba que la muerte sea por headshot , que el ped sea un zombies y que el que mato al ped sea el jugador local  
          sound = sounds[math.random(1, #sounds)])  -- aca se escoje el sonido al azar de todas las opciones del inicio 
          playSound(sound) 
        end 
end 
addEventHandler("onClientPedWasted",root, Sound) 

Vale, lo que no entendia era la linea 3.

¡Muchas gracias a los dos, funciona!

Por cierto, ¿les molestaría si los subo a la community? Principalmente porque no hay ni un resource así.

Link to comment
que parte no comprendes
local sounds = {"sounds/headshot1.mp3","sounds/headshot2.mp3","sounds/headshot3.mp3",} 
function Sound(killer,_,bodypart) 
       if bodypart == 9 and getElementData(source,"zombie") and localPlayer == killer then -- aca comprueba que la muerte sea por headshot , que el ped sea un zombies y que el que mato al ped sea el jugador local  
          sound = sounds[math.random(1, #sounds)])  -- aca se escoje el sonido al azar de todas las opciones del inicio 
          playSound(sound) 
        end 
end 
addEventHandler("onClientPedWasted",root, Sound) 

Vale, lo que no entendia era la linea 3.

¡Muchas gracias a los dos, funciona!

Por cierto, ¿les molestaría si los subo a la community? Principalmente porque no hay ni un resource así.

Claro que no, hazlo.

Lol también eres de Uruguay, el segundo que veo D:

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...