Jump to content

Replacing crosshair


Dzsozi (h03)

Recommended Posts

Hello community! Today I found a script on community which is replaces the crosshair depends on the target, so if the target element is a player and if it's in your team then the crosshair becomes green, but if it's not on your team then it becomes red.

I tried to edit it, but I can't find out what's the problem. I want to set a different crosshair for some weapon slots, but it's not working, the crosshair is being replaced, but for every weaponslot the same. What's the problem?

Here's the community script: Click

Here's my code (there's no error in debugscript):

local shader = dxCreateShader ( "crosshair/replace.fx" ) 
local dot = dxCreateTexture("crosshair/img/dot.png") 
local assault = dxCreateTexture("crosshair/img/assault.png") 
local pistol = dxCreateTexture("crosshair/img/pistol.png") 
local shotgun = dxCreateTexture("crosshair/img/shotgun.png") 
local smg = dxCreateTexture("crosshair/img/smg.png") 
  
function replaceCrosshair() 
    if getControlState("aim_weapon") then 
        if getPedWeaponSlot( getLocalPlayer(), 2 ) then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", pistol) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        elseif getPedWeaponSlot( getLocalPlayer(), 3 ) then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", shotgun) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        elseif getPedWeaponSlot( getLocalPlayer(), 4 ) then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", smg) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        elseif getPedWeaponSlot( getLocalPlayer(), 5 ) then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", assault) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        else 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", dot) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        end 
    end 
end 
addEventHandler("onClientRender", root, replaceCrosshair) 

Link to comment
  
local shader = dxCreateShader ( "crosshair/replace.fx" ) 
local dot = dxCreateTexture("crosshair/img/dot.png") 
local assault = dxCreateTexture("crosshair/img/assault.png") 
local pistol = dxCreateTexture("crosshair/img/pistol.png") 
local shotgun = dxCreateTexture("crosshair/img/shotgun.png") 
local smg = dxCreateTexture("crosshair/img/smg.png") 
  
function replaceCrosshair() 
    if getControlState("aim_weapon") then 
        if getPedWeaponSlot( getLocalPlayer() ) == 2 then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", pistol) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        elseif getPedWeaponSlot( getLocalPlayer() ) == 3 then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", shotgun) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        elseif getPedWeaponSlot( getLocalPlayer() ) == 4 then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", smg) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        elseif getPedWeaponSlot( getLocalPlayer() ) == 5 then 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", assault) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        else 
            engineRemoveShaderFromWorldTexture(shader, "siteM16") 
            dxSetShaderValue(shader, "gTexture", dot) 
            engineApplyShaderToWorldTexture(shader, "siteM16") 
        end 
    end 
end 
addEventHandler("onClientRender", root, replaceCrosshair) 
  

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