general999 Posted March 11, 2023 Share Posted March 11, 2023 So, I got this script ready, but the problem is that I run it, it works without giving an error, but as soon as I aim with a sniper ID 34, it gives this error message, I don't understand much about scripting so I don't know how to solve it or what could it be, can anyone help me? OBS: it's a script so that when the PLAYER aims with the sniper, it changes dimensions, to be correcting the problem of the weapon appearing in front of the scope if you aim too fast. local alpha = 255 bindKey ( "aim_weapon", "both", function ( _, state ) if getPedWeaponSlot ( localPlayer ) == 6 then if ( state == "down" ) then alpha = 0 elseif ( state == "up" ) then alpha = 255 end for _, v in ipairs ( getElementsByType ( "object", root, true ) ) do if isElementAttachedToBone ( v ) then local id = getElementModel ( v ) if ( id == 2584 ) then setElementAlpha ( v, alpha ) setElementDimension(v, alpha == 0 and 9999 or getElementDimension(localPlayer)) end end end end end ) PICTURE OF BUG PICTURE OF BUG 2 Link to comment
FlorinSzasz Posted March 11, 2023 Share Posted March 11, 2023 (edited) Well if u dont use the bone_attach resource i think u should replace isElementAttachedToBone() --- with this isElementAttached() https://wiki.multitheftauto.com/wiki/IsElementAttached Also u dont need to change the dimension of the object u cant just set the alpha to 0 and it should be enough. Edited March 11, 2023 by FlorinSzasz Link to comment
general999 Posted March 12, 2023 Author Share Posted March 12, 2023 21 hours ago, FlorinSzasz said: Bem, se você não usa o recurso bone_attach, acho que deveria substituí-lo https://wiki.multitheftauto.com/wiki/IsElementAttached Além disso, você não precisa alterar a dimensão do objeto, não pode apenas definir o alfa como 0 e deve ser o suficiente. can you fix it for me buddy? I don't understand much about scripting... Link to comment
FlorinSzasz Posted March 12, 2023 Share Posted March 12, 2023 (edited) 39 minutes ago, general999 said: can you fix it for me buddy? I don't understand much about scripting... Well i think it should look something like this local alpha = 255 bindKey ( "aim_weapon", "both", function ( _, state ) if getPedWeaponSlot ( localPlayer ) == 6 then if ( state == "down" ) then alpha = 0 elseif ( state == "up" ) then alpha = 255 end for _, v in ipairs ( getElementsByType ( "object", root, true )) do if isElementAttached ( v ) then local id = getElementModel ( v ) if ( id == 2584 ) then setElementAlpha ( v, alpha ) end end end end end ) Edited March 12, 2023 by FlorinSzasz Link to comment
general999 Posted March 12, 2023 Author Share Posted March 12, 2023 (edited) 6 horas atrás, FlorinSzasz disse: Thank you, it worked <3<3 Edited March 12, 2023 by general999 1 Link to comment
Evan Kinley Posted May 27 Share Posted May 27 Hello guys, i know nothing about scripting and i also got the same problem bindKey("aim_weapon","both",function(key,state) local weapon=getPedWeapon(localPlayer) if weapon==34 then local objs=getElementsByType("object",root,true) for i,obj in ipairs(objs) do if isElementAttachedToBone(obj) then local alpha=getElementAlpha(obj) if alpha==0 and state=="up" then setElementAlpha(obj,255) elseif alpha==255 and state=="down" then setElementAlpha(obj,0) end end end end end) 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