Jump to content

Problem with script


Tren

Recommended Posts

I have problem:script does not work and there is no debug errors and no sound

Client:

function grenadekill(killerWeapon) 
if (killerWeapon == 16) then 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 1) 
end 
end 
addEventHandler("onClientPlayerWasted", getLocalPlayer(), grenadekill) 

Server:

function grenadekill(killerWeapon) 
if (killerWeapon == 16) then 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 1) 
end 
end 
addEventHandler("OnPlayerWasted", resourceRoot , grenadekill) 

Script must play sound when anyone kill anyone with grenade

For example: PLayer1 ,..Perfect!(sound for all players) PLayer2 kills PLayer1 with grenade

Anyone help?Im newbie in scripting.Fix the small code,please :P

Link to comment

You need play sound for all players if player die ?

If yes use this:

function grenadekill(killer,killerWeapon,body) 
if (killerWeapon == 16) then 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 1) 
end 
end 
addEventHandler("onClientPlayerWasted", root, grenadekill) 

if you need play sound for local player use this

function grenadekill(killer,killerWeapon,body) 
if (killerWeapon == 16) then 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 1) 
end 
end 
addEventHandler("onClientPlayerWasted", getLocalPlayer(), grenadekill) 

and remember function

playSound 

not working in server side events.

Link to comment
You need play sound for all players if player die ?

If yes use this:

function grenadekill(killer,killerWeapon,body) 
if (killerWeapon == 16) then 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 1) 
end 
end 
addEventHandler("onClientPlayerWasted", root, grenadekill) 

if you need play sound for local player use this

function grenadekill(killer,killerWeapon,body) 
if (killerWeapon == 16) then 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 1) 
end 
end 
addEventHandler("onClientPlayerWasted", getLocalPlayer(), grenadekill) 

and remember function

playSound 

not working in server side events.

thx,but how is server-side? script doesn't work , no sounds.(and no debug errors)

Now i have files:

client.lua

perfect.mp3

meta.xml

I need help :fadein:

Link to comment

Try This :D

function grenadekill ( killer, weapon, bodypart ) 
if ( weapon == 16 ) then --if the weapon used was the grenade 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 0.5) -- set the sound volume to 50% 
end 
addEventHandler("onClientPlayerWasted",getLocalPlayer(),grenadekill) 
  
  

:wink:

and meta.xml

"youName" type="script" version="1.0" /> 

Link to comment

You have a missing 'end'.

function grenadekill ( killer, weapon, bodypart ) 
if ( weapon == 16 ) then --if the weapon used was the grenade 
local sound = playSound("Perfect.mp3") 
setSoundVolume(sound, 0.5) -- set the sound volume to 50% 
     end 
end 
addEventHandler("onClientPlayerWasted",getLocalPlayer(),grenadekill) 

Link to comment

This should work, happens in serverside and trigger all the players ( play the sound for everybody )

Server

  
function player_Wasted ( ammo, attacker, weapon, bodypart ) 
    if not attacker == source then -- If it is not a suicide then 
        if ( weapon == 16 ) -- and if the weapon is 16 ( granede )  
            triggerClientEvent ( getRootElement(), "perfect", getRootElement()) -- Trigger this to every client. 
        end 
    end 
end 
  

Client

addEvent("perfect",true) -- Creates the event handler 
  
function perfect() -- Play for everybody 
    local sound = playSound("Perfect.mp3") 
    setSoundVolume(sound, 0.5) 
end 
addEventHandler("perfect",getRootElement(),perfect) -- Triggers this event handler 

This should work, else, post /debugscript 3

Edit now with notes so you can understand better what the hell is happening :D

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