Jump to content

createWeapon hit position


Recommended Posts

I'm trying to make custom player's weapon. But I've got a problem.

1. Player equipped normal AK-47

2. I'm creating custom weapon with createWeapon ( "ak-47"

3. I'm attaching this custom weapon via crystalmv bone_attach to player (bone 12)

4. Both AK-47s are in the same position (visually)

5. When custom weapon firing, it's hit position is slightly to the left-bottom than crosshair

I tried to change custom weapon's fire_rotation. So it worked fine on middle-distance firing, but when I moved camera to the bottom, hit position moved to the left from the crosshair, and when I moved camera to the top, hit position moved to the right from the crosshair.

Also I tried to use setWeaponTarhet in onClientRender:

  
function fireWeapOnClientRender() 
    for i, v in ipairs ( getElementsByType ("weapon", true) ) do 
        if getElementData ( v, "cweap" ) then 
            local owner = getElementData ( v, "cweap.owner" ) 
            local sx, sy, sz = getPedTargetEnd(owner) 
            setWeaponTarget (v,sx, sy, sz) 
        end 
    end 
end 
  
addEventHandler('onClientRender', root, fireWeapOnClientRender ) 
  

But in this case custom weapon just don't fire.

Maybe someone knows how fix this problem?

5. When custom weapon firing, it's hit position is slightly to the left-bottom than crosshair
Link to comment
  • Moderators

1) Get the extend line function from the stealth resource. (used for the laser)

2) Extend the line from getPedTargetStart t/m getPedTargetEnd t/m as far as possible.

and you got your target.

Link to comment
1) Get the extend line function from the stealth resource. (used for the laser)

2) Extend the line from getPedTargetStart t/m getPedTargetEnd t/m as far as possible.

and you got your target.

Thanks, but my problem was that weapon didn't shoot if I'm was using setWeponTarget.

Setting these two flags fixed the problem:

setWeaponFlags (weapon, "shoot_if_out_of_range", true)

setWeaponFlags (weapon, "shoot_if_blocked", true)

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