Jump to content

Add sounds to commandhandler


Reacer

Recommended Posts

I have a problem with adding sounds to my commandhandler!

addCommandHandler("bye", 
function (thePlayer) 
outputChatBox(getPlayerName(thePlayer).." would like to say Bye Everyone!",getRootElement(),255,0,0) 
end) 
elseif command == "bye" then playSoundToAll( "sounds/bye.mp3"); text = ptag1 .. "would like to say Bye Everyone! 
 

Link to comment

This is a totally mess. What 'elseif' is doing outside of your function? Where is the 'command' variable declared and what the hell is 'playSoundToAll' ?

--SERVER SIDE 
addCommandHandler( "bye", function( thePlayer, cmd ) 
  outputChatBox( getPlayerName( thePlayer ).." would like to say Bye Everyone!", root, 255, 0, 0 ) 
  triggerClientEvent( root, "playByeSound", root ) 
end ) 
  
--CLIENT SIDE 
addEvent( "playByeSound", true ) 
addEventHandler( "playByeSound", root, function() 
  playSound( "byebye.mp3", false ) 
end ) 

Link to comment

o.0

There are 2 separate files

client.lua

addEvent( "playByeSound", true ) 
addEventHandler( "playByeSound", root, function() 
  playSound( "byebye.mp3", false ) 
end ) 

server.lua

addCommandHandler( "bye", function( thePlayer, cmd ) 
  outputChatBox( getPlayerName( thePlayer ).." would like to say Bye Everyone!", root, 255, 0, 0 ) 
  triggerClientEvent( root, "playByeSound", root ) 
end ) 

and you must add them in meta

Link to comment

Thanks guys! I begin one week ago with scripting and i understand it more everyday!

I already have notepad++ but forgot to open it with ++

I didn't know about client side and server side but now i know :)

Where can i find the commands to use? i wanna make a mediaplayer in server to :P

Link to comment

then i tried to make the coloured names

addCommandHandler( "bye", function colouredchat( chatterName, cmd )  
      local r,g,b = getPlayerNameTagColor ( source )  
      local chatterName = getPlayerName ( source ) 
      outputChatBox ( chatterName..":#FFFFFF"..would like to say Bye Everyone!, getRootElement(), r, g, b, true ) 
    end 

but that doesn't work??

Link to comment

functions are case sensitive , getPlayerNameTagColor = getPlayerNametagColor

  
addCommandHandler( "bye", function ( chatterName, cmd ) -- removed function name from here , because you dont use it inside command handler 
      local r,g,b = getPlayerNametagColor( chatterName ) -- and why source is here ? , source should be the player who entered the command  
      local chatterName = getPlayerName ( chatterName ) 
      outputChatBox ( chatterName..":#FFFFFFwould like to say Bye Everyone!", getRootElement(), r, g, b, true ) -- messages have to be in "string"  
    end 
) -- you have to close the command handler 
  

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