I have seen Player:SetAmmo used in a few examples online, yet I am not able to get it to work.
The example on [url]http://wiki.garrysmod.com/?title=Player.SetAmmo[/url] does not do anything for me, weather it's called on a secondary fire function on a SWEP weapon or manually on a player from lua_run.
I am testing it with "lua_run player.GetHumans()[1]:SetAmmo(100, 'Pistol')" on a single player game. SetHealth works in this case.
Oddly enough, the arguments listed in Garry's changelog state that its the ammo type first, then the count. This method does not work either.
([url]http://webcache.googleusercontent.com/search?q=cache:rwYM8f4DMQ0J:www.garrysmod.com/%3Fdont_buff_my_pylon%3D84+gmod+SetAmmo&cd=4&hl=en&ct=clnk&gl=us[/url])
SetAmmo seemed to zero out my pistol ammo twice it, but this is not repeatable, and I was trying to use the "SMG1" ammo during this time.
Try Using This
[b][url=http://wiki.garrysmod.com/?title=Player.GiveAmmo]Player.GiveAmmo [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
The issue is I am trying to directly set the ammo, not add to it. Right now I am working around it by using RemoveAmmo and GiveAmmo, but that is causing the "ammo added" popups to appear (despite GiveAmmo's popup argument, I am looking into that now).
My specific case requires that no alerts, popups, or noises are used in the ammo changing. The player needs to see it as swapping out the bullet type.
Update:
Turns out the "display popup" argument for GiveAmmo actually hides the popup when true. I have updated the wiki, and my immediate case is solved. However, I would still like to know if SetAmmo works, or has ever worked.
Self-solved. SetAmmo appears to only work with ammo indexes, not names. Unfortunately, the ability for ammo to be referenced by both a name and number severely increases the complexity of my project as a whole...
Sorry, you need to Log In to post a reply to this thread.