India Posted February 14, 2021 Posted February 14, 2021 Hello, i have a script with sniper crosshair but there is a problem Example: DMR weapon have 1 bullet, when its reloading, if i don't release the right mouse button crosshair not closing. i want it to disable its crosshair while reloading ammo. Anyone can help me? client.lua local textures = {}; local cross = false local function render_crosshair() local screenw,screenh = guiGetScreenSize (); local s = screenw * 0.5; local u,v = (screenw - s)*0.5, (screenh - s)*0.5; local black = tocolor (0, 0, 0, 255); dxDrawRectangle (0, 0, screenw, v, black); dxDrawRectangle (0, 0, u, screenh, black); dxDrawRectangle (0, screenh, screenw, -v, black); dxDrawRectangle (screenw, screenh, -u, -screenh, black); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair_background"]); if cross == "DMR" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_dmr"]); elseif cross == "AS50" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_as50"]); elseif cross == "VSS" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_vss"]); elseif cross == "VSSK" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_vss"]); elseif cross == "M107" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_as50"]); elseif cross == "M2000 CheyTac" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_as50"]); end end; local function on_weapon_aimed (key, state) local weapon_sniper_rifle = 34; if getPedWeapon (getLocalPlayer ()) == weapon_sniper_rifle then if state == "down" then cross = getElementData(getLocalPlayer(),"currentweapon_1") setPlayerHudComponentVisible ("crosshair", false); addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); else cross = false removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); end; end; end; addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () textures ["crosshair_background"] = dxCreateTexture ("images/crosshairs/crossBackground1.png", "argb", true, "wrap") textures ["cross_dmr"] = dxCreateTexture ("images/crosshairs/aim_dmr.png", "argb", true, "wrap"); textures ["cross_as50"] = dxCreateTexture ("images/crosshairs/aim_as50.png", "argb", true, "wrap"); textures ["cross_vss"] = dxCreateTexture ("images/crosshairs/aim_vss.png", "argb", true, "wrap"); bindKey ("aim_weapon", "both", on_weapon_aimed); addEventHandler ("onClientPlayerWeaponSwitch", getRootElement (), function (previousWeaponSlot) local weaponslot_type_sniper = 6; if previousWeaponSlot == weaponslot_type_sniper then if not isPlayerHudComponentVisible ("crosshair") then setPlayerHudComponentVisible ("crosshair", true); end; end; end); end); addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), function () unbindKey ("aim_weapon", "both", on_weapon_aimed); if not isPlayerHudComponentVisible ("crosshair") then setPlayerHudComponentVisible ("crosshair", true); end; end); Pictures for details; Spoiler Spoiler Spoiler
Tekken Posted February 14, 2021 Posted February 14, 2021 (edited) getPedSimpleTask() maybe? Or getPedTask() search for reload task Edited February 14, 2021 by Tekken Typo Resources I made: attachToBones - A newer bone_attach. Simple Level system - Just a simple level system. Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!
India Posted February 14, 2021 Author Posted February 14, 2021 2 hours ago, Tekken said: getPedSimpleTask() maybe? Or getPedTask() search for reload task hm, can you make it for me? please
Tekken Posted February 14, 2021 Posted February 14, 2021 No 1 1 Resources I made: attachToBones - A newer bone_attach. Simple Level system - Just a simple level system. Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!
Ayush Rathore Posted February 18, 2021 Posted February 18, 2021 On 14/02/2021 at 18:29, India said: Hello, i have a script with sniper crosshair but there is a problem Example: DMR weapon have 1 bullet, when its reloading, if i don't release the right mouse button crosshair not closing. i want it to disable its crosshair while reloading ammo. Anyone can help me? client.lua local textures = {}; local cross = false local function render_crosshair() local screenw,screenh = guiGetScreenSize (); local s = screenw * 0.5; local u,v = (screenw - s)*0.5, (screenh - s)*0.5; local black = tocolor (0, 0, 0, 255); dxDrawRectangle (0, 0, screenw, v, black); dxDrawRectangle (0, 0, u, screenh, black); dxDrawRectangle (0, screenh, screenw, -v, black); dxDrawRectangle (screenw, screenh, -u, -screenh, black); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair_background"]); if cross == "DMR" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_dmr"]); elseif cross == "AS50" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_as50"]); elseif cross == "VSS" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_vss"]); elseif cross == "VSSK" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_vss"]); elseif cross == "M107" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_as50"]); elseif cross == "M2000 CheyTac" then dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["cross_as50"]); end end; local function on_weapon_aimed (key, state) local weapon_sniper_rifle = 34; if getPedWeapon (getLocalPlayer ()) == weapon_sniper_rifle then if state == "down" then cross = getElementData(getLocalPlayer(),"currentweapon_1") setPlayerHudComponentVisible ("crosshair", false); addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); else cross = false removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); end; end; end; addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () textures ["crosshair_background"] = dxCreateTexture ("images/crosshairs/crossBackground1.png", "argb", true, "wrap") textures ["cross_dmr"] = dxCreateTexture ("images/crosshairs/aim_dmr.png", "argb", true, "wrap"); textures ["cross_as50"] = dxCreateTexture ("images/crosshairs/aim_as50.png", "argb", true, "wrap"); textures ["cross_vss"] = dxCreateTexture ("images/crosshairs/aim_vss.png", "argb", true, "wrap"); bindKey ("aim_weapon", "both", on_weapon_aimed); addEventHandler ("onClientPlayerWeaponSwitch", getRootElement (), function (previousWeaponSlot) local weaponslot_type_sniper = 6; if previousWeaponSlot == weaponslot_type_sniper then if not isPlayerHudComponentVisible ("crosshair") then setPlayerHudComponentVisible ("crosshair", true); end; end; end); end); addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), function () unbindKey ("aim_weapon", "both", on_weapon_aimed); if not isPlayerHudComponentVisible ("crosshair") then setPlayerHudComponentVisible ("crosshair", true); end; end); Pictures for details; Hide contents Hide contents Hide contents For this you may use this little script --server side function reloadWeapon(weapon, ammo) if client then takeWeapon( client, weapon ) giveWeapon( client, weapon, ammo, true) end end addEvent("relWep", true) addEventHandler("relWep", resourceRoot, reloadWeapon) --client side local slots = { [5] = { aimDelay = 1000, }, [6] = { aimDelay = 1000, } } local canAim = true function hideRadar(player, slot, weapon, ammo, aimDelay) if slot == 0 then return end setPedWeaponSlot(player,0) canAim = false if ammo > 1 then if (not isPedDucked(player)) then setPedAnimation(player, "silenced", "silence_reload", aimDelay, false, false, false, false) end triggerServerEvent("relWep", resourceRoot, weapon, ammo) end setTimer(function() canAim = true end, aimDelay, 1) end function playerPressedKey(button, press) if (press) and button == "mouse2" then if canAim == false then cancelEvent() end end end addEventHandler("onClientKey", root, playerPressedKey) addEventHandler("onClientPlayerWeaponFire", root, function() local player = getLocalPlayer() local slot = getPedWeaponSlot(player) local weapon = getPedWeapon(player) local ammo = getPedTotalAmmo(player, slot) if (slots[slot]) then hideRadar(player, slot, weapon, ammo, slots[slot].aimDelay) end end) I am a paid scripter. Contact: [email protected] Instagram: https://www.instagram.com/ayush_kumar_rathore/ Give me a 'Thanks' if I helped.
India Posted February 18, 2021 Author Posted February 18, 2021 5 hours ago, Ayush Rathore said: For this you may use this little script --server side function reloadWeapon(weapon, ammo) if client then takeWeapon( client, weapon ) giveWeapon( client, weapon, ammo, true) end end addEvent("relWep", true) addEventHandler("relWep", resourceRoot, reloadWeapon) --client side local slots = { [5] = { aimDelay = 1000, }, [6] = { aimDelay = 1000, } } local canAim = true function hideRadar(player, slot, weapon, ammo, aimDelay) if slot == 0 then return end setPedWeaponSlot(player,0) canAim = false if ammo > 1 then if (not isPedDucked(player)) then setPedAnimation(player, "silenced", "silence_reload", aimDelay, false, false, false, false) end triggerServerEvent("relWep", resourceRoot, weapon, ammo) end setTimer(function() canAim = true end, aimDelay, 1) end function playerPressedKey(button, press) if (press) and button == "mouse2" then if canAim == false then cancelEvent() end end end addEventHandler("onClientKey", root, playerPressedKey) addEventHandler("onClientPlayerWeaponFire", root, function() local player = getLocalPlayer() local slot = getPedWeaponSlot(player) local weapon = getPedWeapon(player) local ammo = getPedTotalAmmo(player, slot) if (slots[slot]) then hideRadar(player, slot, weapon, ammo, slots[slot].aimDelay) end end) I didn't mention it, i mean when sniper reloading, crosshair still showing or when i press "R" crosshair still showing
Ayush Rathore Posted February 19, 2021 Posted February 19, 2021 On 18/02/2021 at 14:22, India said: I didn't mention it, i mean when sniper reloading, crosshair still showing or when i press "R" crosshair still showing I know just run this and tell if your problem is solved I am a paid scripter. Contact: [email protected] Instagram: https://www.instagram.com/ayush_kumar_rathore/ Give me a 'Thanks' if I helped.
India Posted February 19, 2021 Author Posted February 19, 2021 9 hours ago, Ayush Rathore said: I know just run this and tell if your problem is solved not solved 1
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