Jump to content

[Help] add Gas Mask


iPanda

Recommended Posts

I just recently started learning Lua. This is my first serious script and I need your help.

/*\Skin only works on skin = 0

What gives resourse: When you press the "h" to start the animation and you will find yourself in a gas mask.

How it should work:

1. I replaced the hockey mask (clothing) on a gas mask.

2. Did the script with addPlayerClothes and removePlayerClothes

3. When you press the "h" the player must be in a gas mask. He may at any time take it off and put on again.

Unfortunately the script does not work, help me find the problem and fix it.

p.s. Sorry for my english, I'm from Russia.

--  ANIMATION 
local drees = false 
  
function animGasMask(player, key, keyState) 
  if drees then 
    setPedAnimation(player, false) 
    drees = false 
  else 
    if isPedInVehicle(player) then 
      return 
    end 
    setPedAnimation(player, "goggles", "goggles_put_on", nil, true, false, false, false) 
    drees = true 
  end 
end 
  
--  GIVE GAS MASK FOR PLAYER 
function dressGasMask ( dress, gasmask ) 
  if getLocalPlayer ( getPedSkin ( dress ) == 0 ) then 
    addPlayerClothes ( getLocalPlayer (source, "hockey", "hockeymask", 15 ) ) 
  end 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), dressGasMask ) 
  
function shootGasMask ( shoot, gasmask ) 
  if getLocalPlayer ( getPedSkin ( shoot ) == 0 ) then 
    removePlayerClothes ( source, 15 ) 
  end 
end 
addEventHandler ( "onPlayerLogin", getRootElement(), shootGasMask ) 
  
--  BIND KEYS 
function bindTheKeys() 
  bindKey ( source, "h", "down", animGasMask ) 
  bindKey ( source, "h", "down", shootGasMask ) 
  bindKey ( source, "h", "up", dressGasMask ) 
end 
addEventHandler("onPlayerLogin", getRootElement(), bindTheKeys) 

I look forward to your answers to help me solve this problem ...

Link to comment
  • Moderators

Wrong:

  • You are using 3 times the event onPlayerLogin.
    The player of a onPlayerLogin is the source.
    You are using getLocalPlayer, that is for clientside. But this is serverside.
    Use removePedClothes instead of removePlayerClothes
    getPedSkin ( player) require a player or ped.
    etc.

Link to comment
Wrong:

  • You are using 3 times the event onPlayerLogin.
    The player of a onPlayerLogin is the source.
    You are using getLocalPlayer, that is for clientside. But this is serverside.
    Use removePedClothes instead of removePlayerClothes
    getPedSkin ( player) require a player or ped.
    etc.

What to use removePlayerClothes or removePedClothes, because I want any players could wear / remove a gas mask at all times!

That is, it must be:

--  GIVE GAS MASK FOR PLAYER 
local offmask = 0 
  
addEventHandler ( "onPlayerLogin", getRootElement (), 
  function gasmask ( player ) 
    if offmask == 1 then 
      addPlayerClothes ( source, "hockey", "hockeymask", 15 ) 
    elseif offmask == 0 then 
      removePlayerClothes ( source, 15 ) 
    end 
  end 
) 
bindKey ( "h", "down", gasmask ) 
bindKey ( "h", "up", gasmask ) 

Or the second option:

--  GIVE GAS MASK FOR PLAYER 
local offmask = 0 
  
function gasmask() 
  bindKey (source,"h","up", 
  function ( player ) 
    if offmask == 1 then 
      addPlayerClothes ( player, "hockey", "hockeymask", 15 ) 
    elseif offmask == 0 then 
      removePlayerClothes ( source, 15 ) 
    end 
  end 
  ) 
end 
addEventHandler ("onPlayerLogin",getRootElement(),gasmask) 

But somehow, I am sure that this option is not correct. Please, if you can tell me how to make a script correctly.

-

-

Link to comment
Wrong:

  • You are using 3 times the event onPlayerLogin.
    The player of a onPlayerLogin is the source.
    You are using getLocalPlayer, that is for clientside. But this is serverside.
    Use removePedClothes instead of removePlayerClothes
    getPedSkin ( player) require a player or ped.
    etc.

please can give your life once again, I did not have time to copy it.

Link to comment
  • Moderators
please can give your life once again, I did not have time to copy it.

I didn't had time to fix. Never used pedClothes before.

  
local gasMaskActivation = function (player) 
    local texture,model = getPedClothes ( player, 15 ) 
    if not (texture == "hockey" and model == "hockeymask") then 
        addPedClothes ( player, "hockey", "hockeymask", 15 ) 
    else 
        removePedClothes ( player, 15 ) 
    end 
end 
  
addEventHandler ("onPlayerLogin",root, 
function() 
    bindKey (source,"h","up",gasMaskActivation) 
end) 
  
addEventHandler ("onPlayerLogout",root, 
function() 
    if isKeyBound ( source,"h","up",gasMaskActivation ) then 
        unbindKey (source,"h","up",gasMaskActivation) 
    end 
end) 
  

Link to comment
please can give your life once again, I did not have time to copy it.

I didn't had time to fix. Never used pedClothes before.

  
local gasMaskActivation = function (player) 
    local texture,model = getPedClothes ( player, 15 ) 
    if not (texture == "hockey" and model == "hockeymask") then 
        addPedClothes ( player, "hockey", "hockeymask", 15 ) 
    else 
        removePedClothes ( player, 15 ) 
    end 
end 
  
addEventHandler ("onPlayerLogin",root, 
function() 
    bindKey (source,"h","up",gasMaskActivation) 
end) 
  
addEventHandler ("onPlayerLogout",root, 
function() 
    if isKeyBound ( source,"h","up",gasMaskActivation ) then 
        unbindKey (source,"h","up",gasMaskActivation) 
    end 
end) 
  

I just tested this script on my RPG server. Unfortunately the script does not work: (And I do not know how to fix it.

As the script was supposed to work: Any player on the server can at any time put on and remove mask by pressing the "H".

(Gas mask - clothes, replaced hockey mask)

And yet can take addPlayerClothes and removePlayerClothes? - If you just change the Player to Ped, then nothing at all will not work.

Link to comment
local gasMaskActivation = function ( player ) 
    local texture, model = getPedClothes ( player, 15 ) 
    if not ( texture == "hockey" and model == "hockeymask" ) then 
        addPedClothes ( player, "hockey", "hockeymask", 15 ) 
    else 
        removePedClothes ( player, 15 ) 
    end 
end 
  
addEventHandler ( "onPlayerLogin",root, 
    function ( ) 
        bindKey ( source, "h", "down", gasMaskActivation ) 
    end 
) 
  
addEventHandler ( "onPlayerLogout", root, 
    function ( ) 
        if isKeyBound ( source, "h", "down", gasMaskActivation ) then 
            unbindKey ( source, "h", "down", gasMaskActivation ) 
        end 
    end 
) 

Link to comment
local gasMaskActivation = function ( player ) 
    local texture, model = getPedClothes ( player, 15 ) 
    if not ( texture == "hockey" and model == "hockeymask" ) then 
        addPedClothes ( player, "hockey", "hockeymask", 15 ) 
    else 
        removePedClothes ( player, 15 ) 
    end 
end 
  
addEventHandler ( "onPlayerLogin",root, 
    function ( ) 
        bindKey ( source, "h", "down", gasMaskActivation ) 
    end 
) 
  
addEventHandler ( "onPlayerLogout", root, 
    function ( ) 
        if isKeyBound ( source, "h", "down", gasMaskActivation ) then 
            unbindKey ( source, "h", "down", gasMaskActivation ) 
        end 
    end 
) 

Unfortunately nothing works.

Link to comment

I found your problem, you are using the wrong index, is 16 not 15.

local gasMaskActivation = function ( player ) 
    local texture, model = getPedClothes ( player, 16 ) 
    if not ( texture == "hockey" and model == "hockeymask" ) then 
        addPedClothes ( player, "hockey", "hockeymask", 16 ) 
    else 
        removePedClothes ( player, 16 ) 
    end 
end 
  
addEventHandler ( "onPlayerJoin",root, 
    function ( ) 
        bindKey ( source, "h", "down", gasMaskActivation ) 
    end 
) 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            bindKey ( player, "h", "down", gasMaskActivation ) 
        end 
    end 
) 

Works perfect ( tested ).

Link to comment
I found your problem, you are using the wrong index, is 16 not 15.
local gasMaskActivation = function ( player ) 
    local texture, model = getPedClothes ( player, 16 ) 
    if not ( texture == "hockey" and model == "hockeymask" ) then 
        outputChatBox ( tostring ( addPedClothes ( player, "hockey", "hockeymask", 16 ) ) ) 
    else 
        removePedClothes ( player, 16 ) 
    end 
end 
  
addEventHandler ( "onPlayerJoin",root, 
    function ( ) 
        bindKey ( source, "h", "down", gasMaskActivation ) 
    end 
) 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        for _, player in ipairs ( getElementsByType ( "player" ) ) do 
            bindKey ( player, "h", "down", gasMaskActivation ) 
        end 
    end 
) 

Works perfect ( tested ).

Still does not work :cry: ...

Non, hockey mask = ID 15 https://wiki.multitheftauto.com/wiki/CJ_Clothes%5CHats_(16)

Edited by Guest
Link to comment
The script does work, I tested it, I pressed 'H' and I got the hockey mask, I pressed it again and it dissapeard.

You must have the CJ skin.

Also, remember that this script is SERVER SIDE.

Please give the one script that you used to get a hockey mask!

Link to comment
  • Moderators
The script does work, I tested it, I pressed 'H' and I got the hockey mask, I pressed it again and it dissapeard.

You must have the CJ skin.

Also, remember that this script is SERVER SIDE.

Please give the one script that you used to get a hockey mask!

We just did,

I would almost say unfortunately.

Link to comment
Is the one I posted.

Post your meta.xml content.

A model of how to replace a hockey mask on a gas mask?

Using ID clothing https://wiki.multitheftauto.com/wiki/Clothing_Component_IDs

When to use:

gasmaskTXD = engineLoadTXD("gasmask.txd") 
engineImportTXD(gasmaskTXD, 30376) 
gasmaskDFF = engineLoadDFF("gasmask.dff", 30376) 
engineReplaceModel(gasmaskDFF, 30376) 

That's right, is not it?

If it is correct, then I do not understand why I have an error. MTA itself is closed when I wear a hockey mask replaced by a gas mask.

Can you help me fix the game crashes?

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