Jump to content

Custom sound trigger


Recommended Posts

So I have a custom dff and txd I've loaded onto the poolcue weapon,

My plan is to trigger a client side sound at the position of the ELEMENT or PLAYER when it is hit, and only when an element or player is hit.

to explain it another way, the guitar will have a custom sound play at the coordinates of the hit, and only when it is hitting an element or player

I've spent a lot of time looking through the scripting wiki forums and browsing through here, and haven found anything helpful yet, so any pointing in the right direction would be a help, you don't have the write the code for me lol

  
client.lua 
dff = engineLoadDFF("client/poolcue.dff",338 ) 
    engineReplaceModel(dff,338) 
  
txd = engineLoadTXD("client/poolcue.txd",false) 
    engineImportTXD(txd,338) 
     
function guitarDamage(thePlayer,weapon,bodypart) 
    if (weapon == 7) then 
        local x,y,z = getElementPosition(getLocalPlayer()) 
        local sound = playSound3D("client/guitar_1.wav", x,y,z) 
         
        outputChatBox("YOU GOT HIT",getLocalPlayer()) 
    end 
end 
addEventHandler("onClientPlayerDamage",getLocalPlayer(),guitarDamage) 

  
meta.xml 
<meta> 
    <info author="Shagwrath"/> 
     
    <script src="client.lua" type="client"/> 
    <script src="server.lua" type="server"/> 
     
    <file src="client/poolcue.dff"/> 
    <file src="client/poolcue.txd"/> 
     
    <file src="client/guitar_1.wav"/> 
</meta> 

Link to comment

Try this...

addEventHandler("onClientResourceStart", resourceRoot, 
    function ()  
        dff = engineLoadDFF("client/poolcue.dff",338 ) 
        engineReplaceModel(dff,338) 
        txd = engineLoadTXD("client/poolcue.txd",false) 
        engineImportTXD(txd,338) 
    end 
) 
  
function guitarDamage(attacker,weapon,bodypart) 
    if (weapon == 7) then 
        local x,y,z = getElementPosition(source) 
        local sound = playSound3D("client/guitar_1.wav", x,y,z) 
        outputChatBox("YOU GOT HIT",source) 
    end 
end 
addEventHandler("onClientPlayerDamage", localPlayer, guitarDamage) 

Link to comment

You need to handle the event for all players, then check if the local player was involved in the fight. Then you may play the music. Be careful though, with this implementation, the code is run for both the attacker and the defender, so making it print " you were hit" would make it print for the attacker as well.

  
dff = engineLoadDFF("client/poolcue.dff",338 ) 
engineReplaceModel(dff,338) 
  
txd = engineLoadTXD("client/poolcue.txd",false) 
engineImportTXD(txd,338) 
    
function guitarDamage(thePlayer,weapon,bodypart) 
    if (weapon == 7) and (attacker == localPlayer or source == localPlayer) then 
        local x,y,z = getElementPosition(getLocalPlayer()) 
        local sound = playSound3D("client/guitar_1.wav", x,y,z) 
    end 
end 
addEventHandler("onClientPlayerDamage", root ,guitarDamage) 
  

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...