MrGTAmodsgerman Posted June 16, 2013 Share Posted June 16, 2013 Hello guys i want to make a train horn for the freight on my upcoming server but iam a noob in Lua but i have a script and the script dont work function bindHoron( key, keyState ) if getElementModel ( theVehicle ) == 537 then if ( keyState == 'down' ) then sound = playSound3D( 'hupe/ZUGHUPE.mp3', getElementPosition( localPlayer ) ) setSoundVolume(desusound,5.0) setSoundMaxDistance(desusound, 190) attachElements( sound, getPedOccupiedVehicle( localPlayer ) ) elseif ( keyState == 'up' ) then if isElement( sound ) then stopSound( sound ) end end end end bindKey( 'h', 'down', bindHoron ) bindKey( 'h', 'up', bindHoron ) how to get it work? i wanna have a custom train horn like the cleo mod "trainhorn" i hope you can help me I am grateful for any answer Link to comment
iPrestege Posted June 16, 2013 Share Posted June 16, 2013 Where's theVehicle defined at? Link to comment
Castillo Posted June 16, 2013 Share Posted June 16, 2013 Well, the problem is that you are checking a non-existent variable. function bindHoron ( key, keyState ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if ( not theVehicle ) then return end if ( getElementModel ( theVehicle ) == 537 ) then if ( keyState == 'down' ) then sound = playSound3D ( 'hupe/ZUGHUPE.mp3', getElementPosition ( localPlayer ) ) setSoundVolume ( desusound, 5.0 ) setSoundMaxDistance ( desusound, 190 ) attachElements ( sound, theVehicle ) elseif ( keyState == 'up' ) then if isElement ( sound ) then stopSound ( sound ) end end end end bindKey ( 'h', 'down', bindHoron ) bindKey ( 'h', 'up', bindHoron ) With this script, only the player who presses the key will hear the horn, since is client side. Link to comment
MrGTAmodsgerman Posted June 16, 2013 Author Share Posted June 16, 2013 Well, the problem is that you are checking a non-existent variable.With this script, only the player who presses the key will hear the horn, since is client side. the script makes no sense if no other player hears the horn and it showes a error with you lua script 06-16 19:37:57] SCRIPT ERROR: [gamemodes]\zughupe\zughupe.lua:1: '=' expected near 'number' [2013-06-16 19:37:57] WARNING: Loading script failed: [gamemodes]\zughupe\zughupe.lua:1: '=' expected near 'number' [2013-06-16 19:37:57] start: Resource 'zughupe' started how to fix? like this? Line number On/Off | Expand near/Contract | Select all function bindHoron ( key, keyState ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if ( not theVehicle ) then return end if ( getElementModel ( theVehicle ) == 537 ) then if ( keyState == 'down' ) then sound = playSound3D ( 'hupe/ZUGHUPE.mp3', getElementPosition ( localPlayer ) ) setSoundVolume ( desusound, 5.0 ) setSoundMaxDistance ( desusound, 190 ) attachElements ( sound, theVehicle ) elseif ( keyState == 'up' ) then if isElement ( sound ) then stopSound ( sound ) end end end end bindKey ( 'h', 'down', bindHoron ) bindKey ( 'h', 'up', bindHoron ) how to get it hear for everbody on the radius of the train? how to get fix it? Link to comment
iPrestege Posted June 16, 2013 Share Posted June 16, 2013 Why did you copy this part ? Line number On/Off | Expand near/Contract | Select all Link to comment
Castillo Posted June 16, 2013 Share Posted June 16, 2013 You've copied this part from the forum: "Line number On/Off | Expand near/Contract | Select all", just remove it. To make it global, you must trigger a server event with triggerServerEvent then trigger back to client for everyone. Link to comment
MrGTAmodsgerman Posted June 16, 2013 Author Share Posted June 16, 2013 You've copied this part from the forum: "Line number On/Off | Expand near/Contract | Select all", just remove it.To make it global, you must trigger a server event with triggerServerEvent then trigger back to client for everyone. i got new errors when i try to remove your lince number..... 2013-06-16 19:56:33] WARNING: [gamemodes]\zughupe\zughupe.lua:20: Bad argument @ 'bindKey' [2013-06-16 19:56:33] WARNING: [gamemodes]\zughupe\zughupe.lua:21: Bad argument @ 'bindKey' binkey is to connect a key on the keyboard? Link to comment
Castillo Posted June 16, 2013 Share Posted June 16, 2013 You set the script as client side, right? Link to comment
MrGTAmodsgerman Posted June 16, 2013 Author Share Posted June 16, 2013 You set the script as client side, right? yes Link to comment
Castillo Posted June 16, 2013 Share Posted June 16, 2013 Then, there's no reason to output that error. Link to comment
MrGTAmodsgerman Posted June 16, 2013 Author Share Posted June 16, 2013 Then, there's no reason to output that error. ok I may have misunderstood tell me,how to set the script as client sorry but the script really dont work Link to comment
MrGTAmodsgerman Posted June 16, 2013 Author Share Posted June 16, 2013 Do you have a meta file? ok no i set now the sript type to client and i got no errors but i dont hear the sound Meta Link to comment
iPrestege Posted June 16, 2013 Share Posted June 16, 2013 The type of meta file is 'XML' Right? The sound is in hupe folder right ? Link to comment
MrGTAmodsgerman Posted June 16, 2013 Author Share Posted June 16, 2013 The type of meta file is 'XML' Right? The sound is in hupe folder right ? yes WT Link to comment
iPrestege Posted June 16, 2013 Share Posted June 16, 2013 (edited) And the script doesn't work? Debug script ? Or you can try this if doesn't work : function bindHoron ( key, keyState ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if ( not theVehicle ) then return end if ( getElementModel ( theVehicle ) == 537 ) then if ( keyState == 'down' ) then local x,y,z = getElementPosition ( localPlayer ) desusound = playSound3D ( 'hupe/ZUGHUPE.mp3',x,y,z ) setSoundVolume ( desusound, 5.0 ) setSoundMaxDistance ( desusound, 190 ) attachElements ( desusound, theVehicle ) elseif ( keyState == 'up' ) then if isElement ( desusound ) then stopSound ( desusound ) end end end end bindKey ( 'h', 'down', bindHoron ) bindKey ( 'h', 'up', bindHoron ) Edited June 16, 2013 by Guest Link to comment
iPrestege Posted June 16, 2013 Share Posted June 16, 2013 It was in his code i just edit the position . Link to comment
PaiN^ Posted June 16, 2013 Share Posted June 16, 2013 Now "sound" at lines 13, 15 and 16 ar nils Link to comment
MrGTAmodsgerman Posted June 17, 2013 Author Share Posted June 17, 2013 And the script doesn't work? Debug script ? Or you can try this if doesn't work :bindKey ( 'h', 'up', bindHoron )[/lua] OMG IT WORKS but work it for other players? OMG GREAT SCRIPT BIG THANKS BIG THANKS Link to comment
iPrestege Posted June 17, 2013 Share Posted June 17, 2013 No it's for the client player only you must use : triggerServerEvent triggerClientEvent getRootElement Link to comment
MrGTAmodsgerman Posted June 17, 2013 Author Share Posted June 17, 2013 No it's for the client player only you must use : triggerServerEvent triggerClientEvent getRootElement not work no coming sound triggerServerEvent triggerClientEvent getRootElement function bindHoron ( key, keyState ) local theVehicle = getPedOccupiedVehicle ( localPlayer ) if ( not theVehicle ) then return end if ( getElementModel ( theVehicle ) == 537 ) then if ( keyState == 'down' ) then local x,y,z = getElementPosition ( localPlayer ) desusound = playSound3D ( 'hupe/zughupe.mp3',x,y,z ) setSoundVolume ( desusound, 5.0 ) setSoundMaxDistance ( desusound, 1000 ) attachElements ( desusound, theVehicle ) elseif ( keyState == 'up' ) then if isElement ( desusound ) then stopSound ( desusound ) end end end end bindKey ( 'h', 'down', bindHoron ) bindKey ( 'h', 'up', bindHoron ) it is that right? Link to comment
iPrestege Posted June 17, 2013 Share Posted June 17, 2013 You're not make any sense at all. Link to comment
MrGTAmodsgerman Posted June 17, 2013 Author Share Posted June 17, 2013 You're not make any sense at all. sorry im a extreem noob on lua sense at all ?please lets let me learn Link to comment
MrGTAmodsgerman Posted June 17, 2013 Author Share Posted June 17, 2013 You're not make any sense at all. sorry im a extreem noob on lua sense at all ?please lets let me learn just can you give me a tutorial? EDIT:i need more help Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now