Jump to content

Is there a native that can reduce the player's total ammo?


SuperNovaXM
 Share

Recommended Posts

Hi, 

I'm fairly new to modding in general, but I've followed a few tutorials successfully and now I have some questions. I was trying to use the SET_PED_AMMO native function but when I went to put in the weapon hash it gives me the error: cannot convert from 'RDR2.WeaponHash' to 'RDR2.Native.InputArgument'.

 

I tried constructing an InputArgument using this code, but it crashed my game: 

 

var hash = new RDR2.Native.InputArgument(CurrentPlayerWeapon()); //CurrentPlayerWeapon() returns the hash of the weapon currently equipped

Function.Call(Hash.SET_PED_AMMO, Game.Player.Character.Handle, hash, 100);

 

If there's better documentation than what little I found, or if there's any other way to do this then do let me know.

Edited by SuperNovaXM
Link to comment
Share on other sites

Are you using ABs script hook or RPH?

 

Edit: forget what I asked, just saw the forum you posted in. Why dont you try GET_CURRENT_PED_WEAPON and pass the player ped to it? In the parameters you have to pass the variable in which the weapon shall be stored.

Something like this should do it:

Ped playerPed = PLAYER::PLAYER_PED_ID();
Hash weaponHash = 0;
int ammo = 100;

WEAPON::GET_CURRENT_PED_WEAPON(playerPed, &weaponHash, false, 0, false);
if (weaponHash != 0) WEAPON::SET_PED_AMMO(playerPed, weaponHash, ammo);

 

Edited by HughJanus
Link to comment
Share on other sites

Hmm, it seems like you're using Alexander Blade's c++ scripthook, where I'm using the RDR2.net scripthook api. If I don't find any solutions to my problem then I'll start to look into getting the developing with the AB scripthook, if you have any good resources for starting a project using the AB sdk that would be much appreciated.

Link to comment
Share on other sites

Thanks for your help, but it turns out I was doing a number of things wrong unrelated to the natives so I'm glad I caught that as well. That said, I have a new issue regarding the natives that ought to modify the player's ammo. I have tried using SET_PED_AMMO, SET_PED_AMMO_BY_TYPE, _ADD_AMMO_TO_PED, and other similar functions and the only two I've actually gotten to work are SET_PED_INFINITE_AMMO which is useless in my case and SET_AMMO_IN_CLIP which isn't robust enough as it only moves stored ammo to and from your gun. I was wondering if I was doing something wrong again or if these functions don't work for the player as I thought they might.

Link to comment
Share on other sites

I tested it as well, and it seems that many of the ammo natives do not work correctly on the player (or at all). For instance, SET_PED_AMMO_BY_TYPE has support to remove ammo and calculates the amount to remove properly, only for the actual call to CPedInventory::RemoveAmmo to ignore the request due to a (wrong?) hardcoded parameter. What has worked for me though was 0xB6CFEC32E3742779 aka _REMOVE_AMMO_FROM_PED_BY_TYPE. Calling it like this to remove one ammo from your revolver (RPH syntax):

Game.CallNative(0xB6CFEC32E3742779, Game.LocalPlayer.Character, Game.GetHashKey("AMMO_REVOLVER"), 1, 0x2188E0A3);

 

 

  • Like 1
  • Thanks 1
Link to comment
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.

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.

 Share

×
×
  • Create New...