Scripting Moderators ds1-e Posted March 4, 2019 Scripting Moderators Share Posted March 4, 2019 Hey. Need some help from you guys. I have function which basically, should hide attached to bone model whenever player aims. But it's not perfect. Here are my questions: - It's possible to make it more efficient/optimized? - There's any way to improve it? One and only problem is that this function sometimes don't set element alpha to 0, so the weapon it's visible even if player aiming. It's rarely, but i would like to fix it. function toggleWeaponsVisibility(key, keyState) if getPedWeaponSlot(getLocalPlayer()) == 6 then local alpha = 255 if keyState == "down" then alpha = 0 elseif keyState == "up" then alpha = 255 end local objects = getElementsByType("object", getRootElement(), true) for i = 1, #objects do if isElementAttachedToBone(objects[i]) and getElementModel(objects[i]) == 2763 or getElementModel(objects[i]) == 1820 or getElementModel(objects[i]) == 2708 or getElementModel(objects[i]) == 15036 then setElementAlpha(objects[i], alpha) end end end end bindKey("aim_weapon", "both", toggleWeaponsVisibility) Link to comment
Moderators IIYAMA Posted March 4, 2019 Moderators Share Posted March 4, 2019 (edited) While creating elements: -- on top of the script local boneAttachContainer = createElement("boneAttachContainer", "boneAttachContainer") -- while making objects local object = createObject(...) setElementParent(object, boneAttachContainer) -- on top of the script local validBoneAttachModels = {[2763] = true, [1820] = true, [2708] = true, [15036] = true} -- while pressing key local boneAttachContainer = getElementByID("boneAttachContainer") if boneAttachContainer then local objects = getElementsByType("object", boneAttachContainer, true) for i = 1, #objects do local object = objects[i] local model = getElementModel(object) if validBoneAttachModels[model] then setElementAlpha(object, alpha) end end end 1 hour ago, majqq said: - There's any way to improve it? One and only problem is that this function sometimes don't set element alpha to 0, so the weapon it's visible even if player aiming. It's rarely, but i would like to fix it. You might want to consider using a dirty timer or find an event that will occur at that time. Edited March 4, 2019 by IIYAMA 1 Link to comment
Alraaayts Posted April 23, 2019 Share Posted April 23, 2019 Can you send me the whole script please?? Link to comment
Scripting Moderators ds1-e Posted April 23, 2019 Author Scripting Moderators Share Posted April 23, 2019 13 minutes ago, Alraaayts said: Can you send me the whole script please?? It's in first post. But: function toggleWeaponsVisibility(key, keyState) if getPedWeaponSlot(getLocalPlayer()) == 6 then local alpha = 255 if keyState == "down" then alpha = 0 elseif keyState == "up" then alpha = 255 end local objects = getElementsByType("object", getRootElement(), true) for i = 1, #objects do if isElementAttachedToBone(objects[i]) and getElementModel(objects[i]) == 2763 or getElementModel(objects[i]) == 1820 or getElementModel(objects[i]) == 2708 or getElementModel(objects[i]) == 15036 then -- change id of models here setElementAlpha(objects[i], alpha) end end end end bindKey("aim_weapon", "both", toggleWeaponsVisibility) You need to change ids of objects. Link to comment
Alraaayts Posted April 23, 2019 Share Posted April 23, 2019 3 minutes ago, majqq said: function toggleWeaponsVisibility(key, keyState) if getPedWeaponSlot(getLocalPlayer()) == 6 then local alpha = 255 if keyState == "down" then alpha = 0 elseif keyState == "up" then alpha = 255 end local objects = getElementsByType("object", getRootElement(), true) for i = 1, #objects do if isElementAttachedToBone(objects[i]) and getElementModel(objects[i]) == 2763 or getElementModel(objects[i]) == 1820 or getElementModel(objects[i]) == 2708 or getElementModel(objects[i]) == 15036 then -- change id of models here setElementAlpha(objects[i], alpha) end end end end bindKey("aim_weapon", "both", toggleWeaponsVisibility) Where does i add this? Client side? Then how about IIYAMA post? Where to add it? Link to comment
Scripting Moderators ds1-e Posted April 23, 2019 Author Scripting Moderators Share Posted April 23, 2019 Just now, Alraaayts said: Where does i add this? Client side? It's client. But don't forget to change ids of objects in condition. And this function doesn't work all time, so you would need to improve it a bit, and make things by yourself. Link to comment
Scripting Moderators ds1-e Posted April 23, 2019 Author Scripting Moderators Share Posted April 23, 2019 1 minute ago, Alraaayts said: Is yours fixed? No, i've fixed it by myself, but i wouldn't share it here. You still have function which will do the job. But it's possible to make it better, and work nearly all the time. Or you can use IIYAMA example. I'll probably do the same, when i'll rewrite my gamemode. Link to comment
Alraaayts Posted April 23, 2019 Share Posted April 23, 2019 Can you dm and help me how you do it? A friendly help? Link to comment
Scripting Moderators ds1-e Posted April 23, 2019 Author Scripting Moderators Share Posted April 23, 2019 (edited) 1 hour ago, Alraaayts said: Can you dm and help me how you do it? A friendly help? IIYAMA post is in this topic. He explained well when to use it. And about how i did that. Use int loop instead - which is faster, + use this function when drawing a crosshair, should fix most of problems. Edited April 23, 2019 by majqq Link to comment
Alraaayts Posted April 24, 2019 Share Posted April 24, 2019 then how to create the loop? Link to comment
Alraaayts Posted April 24, 2019 Share Posted April 24, 2019 your scripts does not work Link to comment
Scripting Moderators ds1-e Posted April 24, 2019 Author Scripting Moderators Share Posted April 24, 2019 (edited) 2 hours ago, Alraaayts said: then how to create the loop? My mistake, this loop is ok. Are you sure that id of replaced objects in condition are correct? Edited April 24, 2019 by majqq Link to comment
Alraaayts Posted April 24, 2019 Share Posted April 24, 2019 Yes, all id objects are replaced by weapons properly.... Link to comment
Scripting Moderators ds1-e Posted April 24, 2019 Author Scripting Moderators Share Posted April 24, 2019 (edited) 31 minutes ago, Alraaayts said: Yes, all id objects are replaced by weapons properly.... Maybe you could check it again, and to be sure it should be client-side. You can paste code again? I tested it by myself, and it work somehow, not perfectly but it did the basic job. As far i remember you should also replace following objects with custom transparent model. 356 347 358 355 335 322 353 339 357 349 Scan: https://www.virustotal.com/#/file-analysis/MTAyNWY5MzQ5ZjA5YjcyMTZkNmNkNGFhNjI0ZGI5ZjU6MTU1NjExNzU3OA== Download: https://www.mediafire.com/file/rk9bm7r2oo8gq6w/transparent.rar/file Edited April 24, 2019 by majqq Link to comment
Alraaayts Posted May 19, 2019 Share Posted May 19, 2019 Bro i still didn't fix my problem Link to comment
Scripting Moderators ds1-e Posted May 19, 2019 Author Scripting Moderators Share Posted May 19, 2019 32 minutes ago, Alraaayts said: Bro i still didn't fix my problem Then i don't know how can i help, i gave you all ways i used to fix it. Link to comment
Alraaayts Posted May 19, 2019 Share Posted May 19, 2019 Bro do you still have your dayz GM? And do you still manage dayz server?? Link to comment
Scripting Moderators ds1-e Posted May 19, 2019 Author Scripting Moderators Share Posted May 19, 2019 (edited) 12 minutes ago, Alraaayts said: Bro do you still have your dayz GM? And do you still manage dayz server?? I don't have dayz server, and i didn't had. Edited May 19, 2019 by majqq Link to comment
Alraaayts Posted May 19, 2019 Share Posted May 19, 2019 What gm do you manage?? Why u post like this codes?? This is codes for dayz Link to comment
Scripting Moderators ds1-e Posted May 19, 2019 Author Scripting Moderators Share Posted May 19, 2019 17 minutes ago, Alraaayts said: What gm do you manage?? Why u post like this codes?? This is codes for dayz Not only for DayZ, it's custom gamemode. Link to comment
Alraaayts Posted May 21, 2019 Share Posted May 21, 2019 On 05/03/2019 at 02:52, IIYAMA said: While creating elements: -- on top of the script local boneAttachContainer = createElement("boneAttachContainer", "boneAttachContainer") -- while making objects local object = createObject(...) setElementParent(object, boneAttachContainer) -- on top of the script local validBoneAttachModels = {[2763] = true, [1820] = true, [2708] = true, [15036] = true} -- while pressing key local boneAttachContainer = getElementByID("boneAttachContainer") if boneAttachContainer then local objects = getElementsByType("object", boneAttachContainer, true) for i = 1, #objects do local object = objects[i] local model = getElementModel(object) if validBoneAttachModels[model] then setElementAlpha(object, alpha) end end end You might want to consider using a dirty timer or find an event that will occur at that time. Like this code i am looking for... Can you help me how to place ur code on majqq code? Link to comment
Moderators IIYAMA Posted May 21, 2019 Moderators Share Posted May 21, 2019 (edited) 2 hours ago, Alraaayts said: Like this code i am looking for... Can you help me how to place ur code on majqq code? Only if you can explain what the code does. It is bad practice to use code you do not understand. For you, your server and your players. Example: What if my code contains something that would expose your password? Steals your resources? Or makes the performance even worse? Edited May 21, 2019 by IIYAMA Link to comment
Alraaayts Posted May 21, 2019 Share Posted May 21, 2019 So you mean... The one u sent contains bad intention?? 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