Jump to content

triggerClientEvent problem


Recommended Posts

Hello everyone! Today I tried the triggering stuff, but it's not working. I don't know why. :( Can somebody help me please? This script is about when the engine is broken and you try to start it, it should start play a sound.

Here's this part of the code:

Server

if (vehKey) or (owner < 0) and (faction == -1) or (playerFaction == faction) and (faction ~= -1) or (exports.global:isPlayerAdmin(source)) then 
                        local fuel = getElementData(veh, "fuel") 
                        local broke = getElementData(veh, "enginebroke") 
                        if broke == 1 then 
                            exports.global:sendLocalMeAction(source, "megpróbálja beindítani a jármûvet, de nem sikerül.") 
                            exports["notifications"]:showBox(source, "error", "A jármű motorja sérült.") 
                            triggerClientEvent ("onMotorSerult",getRootElement()) 
                         end 
  
end 

Client

addEvent ("onMotorSerult",true) 
  
addEventHandler ("onMotorSerult",getRootElement(), 
function () 
    local jatekosjarmu = getPedOccupiedVehicle(localPlayer) 
    local x, y, z = getElementPosition(jatekosjarmu) 
    motor = playSound3D("startup.mp3", x, y, z, false) 
    setSoundMaxDistance(motor, 30) 
end 
) 

Link to comment
  • Moderators

@Dzsozi

Did you know that with your code every player has to be in a vehicle to hear a sound?

and if they are not they get 3 warnings at clientside? Because you don't check if the vehicle does exist.

try:

-- server

triggerClientEvent ("onMotorSerult",veh) 

-- client

  
addEvent ("onMotorSerult",true) 
addEventHandler ("onMotorSerult",root, 
function () 
    if isElement(source) then 
        local x, y, z = getElementPosition(source) 
        local motor = playSound3D("startup.mp3", x, y, z, false) 
        setSoundMaxDistance(motor, 30) 
    end 
end 
) 

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