Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Teki

[SHDN] How to retrieve the target of bullet when shooting

Recommended Posts

Teki

Hi ! I'm reading this forum for a while now but this is my first post, so nice to meet you everybody ! =)

 

I'm working on a First Person script but i'm stuck with a problem : i can't manage to get/set the point the player is aiming to : I tried to get the default aiming camera rotation but it seems to disapear when another camera is active.

 

I want to change it because the weapons don't shoot right forward the player

 

Currently i'm using the Player Direction and the Head Bone vertical rotation and it's not far of the expected result but the crosshair don't perfectly fit the bullet target and it is still messy. (i made my own crosshair, i don't know how to use the default one ?)

 

I'm not a native speaker, so please forgive me (and tell me ?) if i made mistakes or if i'm not clear,

Thanks,

Teki

Share this post


Link to post
Share on other sites
byteMe420

a first person script is not going to work nicely on gta iv because the game handles movement in a 3rd person reference only (depends on where you aim the third person camera) and you cant really override that with the scripthooks and native functions. Anyways for aiming this is the camera used, it's handle is 258 and you can make a reference to it like this...

        private Camera GetAimingCamera()        {            Type t = typeof(Camera);            int camHandle = 258;            object obj = Activator.CreateInstance(t, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { camHandle }, null);            Camera aimCam = obj as Camera;            return aimCam;        }

ive noticed if u call this code a lot, it wont work (returns null iirc) so you probably have to delete them when done, use that to get the direction of your gunfire, where that camera aims is where you shoot

Edited by byteMe420

Share this post


Link to post
Share on other sites
Teki

a first person script is not going to work nicely on gta iv because the game handles movement in a 3rd person reference only (depends on where you aim the third person camera) and you cant really override that with the scripthooks and native functions. Anyways for aiming this is the camera used, it's handle is 258 and you can make a reference to it like this...

        private Camera GetAimingCamera()        {            Type t = typeof(Camera);            int camHandle = 258;            object obj = Activator.CreateInstance(t, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { camHandle }, null);            Camera aimCam = obj as Camera;            return aimCam;        }

ive noticed if u call this code a lot, it wont work (returns null iirc) so you probably have to delete them when done, use that to get the direction of your gunfire, where that camera aims is where you shoot

 

Thanks a lot that is exactly what i was searching for !

 

Where this camHandle come from ? I've found nothing documenting that thing ...

 

I've noticed too a null return with this function when i load a save, but i don't understand what you mean by "delete them when done", i try to make sure to don't keep any reference to this camera when no more needed, but the problem remains. It seems the handle is'nt the same after a save was loaded, or i missed something ...

 

Again, thanks !

Edited by Teki

Share this post


Link to post
Share on other sites
InfamousSabre

Thanks a lot that is exactly what i was searching for !

 

Where this camHandle come from ? I've found nothing documenting that thing ...

 

I've noticed too a null return with this function when i load a save, but i don't understand what you mean by "delete them when done", i try to make sure to don't keep any reference to this camera when no more needed, but the problem remains. It seems the handle is'nt the same after a save was loaded, or i missed something ...

 

Again, thanks !

 

 

It comes from me, byteMe420, and LostProphet. I found the whole 258 bit, and LostProphet helped me use it with Reflection.

Right, it does change when loading a save game. Such things are not part of normal play imho, so I never bothered to find another way to do this.

 

This isn't the best way to get this camera, it's just the first one I tried that worked.

Edited by InfamousSabre

Share this post


Link to post
Share on other sites
byteMe420

 

Thanks a lot that is exactly what i was searching for !

 

Where this camHandle come from ? I've found nothing documenting that thing ...

 

I've noticed too a null return with this function when i load a save, but i don't understand what you mean by "delete them when done", i try to make sure to don't keep any reference to this camera when no more needed, but the problem remains. It seems the handle is'nt the same after a save was loaded, or i missed something ...

 

Again, thanks !

 

 

It comes from me, byteMe420, and LostProphet. I found the whole 258 bit, and LostProphet helped me use it with Reflection.

Right, it does change when loading a save game. Such things are not part of normal play imho, so I never bothered to find another way to do this.

 

This isn't the best way to get this camera, it's just the first one I tried that worked.

 

yeah it was when i was making my first person script and learned it cant be done without overriding the default actions of the game (camera direction determines how player moves). So you cant do that with natives unless maybe you disable character movement (Player.CanControlCharacter = false) and script all the animations yourself. Not sure if that would work but you need to disable the way the player moves in third person to make a nice first person script... or just go play V now and delete IV xD

 

btw that cam 258 is sitting above and to the right of the player so it is aiming from a different perspective than your first person cam so aiming is not going to be accurate from your first person cam.

 

 

(overhead view, you need to adjust your fps direction depending on where 258 is looking and for different ranges the direction is different, it wont work, and cam 258 can't be moved because it is likely the game is constantly setting it's position)

juG6xFO.png

Edited by byteMe420

Share this post


Link to post
Share on other sites
byteMe420

 

a first person script is not going to work nicely on gta iv because the game handles movement in a 3rd person reference only (depends on where you aim the third person camera) and you cant really override that with the scripthooks and native functions. Anyways for aiming this is the camera used, it's handle is 258 and you can make a reference to it like this...

        private Camera GetAimingCamera()        {            Type t = typeof(Camera);            int camHandle = 258;            object obj = Activator.CreateInstance(t, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { camHandle }, null);            Camera aimCam = obj as Camera;            return aimCam;        }

ive noticed if u call this code a lot, it wont work (returns null iirc) so you probably have to delete them when done, use that to get the direction of your gunfire, where that camera aims is where you shoot

 

but i don't understand what you mean by "delete them when done", i try to make sure to don't keep any reference to this camera when no more needed, but the problem remains.

 

public unsafe void Delete(){    if (this.Exists())    {        base.SetExistsFalse();        if (this.pHandle != 0)        {            if (!this.Exists())            {                throw new NonExistingObjectException();            }            if (<Module>.Scripting.?A0x694621a4.IsCamActive(this.pHandle) != null)            {                this.Deactivate();            }            int pHandle = this.pHandle;            NativeContext3* cxt = Function.cxt3;            <Module>.unmanaged.NativeContext3.Reset(cxt);            <Module>.unmanaged.NativeContext3.Push<int>(cxt, pHandle);            <Module>.unmanaged.NativeContext3.Invoke((sbyte*)(&<Module>[email protected][email protected]@[email protected]), cxt);            <Module>.unmanaged.NativeContext3.GetResult<int>(cxt);        }    }}

scripthookdotnet via ilspy... so u see the gta native used to destroy cameras, either use the Camera class to delete or call the native and pass the handle to the native

 

http://www.gtamodding.com/wiki/DESTROY_CAM

 

if you review the shdn source code or put in a reflection program like ilspy you can learn alot about how gta works

 

also by you not keeping reference to the camera variable in your script only tells .Net garbage collector to free the memory used for your variable but the Camera is also a game resource you created and this resource is not managed by .Net. R* devs create their own disposal methods and don't rely on something like .Net. .Net can't do it because GTA stuff is not managed by .Net ;)

 

what would be nice is all these classes in shdn that create gta resources, implement idisposable and in the dispose methods it calls the gta native to destroy or whatever and then you could do something like...

using (Camera cam = new Camera()){    //use here} //disposed here, but scripthookdotnet needs to have this built in, it does not so you need to destroy yourself
Edited by byteMe420

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.