Jump to content

Weap target fix


iPanda

Recommended Posts

Posted (edited)

Hello.

I have a problem with crosshair (gunpoint).

I want a player to aim weapons MP5 (ID 29), then there is a special sight. Help me.

Create new crosshair (gunpoint):

The event should be triggered when I press the sight (zoom_in Zoom or zoom_out), with push button "mouse2"

png = guiCreateStaticImage(0.311, 0.454, 0.349, 0.626, "target.png", true)  
guiSetVisible(png , false) 

Example:

addEventHandler( "onClientPlayerTarget", root, function( target ) 
    if ( getPedWeapon( localPlayer ) == 29 ) then 
        if ( target ) then 
            guiSetVisible(png, true) 
        else 
            guiSetVisible(png, false) 
        end 
    end 
end) 

Also try this feature, it is shorter and I think correctly, but also does not work.

function target() 
    if isControlEnabled( zoom_in ) == true then 
        guiSetVisible(png, true) 
    else 
        guiSetVisible(png, false) 
    end 
end 

IMPORTANT: it works only when I'm aiming for vehicles. I need a sight at any time when I want to.

Edited by Guest
Posted
Hello.

I have a problem with gunpoint.

I want a player to aim weapons MP5 (ID 29), then there is a special sight. Help me.

png = guiCreateStaticImage(0.311, 0.454, 0.349, 0.626, "target.png", true)  
guiSetVisible(png , false) 
  
addEventHandler( "onClientPlayerTarget", root, function( target ) 
    if ( getPedWeapon( player ) == 29 ) then 
        if ( target ) then 
            guiSetVisible(png, true) 
        else 
            guiSetVisible(png, false) 
        end 
    end 
end) 

Line 5 >

if ( getPedWeapon( player ) == 29 ) then 

player :

The source of this event is the player that targeted the element.

So you must change the player to source .

  

Posted

Line 5 >

if ( getPedWeapon( player ) == 29 ) then 

player :

The source of this event is the player that targeted the element.

So you must change the player to source .

With source also does not work.

ps. player = getLocalPlayer()

  • Moderators
Posted

If you can't find the problem, you have to debug the script. I am saying that for years.....

  
    png = guiCreateStaticImage(0.311, 0.454, 0.349, 0.626, "target.png", true) 
    guiSetVisible(png , false) 
     
    if not isElement(png) then 
        outputChatBox("no png...") 
    end 
      
    addEventHandler( "onClientPlayerTarget", root, function( target ) 
        outputChatBox("target changed localPlayer") 
        if ( getPedWeapon( localPlayer ) == 29 ) then 
            outputChatBox("localPlayer has mp5") 
            if ( target ) then 
                outputChatBox("show png)" 
                guiSetVisible(png, true) 
            else 
                outputChatBox("hide png") 
                guiSetVisible(png, false) 
            end 
        end 
    end)     

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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