Xwad Posted June 7, 2016 Share Posted June 7, 2016 the sync is not working:/ i use root, i dont know why its not working.. I thought root contains the sync function sniper_sound(weaponID) local muzzleX, muzzleY, muzzleZ = getPedWeaponMuzzlePosition(source) if weaponID == 34 then local id = getElementModel ( localPlayer ) if id == 23 then sound_shoot = playSound3D("files/sounds/sniper_kar98.wav", muzzleX, muzzleY, muzzleZ, false) setSoundMaxDistance(sound_shoot, 100) setTimer ( function() local sound_reload = playSound3D("files/sounds/reload.wav", muzzleX, muzzleY, muzzleZ, false) setSoundMaxDistance(sound_reload, 10) setSoundVolume(sound_reload, 0.12) end, 500, 1 ) elseif id == 103 then sound_shoot2 = playSound3D("files/sounds/sniper_springfield.wav", muzzleX, muzzleY, muzzleZ, false) setSoundMaxDistance(sound_shoot2, 100) setTimer ( function() local sound_reload = playSound3D("files/sounds/reload.wav", muzzleX, muzzleY, muzzleZ, false) setSoundMaxDistance(sound_reload, 10) setSoundVolume(sound_reload, 0.12) end, 500, 1 ) end end end addEventHandler("onClientPlayerWeaponFire", root, sniper_sound) Link to comment
Castillo Posted June 7, 2016 Share Posted June 7, 2016 Try changing 'localPlayer' from getElementModel to 'source'. Link to comment
Xwad Posted June 7, 2016 Author Share Posted June 7, 2016 WOW its working! THANKS A LOT! Link to comment
Xwad Posted June 7, 2016 Author Share Posted June 7, 2016 I have one more problem with sync: now this time its with bone_attach.. the problem is with the attachElementToBone. Other players can't see the object on the player, only the localPlayer can see it function custom_sniper() local id = getElementModel ( source ) if id == 23 then local PedWeapon = getPedWeapon(localPlayer) if (PedWeapon == 34) then sniper = createObject(1853,-1317,-167,14.14) exports.bone_attach:attachElementToBone(sniper2,localPlayer,12,0,0,0,0,-90,0) outputChatBox("sniper created", 255, 255, 0) end end if id == 23 then local PedWeapon = getPedWeapon(localPlayer) if not (PedWeapon == 34) then destroyElement(sniper2) outputChatBox("sniper destroyed", 255, 0, 0) end end end addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), custom_sniper ) Link to comment
Castillo Posted June 7, 2016 Share Posted June 7, 2016 That's because: Wiki: This event is triggered whenever the local player's equipped weapon slot changes. That even is only triggered for the local player, not everyone. Link to comment
Xwad Posted June 8, 2016 Author Share Posted June 8, 2016 So i have to use triggerServerEvent right? Link to comment
Xwad Posted June 8, 2016 Author Share Posted June 8, 2016 this is not working too:/ pls help! client --SNIPER function custom_sniper() local id = getElementModel ( source ) if id == 23 then local PedWeapon = getPedWeapon(localPlayer) if (PedWeapon == 34) then sniper = createObject(1853,-1317,-167,14.14) exports.bone_attach:attachElementToBone(sniper,localPlayer,12,0,0,0,0,-90,0) outputChatBox("sniper create", 255, 255, 0) end end if id == 23 then local PedWeapon = getPedWeapon(localPlayer) if not (PedWeapon == 34) then destroyElement(sniper) outputChatBox("sniper destroyed", 255, 0, 0) end end end addEvent( "client", true ) addEventHandler( "client", root, custom_sniper ) server function server () triggerClientEvent ( root, "client", source) end addEvent( "server", true ) addEventHandler( "server", resourceRoot, server ) 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