Jump to content

Tell me one command


pocko

Recommended Posts

Posted

there are examples on the wiki, you know.

  
function playMySound() 
  local sound = playSound("mySoundFile.mp3") 
end 
addCommandHandler("wtf", playMySound) 
  

dont forget that sound file should also be added to meta.xml of your resource:

  
<file src="mySoundFile.mp3" /> 
  

Posted

Please Help me again i have somewhere mistake :x

function AngryEmotion(player, command) 
        outputChatBox( "* "..getPlayerName(player).." is angry", getRootElement(), 255, 0, 255, true ) 
  
end 
  
addCommandHandler("angry", AngryEmotion) 
  
function angry() 
  local sound = angry("sounds/angry.mp3") 
end 
addCommandHandler("angry", angry) 

Posted (edited)
function AngryEmotion(command) 
  outputChatBox( "* "..getPlayerName(getLocalPlayer()).." is angry", 255, 0, 255, true ) 
  angry() 
end 
addCommandHandler("angry", AngryEmotion) 
  
function angry() 
  local sound = playSound("sounds/angry.mp3") --typo 
end 

Since it is a client-side, no one will see your message. If you want to output your message to everyone, you should add a server side event and trigger it when you type /angry. So the final result will be:

--client 
function AngryEmotion(command) 
  triggerServerEvent( "onAngry", getLocalPlayer() ) 
  angry() 
end 
addCommandHandler("angry", AngryEmotion) 
  
function angry() 
  local sound = playSound("sounds/angry.mp3") 
end 
  
--server 
addEvent( "onAngry", true ) 
addEventHandler( "onAngry", root, function() 
  outputChatBox( "* "..getPlayerName(source).." is angry", root, 255, 0, 255, true ) 
end ) 

Edited by Guest
Posted

i tryed the text working

Now left only the sound

when i write now debugscript 3 write me this

ERROR emotions\angry.lua:2: attempt to call global 'getLocalPlayer' (a nil value) 

Error emotions\angry.lua:8: stack overflow 

Posted

Show me your meta.xml file. Did you define that script as client-side?

="my_script.lua" type="client" />

Edit: oh, and look at the 8th line, it must be:

local sound = playSound("sounds/angry.mp3") 

Posted

yes there was the problem.I corrected it now working ty :) i was forgot to make one space sounds= playsound

I m new and that is my first script ty :)

Posted

hey the script work perfect but i found another problem the other can t hear the sound when i start the command.I don t know but i want only admins to can active the sound

Posted

here my try

addEvent( "onAngry", true ) 
addEventHandler( "onAngry", root, function() 
local sound = playSound("sound/angry.mp3") 
end 

Posted
you forgot ) after end to close addEventHandler.

I close it but not work again :DTHe others can t hear the sound :x

/debugscript 3 and write this error

Error: emotions/s_angry.lua  attempt to cal global 'playsound' (a nil value) 

Posted

on the server you need only to trigger the event, that's all.

and in client event handler for this event you place the playSound function.

Posted

well you should try to understand.

--client 
addEvent( "onAngry", true ) 
addEventHandler( "onAngry", root, function() 
  local sound = playSound("sounds/angry.mp3")  
end ) 
  
--server 
function AngryEmotion(player, command) 
  outputChatBox( "* "..getPlayerName(player).." is angry", root, 255, 0, 255, true ) 
  triggerClientEvent("onAngry", root) -- this will trigger onAngry event for all players. 
end 
addCommandHandler("angry", AngryEmotion) 

Posted

hey i start to make a new emotion and write this !The text is showing but the sound can t :x please help me again and tell me where i making the problem :x

Client: 
function GoodbyeEmotion(command) 
  triggerServerEvent( "onbye", getLocalPlayer() ) 
end 
addCommandHandler("bb", GoodbyeEmotion) 
  
addEvent( "onbye", true ) 
addEventHandler( "onbye", root, function() 
  local sound = playSound("sound/goodbuy.mp3") 
end ) 
  
Server 
addEvent( "onbye", true ) 
addEventHandler( "onbye", root, function() 
  outputChatBox( "* "..getPlayerName(source).." said: Goodbye all", root, 255, 0, 255, true ) 
end ) 
  
function GoodbyeEmotions(player, command) 
   triggerClientEvent("onbye", root) 
end 
addCommandHandler("bb", GoodbyeEmotion) 

Posted

why didn't you copy Aiboforcen's code?

--client 
addEvent( "onBye", true ) 
addEventHandler( "onBye", root, function() 
  local sound = playSound("sounds/goodbuy.mp3") 
end ) 
  
--server 
function ByeEmotion(player, command) 
  outputChatBox( "* "..getPlayerName(player).."said: Goodbye all", root, 255, 0, 255, true ) 
  triggerClientEvent("onBye", root) 
end 
addCommandHandler("bye", ByeEmotion) 

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