Jump to content

createWeapon hit position


Recommended Posts

Posted

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
  • Moderators
Posted

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.

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

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
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)

Posted

Are Custom weapons even synced nowadays? I wanted to make some scripts with custom weapons but i heard that they are still WIP, not finished and buggy/not synced/ have whatever problems.

n-560x95_FFFFFF_FFFFFF_000000_000000.png

  • Moderators
Posted

They are not by default, it is something you have to make. When the custom weapons got released, I created my own script for it. You should do it too if you want it that badly.

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

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

It's not really important for me at the moment, I have to do other stuff first. I plan some things like MG Nests and coaxial rhino machine guns.

n-560x95_FFFFFF_FFFFFF_000000_000000.png

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