iPanda Posted July 14, 2013 Posted July 14, 2013 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 ...
Moderators IIYAMA Posted July 14, 2013 Moderators Posted July 14, 2013 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 removePlayerClothesgetPedSkin ( player) require a player or ped.etc. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
iPanda Posted July 14, 2013 Author Posted July 14, 2013 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 removePlayerClothesgetPedSkin ( 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. - -
iPanda Posted July 14, 2013 Author Posted July 14, 2013 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 removePlayerClothesgetPedSkin ( player) require a player or ped.etc. please can give your life once again, I did not have time to copy it.
Moderators IIYAMA Posted July 14, 2013 Moderators Posted July 14, 2013 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) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
iPanda Posted July 14, 2013 Author Posted July 14, 2013 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.
Castillo Posted July 14, 2013 Posted July 14, 2013 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 ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
iPanda Posted July 14, 2013 Author Posted July 14, 2013 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.
Castillo Posted July 14, 2013 Posted July 14, 2013 You are logging in, right? because it binds it on login. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
iPanda Posted July 14, 2013 Author Posted July 14, 2013 You are logging in, right? because it binds it on login. Oops, that's the thing. I do not go in with the Login Panel. May apply onPlayerJoin and onPlayerQuit ??
Castillo Posted July 14, 2013 Posted July 14, 2013 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 ). San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Moderators IIYAMA Posted July 14, 2013 Moderators Posted July 14, 2013 @Solidsnake14 O_o, lol Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
iPanda Posted July 14, 2013 Author Posted July 14, 2013 (edited) 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 ... Non, hockey mask = ID 15 https://wiki.multitheftauto.com/wiki/CJ_Clothes%5CHats_(16) Edited July 14, 2013 by Guest
Castillo Posted July 14, 2013 Posted July 14, 2013 No, look, the index is for the category, 15 = Glasses, 16 = Hats. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Moderators IIYAMA Posted July 14, 2013 Moderators Posted July 14, 2013 https://wiki.multitheftauto.com/wiki/CJ_Clothes%5CHats_%2816%29Index: 15 Texture: hockey Model: hockeymask hmms looks like incorrect information on wiki mta. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Castillo Posted July 14, 2013 Posted July 14, 2013 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. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
iPanda Posted July 14, 2013 Author Posted July 14, 2013 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!
Castillo Posted July 14, 2013 Posted July 14, 2013 Is the one I posted. Post your meta.xml content. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Moderators IIYAMA Posted July 14, 2013 Moderators Posted July 14, 2013 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. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
iPanda Posted July 14, 2013 Author Posted July 14, 2013 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?
Castillo Posted July 15, 2013 Posted July 15, 2013 Model ID must be wrong. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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