Jump to content

Help with script guys


Kenix

Recommended Posts

script not work.

I sometimes frequent problems with the "if" "elseif" "else" please help guys :(

  
addEventHandler( "onClientPlayerWasted", getRootElement( ), 
    function(killerweapon, killer) 
        if ( killerweapon == 54 ) then  -- чел упал 
        playSound( 'sounds/humans/EndScream.mp3', false) 
        outputChatBox("1") 
        elseif ( killerweapon == 56 ) then     -- убит из кулаков 
        playSound( 'sounds/humans/PlayerPainBreathing.mp3', false) 
        outputChatBox("2") 
        elseif ( killerweapon == 53 ) then      -- умер в воде  
        playSound( 'sounds/humans/hurt.mp3', false) 
        outputChatBox("3") 
        elseif ( killerweapon or killer  == 57 ) then 
        survivorkillsounds = playSound( "sounds/humans/attack" .. tostring( math.random( 1, 4 ) ) .. ".mp3", x,y,z, false ) 
        setSoundVolume(survivorkillsounds, 0.9) 
        setSoundMaxDistance(survivorkillsounds, 10) 
        outputChatBox("4") 
    else 
        zombiekillsounds = playSound( "sounds/zombies/attack" .. tostring( math.random( 1, 5 ) ) .. ".mp3", x,y,z, false ) 
        setSoundVolume(zombiekillsounds, 0.9) 
        setSoundMaxDistance(zombiekillsounds, 10) 
        outputChatBox("5") 
end 
        if ( killerweapon or source == 57 ) then     
        local pTeam = getPlayerTeam" class="kw2">getPlayerTeam(source) 
         
        if not pTeam then return end 
      
        local pTeamName = getTeamName(pTeam) 
        if type(pTeamName) ~= "string" then return end 
         
        if pTeamName == "Zombies" then -- еси умер зомби 
        zombiediesounds = playSound( "sounds/zombies/die" .. tostring( math.random( 1, 3 ) ) .. ".mp3", x,y,z, false ) 
        setSoundVolume(zombiediesounds, 0.9) 
        setSoundMaxDistance(zombiediesounds, 10) 
        outputChatBox("6") 
        elseif pTeamName == "Survivors" then -- еси умер игрок 
        survivordiesounds = playSound( "sounds/humans/dead" .. tostring( math.random( 1, 4 ) ) .. ".mp3", x,y,z, false ) 
        setSoundVolume(survivordiesounds, 0.9) 
        setSoundMaxDistance(survivordiesounds, 10) 
        outputChatBox("7") 
          end    
        end  
    end   
)        
  

Link to comment
  • Moderators

Hi,

What you are trying to do in this line ?? :shock:

killer  == 57 

And it's not

function(killerweapon, killer) 

but

function(killer, killerweapon) 

So I tried to repair your code but it is not very understandable ( but you can test it, it works ):

addEventHandler( "onClientPlayerWasted", getRootElement( ), 
    function(killer, killerweapon) 
        if ( killerweapon == 54 ) then  -- ??? ???? 
            playSound( 'sounds/humans/EndScream.mp3', false) 
            outputChatBox("1") 
        elseif ( killerweapon == 56 ) then     -- ???? ?? ??????? 
            playSound( 'sounds/humans/PlayerPainBreathing.mp3', false) 
            outputChatBox("2") 
        elseif ( killerweapon == 53 ) then      -- ???? ? ???? 
            playSound( 'sounds/humans/hurt.mp3', false) 
            outputChatBox("3") 
        elseif ( killerweapon == 57 ) then 
            survivorkillsounds = playSound( "sounds/humans/attack" .. tostring( math.random( 1, 4 ) ) .. ".mp3", x,y,z, false ) 
            setSoundVolume(survivorkillsounds, 0.9) 
            setSoundMaxDistance(survivorkillsounds, 10) 
            outputChatBox("4") 
        else 
            zombiekillsounds = playSound( "sounds/zombies/attack" .. tostring( math.random( 1, 5 ) ) .. ".mp3", x,y,z, false ) 
            setSoundVolume(zombiekillsounds, 0.9) 
            setSoundMaxDistance(zombiekillsounds, 10) 
            outputChatBox("5") 
        end 
        if ( killerweapon == 57 ) then    
            local pTeam = getPlayerTeam" class="kw2">getPlayerTeam" class="kw2">getPlayerTeam(source) 
            if not pTeam then return end 
            local pTeamName = getTeamName(pTeam) 
            if type(pTeamName) ~= "string" then return end 
            if pTeamName == "Zombies" then -- ??? ???? ????? 
                zombiediesounds = playSound( "sounds/zombies/die" .. tostring( math.random( 1, 3 ) ) .. ".mp3", x,y,z, false ) 
                setSoundVolume(zombiediesounds, 0.9) 
                setSoundMaxDistance(zombiediesounds, 10) 
                outputChatBox("6") 
            elseif pTeamName == "Survivors" then -- ??? ???? ????? 
                survivordiesounds = playSound( "sounds/humans/dead" .. tostring( math.random( 1, 4 ) ) .. ".mp3", x,y,z, false ) 
                setSoundVolume(survivordiesounds, 0.9) 
                setSoundMaxDistance(survivordiesounds, 10) 
                outputChatBox("7") 
            end    
        end 
    end 
) 
 

Can you explain each possiblities please ?

Link to comment
  • Moderators
@Citizen: It represents ID of Death Reason: https://wiki.multitheftauto.com/wiki/Death_Reasons

I know but why killer == 57 and not killerWeapon == 57 ??

script not work

killerWeapon == 57

because what it says on the wiki that need to check exactly

"killerWeapon: an integer representing the killer weapon or the death reason."

Yes it is what I say:

killer: A player element representing the killer.

weapon: An integer representing the killer weapon or the death reason.

So killerWeapon == 57 and not killer == 57

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