Jump to content

Question - Crosshair


manve1

Recommended Posts

I got a problem as it didn't apply the crosshair to any weapon

LUA:

addEventHandler( "onClientResourceStart", resourceRoot, 
    function() 
    local texture = dxCreateTexture ("hud/aimer.png") 
    local shader = dxCreateShader ( "hud/shader.fx" ) 
    dxSetShaderValue ( shader, "gTexture", texture ) 
    engineApplyShaderToWorldTexture ( shader, "sitem16") 
    end 
) 

SHADER:

texture gTexture; 
technique TexReplace 
{ 
    pass P0 
    { 
        Texture[0] = gTexture;  
    } 
} 

And i need one for weapons like deagle, m4 and a sniper, but for sniper a different crosshair

Link to comment

this resource has an exports function's

https://community.multitheftauto.com/ind ... ls&id=6210

exports.crosshairreplace:register(weaponid, newcrosshairpath)

Sets the new crosshair for 'weaponid'. 'newcrosshairpath' should be a path to an image file

 

exports.crosshairreplace:unregister(weaponid)

Restores the default crosshair for 'weaponid'

try something like this :

client:

addEventHandler( "onClientResourceStart", resourceRoot, 
    function ( startedRes ) 
        exports.crosshairreplace:register( 34, "sniperCH.png" ) 
    end 
) 

Link to comment

i think you should edit the script to :

* EDIT

Crosshair = { 
    crosshairs = {}; 
    shader = {}; 
    default = dxCreateTexture("siteM16.png"); 
     
    register = function(weaponid, crosshairpath) 
        if not crosshairpath:find(":") then 
            crosshairpath = (":%s/%s"):format(getResourceName(sourceResource), crosshairpath) 
        end 
        assert(fileExists(crosshairpath), "Invalid File for Crosshair.register") 
         
        if Crosshair.crosshairs[weaponid] then destroyElement(Crosshair.crosshairs[weaponid]) end 
        Crosshair.crosshairs[weaponid] = dxCreateTexture(crosshairpath) 
    end, 
     
    unregister = function(weaponid) 
        if Crosshair.crosshairs[weaponid] then destroyElement(Crosshair.crosshairs[weaponid]) end 
        Crosshair.crosshairs[weaponid] = nil 
    end, 
     
    init = function() 
        Crosshair.shader = dxCreateShader("texreplace.fx") 
        assert(Crosshair.shader, "Could not create Crosshair Replacement Shader") 
        engineApplyShaderToWorldTexture(Crosshair.shader, "siteM16") 
        dxSetShaderValue(Crosshair.shader, "gTexture", Crosshair.default) 
        addEventHandler("onClientPlayerWeaponSwitch", localPlayer, Crosshair.weaponSwitch) 
    end,  
  
    weaponSwitch = function( prev, now ) 
        weapon = getPedWeapon( localPlayer, now ) 
        if weapon == 34 then 
            dxSetShaderValue( Crosshair.shader, "gTexture", Crosshair.crosshairs[weapon] ) 
        else 
            dxSetShaderValue( Crosshair.shader, "gTexture", Crosshair.default ) 
        end 
    end 
} 
  
Crosshair.init() 
  
-- Exports 
register    = Crosshair.register 
unregister  = Crosshair.unregister 

Link to comment

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...