Jump to content

How to load a gun in lua?


nolanri

Recommended Posts

player:getPrimaryHandItem():LoadGun()

 

I want to give the gun ammo, whether its reloading the gun from ammo in inventory or just setting the current bullet count to 999, I don't care which I just need to give ammo to a gun in the players primary hand.

 

Help please

Edited by nolanri
Link to comment
Share on other sites

4 minutes ago, tommysticks said:

Sup dude, I think you can use this:

 


local function reloadWeapon()
    local player = getPlayer();
    local primary = player:getPrimaryHandItem();
    primary:getModData().currentCapacity = primary:getModData().maxCapacity;
end

 

Thanks for replying but this just does not seem to work.

Link to comment
Share on other sites

actually it did sort of work. seems like it triggers a normal timed action reload, but it only seems to work when there is 0 ammo in the gun. if there is 1 round still left it does nothing.

 

And its not working on my clones. which was the whole point of my question. I want to give my clones loaded guns and spawn in ranks like a fireing squad or something.

Link to comment
Share on other sites

This worked fine for me:

local function pressTest(_keyPressed)
	local key = _keyPressed;	
	if key == 209 then -- PG DOWN 
		getPlayer():getPrimaryHandItem():getModData().currentCapacity = getPlayer():getPrimaryHandItem():getModData().maxCapacity;
	end
end

Events.OnKeyPressed.Add(pressTest);

 

Link to comment
Share on other sites

4 minutes ago, tommysticks said:

It reloads with any amount.

Right i see it does now. it also triggers the timed action reload IF it has 0 ammo loaded.  But this only seems to work for the Local player. I'm trying to give loaded guns to additionally spawned players. Replacing getPlayer() with their player instance doesnt work.

Link to comment
Share on other sites

I looked at the video for the mod you're working on, without seeing how you are adding the weapons I can only make a guess, you might be able to use something like this to make the weapons have 1000 rounds when they are spawned:

 

local startGun = player:getInventory():AddItem("Base.Shotgun");
startGun:getModData().currentCapacity = 1000;

...or some variation of that by storing the weapon in a variable before it's added.

 

 

Link to comment
Share on other sites

  • 2 weeks later...
On 2016-10-07 at 4:22 PM, tommysticks said:

I looked at the video for the mod you're working on, without seeing how you are adding the weapons I can only make a guess, you might be able to use something like this to make the weapons have 1000 rounds when they are spawned:

 


local startGun = player:getInventory():AddItem("Base.Shotgun");
startGun:getModData().currentCapacity = 1000;

...or some variation of that by storing the weapon in a variable before it's added.

 

 

It worked when i first loaded the gun in my local players hand AND THEN passed the item class instance to my clones.

Link to comment
Share on other sites

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
×
×
  • Create New...