Leo Messi Posted September 21, 2017 Share Posted September 21, 2017 (edited) Hello, My friend made binds script but once I switch weapons there will be FPS drops, I don't know why. Here is the code; https://pastebin.com/raw/AwpcMM3d Edited September 21, 2017 by Leo Messi .. Link to comment
Moderators IIYAMA Posted September 21, 2017 Moderators Share Posted September 21, 2017 function Switch(button,press) wep = getPedWeaponSlot(localPlayer) a= {} for z=0,12 do a[z] = exports.SMGsettings:getSetting(tostring(z)) end for z= 0,12 do if button == a[0] then if(press) then setPedWeaponSlot(localPlayer, 0) end end if a[0] == a[z+1] then addEventHandler("onClientKey", root, function (button, press) if button == a[0] then if (press) then if wep == 0 then setPedWeaponSlot(localPlayer, z+1) else setPedWeaponSlot(localPlayer,0) end end end end) end end for z= 0,12 do if button == a[2] then if(press) then setPedWeaponSlot(localPlayer, 2) end end if a[2] == a[z+3] then addEventHandler("onClientKey", root, function (button, press) if button == a[2] then if (press) then if wep == 2 then setPedWeaponSlot(localPlayer, z+3) else setPedWeaponSlot(localPlayer,2) end end end end) end end for z= 0,12 do if button == a[3] then if(press) then setPedWeaponSlot(localPlayer, 3) end end if a[3] == a[z+4] then addEventHandler("onClientKey", root, function (button, press) if button == a[3] then if (press) then if wep == 3 then setPedWeaponSlot(localPlayer, z+4) else setPedWeaponSlot(localPlayer,3) end end end end) end end for z= 0,12 do if button == a[4] then if(press) then setPedWeaponSlot(localPlayer, 4) end end if a[4] == a[z+5] then addEventHandler("onClientKey", root, function (button, press) if button == a[4] then if (press) then if wep == 4 then setPedWeaponSlot(localPlayer, z+5) else setPedWeaponSlot(localPlayer,4) end end end end) end end for z= 0,12 do if button == a[5] then if(press) then setPedWeaponSlot(localPlayer, 5) end end if a[5] == a[z+6] then addEventHandler("onClientKey", root, function (button, press) if button == a[5] then if (press) then if wep == 5 then setPedWeaponSlot(localPlayer, z+6) else setPedWeaponSlot(localPlayer,5) end end end end) end end for z= 0,12 do if button == a[6] then if(press) then setPedWeaponSlot(localPlayer, 6) end end if a[6] == a[z+7] then addEventHandler("onClientKey", root, function (button, press) if button == a[6] then if (press) then if wep == 6 then setPedWeaponSlot(localPlayer, z+7) else setPedWeaponSlot(localPlayer,6) end end end end) end end for z= 0,12 do if button == a[7] then if(press) then setPedWeaponSlot(localPlayer, 7) end end if a[7] == a[z+8] then addEventHandler("onClientKey", root, function (button, press) if button == a[7] then if (press) then if wep ==7 then setPedWeaponSlot(localPlayer, z+8) else setPedWeaponSlot(localPlayer,7) end end end end) end end for z= 0,12 do if button == a[8] then if(press) then setPedWeaponSlot(localPlayer, 8) end end if a[8] == a[z+9] then addEventHandler("onClientKey", root, function (button, press) if button == a[8] then if (press) then if wep ==8 then setPedWeaponSlot(localPlayer, z+9) else setPedWeaponSlot(localPlayer,8) end end end end) end end end addEventHandler("onClientKey", localPlayer, Switch) Adding infinity addEventHandlers, to new created functions and not clearing the Switch function block after every execution. That is what causing the lagg. Your friend should be the one posting the code. If he wants to fix his code, he should start with making a flowchart to figure out which steps he has to make to rewrite his code. Because it is extremely unoptimised and should be recreated. 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