Jump to content

Vehicle crosshair (scope)


Xwad

Recommended Posts

Posted

Hi. I want to make a script that makes possible that when i press mouse2 in the rhino then it will aim with a scope. Here is a script but its not working:/ Whats the problem??

  
local textures = {};  
  
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"]); 
    dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair"]); 
end; 
  
local function on_weapon_aimed (key, state) 
if isPedInVehicle(source) then 
if (getElementModel(source) == 432) then 
        if state == "down" then  
            showPlayerHudComponent ("crosshair", false); 
            addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); 
        else  
            removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair);  
        end; 
    end; 
end;  
  
  
addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), 
    function ()  
        -- load textures.  
        textures ["crosshair"] = dxCreateTexture ("images/PKS-07_crosshair.png", "argb", true, "wrap");  
        if not textures ["crosshair"] then  
            outputDebugString ("failed to load \"images/PKS-07_crosshair.png\" texture", 1);  
            return; 
        end; 
        textures ["crosshair_background"] = dxCreateTexture ("images/PKS-07_crosshair_background.png", "argb", true, "wrap");  
        if not textures ["crosshair_background"] then 
            outputDebugString ("failed to load \"images/PKS-07_crosshair_background.png\" texture", 1);  
            return;      
        end; 
     
        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  
                        showPlayerHudComponent ("crosshair", true); 
                    end; 
                end;  
            end); 
    end);  
     
addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), 
    function () 
        unbindKey ("aim_weapon", "both", on_weapon_aimed);  
        if not isPlayerHudComponentVisible ("crosshair") then 
            showPlayerHudComponent ("crosshair", true); 
        end; 
    end); 
     
  

Posted

Any errors in debugscript?

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted
local textures = {}; 
  
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"]); 
    dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair"]); 
end; 
  
local function on_weapon_aimed (key, state) 
if isPedInVehicle(source) then 
if (getElementModel(source) == 432) then 
        if state == "down" then 
            showPlayerHudComponent ("crosshair", false); 
            addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); 
        else 
            removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); 
        end; 
    end; 
end 
end; 
  
  
addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), 
    function () 
        -- load textures. 
        textures ["crosshair"] = dxCreateTexture ("images/PKS-07_crosshair.png", "argb", true, "wrap"); 
        if not textures ["crosshair"] then 
            outputDebugString ("failed to load \"images/PKS-07_crosshair.png\" texture", 1); 
            return; 
        end; 
        textures ["crosshair_background"] = dxCreateTexture ("images/PKS-07_crosshair_background.png", "argb", true, "wrap"); 
        if not textures ["crosshair_background"] then 
            outputDebugString ("failed to load \"images/PKS-07_crosshair_background.png\" texture", 1); 
            return;     
        end; 
    
        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 
                        showPlayerHudComponent ("crosshair", true); 
                    end; 
                end; 
            end); 
    end); 
    
addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), 
    function () 
        unbindKey ("aim_weapon", "both", on_weapon_aimed); 
        if not isPlayerHudComponentVisible ("crosshair") then 
            showPlayerHudComponent ("crosshair", true); 
        end; 
    end); 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

Well, that is really a self-explanatory thing. It says you forgot to put an 'end' to close the function which starts at line 19.

In that case, the below code will work:

  
local textures = {}; 
  
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"]); 
    dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair"]); 
end; 
  
local function on_weapon_aimed (key, state) 
if isPedInVehicle(source) then 
    if (getElementModel(source) == 432) then 
        if state == "down" then 
            showPlayerHudComponent ("crosshair", false); 
            addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); 
        else 
            removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); 
        end; 
    end; 
end; 
end; 
  
  
addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), 
    function () 
        -- load textures. 
        textures ["crosshair"] = dxCreateTexture ("images/PKS-07_crosshair.png", "argb", true, "wrap"); 
        if not textures ["crosshair"] then 
            outputDebugString ("failed to load \"images/PKS-07_crosshair.png\" texture", 1); 
            return; 
        end; 
        textures ["crosshair_background"] = dxCreateTexture ("images/PKS-07_crosshair_background.png", "argb", true, "wrap"); 
        if not textures ["crosshair_background"] then 
            outputDebugString ("failed to load \"images/PKS-07_crosshair_background.png\" texture", 1); 
            return;     
        end; 
    
        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 
                        showPlayerHudComponent ("crosshair", true); 
                    end; 
                end; 
            end); 
    end); 
    
addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), 
    function () 
        unbindKey ("aim_weapon", "both", on_weapon_aimed); 
        if not isPlayerHudComponentVisible ("crosshair") then 
            showPlayerHudComponent ("crosshair", true); 
        end; 
    end); 

Posted

i'm pretty sure there is no function to detect where is the rhino aiming so you would aim in that direction.

Ingame Name: Arnold

If you need my help, contact me on Skype @bshr.ara

NOTE:DO NOT ASK ME FOR SCRIPTS, ASK ME FOR HELP

Posted

ok i fixed but there is a problem that i still cant fix. Its the camera zoom. When i press mouse2 then itt will show the crosshair but its not zooming and i can see my ped:/ what functions need i use for that?

Posted
setCameraMatrix 

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

But setCameraMatrix is for set the camera to a fix point no? i want to use this crosshair like a sniper crosshair but in rhino vehicle

Posted

To zoom in the camera, you need setCameraMatrix, and no, it's not only for a static point.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

Draw an image over whole screen then. And if you want, set player's alpha to 0, to hide the player.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

but i dont want to hide the player i just want to zoom. You know for example world of tanks . When you in the tank and press mouse 2 then it will zoom with a scope

Posted

Zoom in with

setCameraMatrix 

as I told you before.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

The only way to zoom in is with setCameraMatrix. If you have any other idea, why do you keep asking?

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...