Jump to content

How to make a gun that adds ammo to the player's inventory?


Recommended Posts

Hello all. I'm fairly new to the modding scene and am just really starting to learn with the Creation Kit. I know the weapon I want to make, but am not sure how to go about doing this however.

 

The premise is fairly simple: I want a gun that generates its own ammo. Figuring out how to do this might be beyond me though. At first I thought I might be able to just have a weapon with a mod that has an effect like drinking a Nuka-Cola, where a single cap is added to your inventory. Then I could just swap the cap for the ammo and be done, but that particular effect "NukaColaBottleCapAdder" can only add MISC items, not ammo. My next idea was to attempt to use a quest, sort of like how NPCs just give you items from time to time, and make this quest activate or repeat stages of ammo giving over time or by firing the gun, but after a couple hours of sifting through dialogues and quest data, I can safely say I am completely confused by that concept, so probably a no-go.

 

Does anyone here have any ideas on how this might work that someone of my skill level could pull off? If 4 had recharging weapons like NV did, I'd feel a lot more confident in myself, but unfortunately it doesn't. I'm getting a bit frustrated because the idea of adding items to the player's inventory seems so simple in theory since it can be done with one easy console command, but I have no idea how to make it work... Any help is appreciated... Thoughts?

Link to comment
Share on other sites

Ok, here's script. You should attach this to the needed weapon.

 

this script as it is now will add 1 ammo each second until total count of that ammo in player inventory becomes 10. And it will check each second if ammo becomes less than 10 to begin process again. You can change values of the variables to your needs

float interval = 1.0 ;this is interval of how much time is needed the amount of ammo to be added in inventory
int amount = 1 ;how much ammo will be added in each interval second
int maxAmmo = 10 ;this is max number of ammo that will be added to player
bool isSilent = true ;whether or not notification to appear in corner when the amount of ammo is added

Ammo weaponAmmo

Event OnEquipped(Actor akActor)
	if akActor == Game.GetPlayer()
		weaponAmmo = Game.GetPlayer().getequippedweapon().GetAmmo()
		if(ammoChecker(weaponAmmo))
			StartTimer(interval,10)
		endif    	
	endIf
endEvent

Event OnTimer(int aiTimerID)		
	If aiTimerID == 10
		if (ammoChecker(weaponAmmo))
			  Game.getplayer().additem(weaponAmmo,amount,isSilent)
		endif
                StartTimer(interval,10)
	EndIf
EndEvent

bool Function ammoChecker(Ammo weapAmmo)
	if (Game.GetPlayer().getitemcount(weaponAmmo) < maxAmmo)
		return True
	else
		return False
	endif
Endfunction

Event OnUnequipped(Actor akActor)
	if akActor == Game.GetPlayer()
		CancelTimer(10)
	endIf
endEvent 

I don't have access to CK and can't compile it, so just let me know if you got any errors.

Edited by shavkacagarikia
Link to comment
Share on other sites

Sorry it's taken me a while to respond, but your script worked beautifully. The weapon I made was intended for a PS4 mod, which unfortunately doesn't allow for loose pex files, but it's pretty damn awesome to play around with on PC. I couldn't find a way to make the ammo go directly into the magazine instead of the reserves (even tried using the effect of the "Unlimited" legendary mod, but to no avail), so I just made the weapon reload instantly instead. Thank you so much for throwing this together though. I even had a friend of mine who works as a programmer for a living look through it and help me implement it in the CK, and he complimented it as a "pretty script" haha. So yeah, worked like a charm, thanks again!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...