Jump to content

trigger event only works for local player


Recommended Posts

Hello everyone!

So i started to make a script which does the following:

Basically it is a weapon sound system. It plays a normal sound for the player who shot, and plays a 3d sound for everone except the local player (who shot). It plays the normal sound fine, but the evenet is not triggered for everyone for some reason, however, it is triggered for the local player. Why isn't it triggered for everyone?

addEventHandler("onClientPlayerWeaponFire", localPlayer, function(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
  
local x, y, z = getElementPosition(localPlayer) 
local pplayer = localPlayer 
triggerEvent("weaponSound", getRootElement(), weapon, x, y, z, pplayer) 
playSound("sounds/"..weapon..".wav") 
end) 
  
addEvent("weaponSound", true) 
  
addEventHandler("weaponSound", getRootElement(), function(weapon, x, y, z, pplayer) 
if pplayer ~= localPlayer then 
    local sound = playSound3D("sounds/"..weapon..".wav", x, y, z) 
    setSoundMaxDistance(sound, 300) 
end 
end) 

Link to comment
addEventHandler("onClientPlayerWeaponFire", root, 
function(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if source == localPlayer then 
        playSound("sounds/"..weapon..".wav") 
    else 
        local x, y, z = getElementPosition(source) 
        local sound = playSound3D("sounds/"..weapon..".wav", x, y, z) 
        setSoundMaxDistance(sound, 300) 
    end 
end) 

Link to comment
addEventHandler("onClientPlayerWeaponFire", root, 
function(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if source == localPlayer then 
        playSound("sounds/"..weapon..".wav") 
    else 
        local x, y, z = getElementPosition(source) 
        local sound = playSound3D("sounds/"..weapon..".wav", x, y, z) 
        setSoundMaxDistance(sound, 300) 
    end 
end) 

local x, y, z = getElementPosition(source) 

@TAPL, source not work in ClientSide :roll:

Link to comment
addEventHandler("onClientPlayerWeaponFire", root, 
function(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if source == localPlayer then 
        playSound("sounds/"..weapon..".wav") 
    else 
        local x, y, z = getElementPosition(source) 
        local sound = playSound3D("sounds/"..weapon..".wav", x, y, z) 
        setSoundMaxDistance(sound, 300) 
    end 
end) 

local x, y, z = getElementPosition(source) 

@TAPL, source not work in ClientSide :roll:

source work in client & server

Source

The source of this event is the streamed in player who fired the weapon.

Link to comment
  • 4 weeks later...
addEventHandler("onClientPlayerWeaponFire", root, 
function(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if source == localPlayer then 
        playSound("sounds/"..weapon..".wav") 
    else 
        local x, y, z = getElementPosition(source) 
        local sound = playSound3D("sounds/"..weapon..".wav", x, y, z) 
        setSoundMaxDistance(sound, 300) 
    end 
end) 

local x, y, z = getElementPosition(source) 

@TAPL, source not work in ClientSide :roll:

Shared function

Link to comment
addEventHandler("onClientPlayerWeaponFire", root, 
function(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if source == localPlayer then 
        playSound("sounds/"..weapon..".wav") 
    else 
        local x, y, z = getElementPosition(source) 
        local sound = playSound3D("sounds/"..weapon..".wav", x, y, z) 
        setSoundMaxDistance(sound, 300) 
    end 
end) 

local x, y, z = getElementPosition(source) 

@TAPL, source not work in ClientSide :roll:

Shared function

So you replied to a topic after 23 days of the last reply to say "source = function"?

:violent1:

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