Jump to content

Train horn script dont work


Recommended Posts

Posted

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

Posted

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.

Posted
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? :|

Posted

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.

Posted
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? :o

Posted (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 by Guest
Posted
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 :D:D:D:D:D:D:D

but work it for other players? :?:

OMG GREAT SCRIPT :D:D:D

BIG THANKS BIG THANKS :D

Posted
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? :roll:

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