Jump to content

Ammo Dispenser script help


mrlostsoul

Recommended Posts

Hi,

 

I want to add the Alaska DLC Ammo Dispenser to the player house in Megaton.

 

Now, I already made it into its own plug-in. I've already placed the ammo dispenser where I want it. I've been able to use it, but I only get the message "No ammo added", "maximum Ammo reached." I can't remember what the message actually said. But basically it's telling me I can't add anymore ammo. So I gave all my 10mm ammo to a companion to see if I have to have 0 before it gives me more ammo. And I'm carrying a weapon that requires 10mm. But the dispenser still won't give me ammo.

 

I took a look at the script. I'm new to modding. But I'm slowly picking things up by asking questions when I make a small mod, or when I download a mod, and it doesn't work. So I have to fix something the author forgot to do. For example, I just created summon pills for my companions including Clover and Cross. But I still have very little clue about script. So I need help.

 

Basically, I want the dispenser to give 50 rounds to whatever weapon, I'm carrying that is empty of ammo. Even though I may have another weapon of different ammo type that is fully stocked. If it's possible. If I have to, I can make more dispensers with each having specific ammo, if that's the only solution.

 

I've already made the dispenser and script unique. I've copied, renamed them, and created a new form. So any changes I do, will only affect my plug-in and my unique dispenser. But my attempts at changing the script have failed.

 

I've added the original script below.

 

 

 

scn DLC02AmmoBoxSCRIPT

 

;This script handles the giving of ammo the player when he activates the ammo box, and the random flickering that occures on the box.

 

short hasAmmo ;Number of specific ammo the player has in his inventory

short giveAmmo

float disableTimer

short switched

 

short ammoAdded

 

short MaxMicroFusionCell

short MaxGrenadeFrag

short MaxMineFrag

short MaxMissile

 

;GLOBALS

;DLC02Max10mm

;DLC02Max556mm

;DLC02MaxFuel

;DLC02Max5mm

;DLC02Max308Caliber

;DLC02MaxShells

 

;-----Flickering Stuff----

short flickering

short flickerOnSecond ;(must be less than 100)

float myTimer ;COUNTS UP to DLC02RezFlickerTime

 

 

float timerToStopShader ;COUNTS DOWN

 

Begin OnLoad

 

set disableTimer to .5

 

 

 

 

set MaxMicroFusionCell to 10

set MaxGrenadeFrag to 4

set MaxMineFrag to 4

set MaxMissile to 4

 

 

 

;-----Flickering Stuff----

set flickerOnSecond to GetRandomPercent * DLC02RezFlickerTime/100 + 1 ;example, if 25, this rolls a die between 1 and 25

set myTimer to 0

set flickering to 1

 

End

 

 

 

Begin OnActivate

 

if ( IsActionRef Player == 1 )

 

set ammoAdded to 0

 

;--------10MM Weapons--------

if (player.GetItemCount DLC02Weap10mmPistol >0) || (player.GetItemCount DLC02Weap10mmPistolSilenced >0) || (player.GetItemCount DLC02Weap10mmSubmachineGun >0) || (player.GetItemCount DLC02WeapChinesePistol >0)

 

if (player.GetItemCount Ammo10mm >= DLC02Max10mm)

 

;Do Nothing

 

elseif (player.GetItemCount Ammo10mm < DLC02Max10mm)

set hasAmmo to player.GetItemCount Ammo10mm

set giveAmmo to DLC02Max10mm - hasAmmo

player.AddItem Ammo10mm giveAmmo 1

set ammoAdded to 1

endif

 

endif

 

 

;--------556MM Weapons--------

if (player.GetItemCount DLC02WeapChineseAssaultRifle >0) || (player.GetItemCount DLC02WeapAssaultRifle >0)

 

if (player.GetItemCount Ammo556mm >= DLC02Max556mm)

 

;Do Nothing

elseif (player.GetItemCount Ammo556mm < DLC02Max556mm)

 

set hasAmmo to player.GetItemCount Ammo556mm

set giveAmmo to DLC02Max556mm - hasAmmo

player.AddItem Ammo556mm giveAmmo 1

set ammoAdded to 1

endif

 

endif

 

 

;--------Flamer--------

if (player.GetItemCount DLC02WeapFlamer > 0)

 

if (player.GetItemCount AmmoFlamerFuel >= DLC02MaxFuel)

 

;Do Nothing

elseif (player.GetItemCount AmmoFlamerFuel < DLC02MaxFuel)

 

set hasAmmo to player.GetItemCount AmmoFlamerFuel

set giveAmmo to DLC02MaxFuel - hasAmmo

player.AddItem AmmoFlamerFuel giveAmmo 1

set ammoAdded to 1

endif

 

endif

 

 

;--------Gauss Rifle--------

; if (player.GetItemCount DLC02WeapGaussRifle > 0)

;

; if (player.GetItemCount AmmoMicroFusionCell >= MaxMicroFusionCell)

;

; ;Do Nothing

; elseif (player.GetItemCount AmmoMicroFusionCell < MaxMicroFusionCell)

;

; set hasAmmo to player.GetItemCount AmmoMicroFusionCell

; set giveAmmo to MaxMicroFusionCell - hasAmmo

; player.AddItem AmmoMicroFusionCell giveAmmo 1

; set ammoAdded to 1

; endif

;

; endif

 

 

;--------Frag Grenade--------

; if (player.GetItemCount DLC02WeapGrenadeFrag >= MaxGrenadeFrag )

;

; ;Do Nothing

;

; elseif (player.GetItemCount DLC02WeapGrenadeFrag < MaxGrenadeFrag )

;

; set hasAmmo to player.GetItemCount DLC02WeapGrenadeFrag

; set giveAmmo to MaxGrenadeFrag - hasAmmo

; player.AddItem DLC02WeapGrenadeFrag giveAmmo 1

; set ammoAdded to 1

; endif

 

 

;--------Frag Mine-------

; if (player.GetItemCount DLC02WeapMineFrag >= MaxMineFrag )

;

; ;Do Nothing

;

; elseif (player.GetItemCount DLC02WeapMineFrag < MaxMineFrag )

;

; set hasAmmo to player.GetItemCount DLC02WeapMineFrag

; set giveAmmo to MaxMineFrag - hasAmmo

; player.AddItem DLC02WeapMineFrag giveAmmo 1

; set ammoAdded to 1

; endif

 

 

;--------Minigun--------

if (player.GetItemCount DLC02WeapMinigun > 0)

 

if (player.GetItemCount Ammo5mm >= DLC02Max5mm )

 

;Do Nothing

elseif (player.GetItemCount Ammo5mm < DLC02Max5mm )

 

set hasAmmo to player.GetItemCount Ammo5mm

set giveAmmo to DLC02Max5mm - hasAmmo

player.AddItem Ammo5mm giveAmmo 1

set ammoAdded to 1

endif

 

endif

 

 

;--------Missile Launcher--------

; if (player.GetItemCount DLC02WeapMissileLauncher > 0)

;

; if (player.GetItemCount AmmoMissile >= MaxMissile )

;

; ;Do Nothing

; elseif (player.GetItemCount AmmoMissile < MaxMissile )

;

; set hasAmmo to player.GetItemCount AmmoMissile

; set giveAmmo to MaxMissile - hasAmmo

; player.AddItem AmmoMissile giveAmmo 1

; set ammoAdded to 1

; endif

;

; endif

 

 

;--------Sniper Rifle--------

if (player.GetItemCount DLC02WeapSniperRifle > 0)

 

if (player.GetItemCount Ammo308Caliber >= DLC02Max308Caliber )

 

;Do Nothing

elseif (player.GetItemCount Ammo308Caliber < DLC02Max308Caliber )

 

set hasAmmo to player.GetItemCount Ammo308Caliber

set giveAmmo to DLC02Max308Caliber - hasAmmo

player.AddItem Ammo308Caliber giveAmmo 1

set ammoAdded to 1

endif

 

endif

 

;--------Shotgun--------

if (player.GetItemCount DLC02WeapShotgunCombat > 0)

 

if (player.GetItemCount AmmoShotgunShell >= DLC02MaxShells )

 

;Do Nothing

elseif (player.GetItemCount AmmoShotgunShell < DLC02MaxShells )

 

set hasAmmo to player.GetItemCount AmmoShotgunShell

set giveAmmo to DLC02MaxShells - hasAmmo

player.AddItem AmmoShotgunShell giveAmmo 1

set ammoAdded to 1

endif

 

endif

 

if (ammoAdded == 1)

PlaySound3d FXObjectUse

ShowMessage DLC02AmmoRefill

activate

elseif (ammoAdded == 0)

PlaySound3d QSTToneSequenceFail

ShowMessage DLC02AmmoFull

activate

endif

 

pms DLC02DeRezItemShader

set timerToStopShader to 2

set flickering to 1

 

set switched to 1

endif

End

 

 

 

Begin GameMode

 

;-----Flickering Stuff----

if flickering == 1

if timerToStopShader > 0

set timerToStopShader to timerToStopShader - getSecondsPassed

else

sms DLC02DeRezItemShader

set flickering to -1

endif

 

endif

 

if myTimer < DLC02RezFlickerTime

set myTimer to myTimer + getSecondsPassed

 

if flickering == 0

if myTimer >= flickerOnSecond

playSound3D FXObjectHighlight

pms DLC02DeRezItemShader

set timerToStopShader to 2

set flickering to 1

endif

 

endif

 

elseif flickering != 1

set myTimer to 0

set flickering to 0

;pick a random second to start flickering next pass

set flickerOnSecond to GetRandomPercent * DLC02RezFlickerTime/100 + 1 ;example, if DLC02RezFlickerTime == 25, this rolls a die between 1 and 25

 

endif

 

 

End

Link to comment
Share on other sites

see the DLC02 in front of every weapon name? that means it checks for the Anchorage (cleaned sim version) of each weapon. change them to their regular versions. or use "or" ( || )

also the DLC02MAX****** are global variables, you should set those to specific numbers, or make your own globals and use those instead.

which you'll also need to set, otherwise they default to 0.

 


scn pieceofscript
short tempcount
short maxammo

begin onactivate
set maxammo to 100 ;should set somewhere else
if player.getitemcount ammo556mm >= maxammo
;do nothing
elseif (player.getitemcount weapAssaultrifle >= 1) || (player.getitemcount weapChineseAssaultrifle >= 1) ; check if the player has a weapon that uses the ammo type
  set tempcount to (maxammo - player.getitemcount ammo556mm)
  player.additem ammo556mm tempcount
endif
if player.getitemcount ammo10mm >= maxammo
;do nothing
elseif (player.getitemcount weap10mmpistol >= 1) || (player.getitemcount weap10mmpistolsilenced >= 1) || (player.getitemcount weap10mmsubmachinegun >= 1)
Set tempcount to (maxammo - player.getitemcount ammo10mm)
player.additem ammo10mm tempcount
endif

activate
playsound OBJswitchButtonA
end

 

do that for every type of ammo you want to stock

if you want it to flicker, you can write your own gamemode block too, its really not hard.

Edited by xab666
Link to comment
Share on other sites

It would be easier to make a completely new script for this IMO

Here's of what I think would be a good idea for what you're trying to do:

 

 

 

scriptname insert something adequate to your mod - like yourname,nameofmod,functionofscript

 

begin onactivate

if isactionref player == 1

if player.getitemcount weap10mmpistol > 0 && player.getitemcount ammo10mm <= 0

player.additem ammo10mm 50

endif

end

 

Everything this color can be replaced with any value/id you want (Get weapon IDs from the object list, ect, if you make the ammo check higher than 0 you should use <= for that)

 

 

 

You can then apply that script to any activator you want, including the one from Anchorage, just make sure to re-name it. You can also add in more blocks (eg. include more weapons) by repeating the part in italics and renaming the if to elseif.

Hope this was of any help.

Link to comment
Share on other sites

It would be easier to make a completely new script for this IMO

Here's of what I think would be a good idea for what you're trying to do:

 

 

 

scriptname insert something adequate to your mod - like yourname,nameofmod,functionofscript

 

begin onactivate

if isactionref player == 1

if player.getitemcount weap10mmpistol > 0 && player.getitemcount ammo10mm <= 0

player.additem ammo10mm 50

endif

end

 

Everything this color can be replaced with any value/id you want (Get weapon IDs from the object list, ect, if you make the ammo check higher than 0 you should use <= for that)

 

 

 

You can then apply that script to any activator you want, including the one from Anchorage, just make sure to re-name it. You can also add in more blocks (eg. include more weapons) by repeating the part in italics and renaming the if to elseif.

Hope this was of any help.

 

Computer programming 101.

 

IF < --- is the statement is true (or == 1) this will execute everything in the IF block.

DO THIS 1.

 

ELSEIF <-- if Conditions are failed for the IF block (And only if failed), do this IF another condition is met

DO THIS instead

 

ELSE <-- given that IF and ELSEIF failed, do this

DO THIS instead instead.

endif (end of conditional statement)

end (end of block)

 

proper format is a IF, ENDIF block for EACH.

I know this, because I've written the script your talking about.

elseif statements will work, if you use them in a condition block like i did.

 

that way the IF checks if you have MORE then the max ammo

if you DON"T then it checks if you have the applicable weapons

if not, it doesnt nothing

if you DO, it gives ammo = Maxammo - current ammount

 

then check with a differant if statement the next ammo

 

 

also could:

 

Check if has a weapon of given type

short tempnum
IF (player.getitemcount weapname >= 1) || (player.getitemcount weapname >= 1) || (player.getitemcount weapname >= 1) 
  if player.getitemcount AmmoName >= maxammo
   ;donothing
  elseif player.getitemcount ammoName < maxammo
    set tempnum to (Maxammo - player.getitemcount ammoname)
  endif
endif
;IF NEXT WEAPON STATEMENT

 

 

because mutiple weapons use the same ammo. (assualt rifle, chinese assualt rifle, infiltrator, perferator...), you should check for possession of any of them using || (or) conditions in the IF statement. you should check if the ammo is greater then or equal to max, and only execute if not (done using the IF/ELSEIF in second part). then end the statement and staart a new IF statement.

 

you start a NEW if statement because you actually want the script to check for every ammo type and do them all, not just the first one it succeeded with.

 

also note that math statements MUST BE MADE within delcarations...

 

you can't say

 

 player.additem caps001 (maxcaps - player.getitemcount caps001)

it will give you Maxcaps, and ignore the itemcount.

you have to use a temp variable, like tempcount. like i did in both my example scripts...

 

 set tempcount to (maxcaps - player.getitemcount caps001)
 player.additem tempcount

 

 

I agree with fakepersonality that this would be a easier script to re-write then just alter.

Link to comment
Share on other sites

It would be easier to make a completely new script for this IMO

Here's of what I think would be a good idea for what you're trying to do:

 

 

 

scriptname insert something adequate to your mod - like yourname,nameofmod,functionofscript

 

begin onactivate

if isactionref player == 1

if player.getitemcount weap10mmpistol > 0 && player.getitemcount ammo10mm <= 0

player.additem ammo10mm 50

endif

end

 

Everything this color can be replaced with any value/id you want (Get weapon IDs from the object list, ect, if you make the ammo check higher than 0 you should use <= for that)

 

 

 

You can then apply that script to any activator you want, including the one from Anchorage, just make sure to re-name it. You can also add in more blocks (eg. include more weapons) by repeating the part in italics and renaming the if to elseif.

Hope this was of any help.

 

Computer programming 101.

 

IF < --- is the statement is true (or == 1) this will execute everything in the IF block.

DO THIS 1.

 

ELSEIF <-- if Conditions are failed for the IF block (And only if failed), do this IF another condition is met

DO THIS instead

 

ELSE <-- given that IF and ELSEIF failed, do this

DO THIS instead instead.

endif (end of conditional statement)

end (end of block)

 

proper format is a IF, ENDIF block for EACH.

I know this, because I've written the script your talking about.

elseif statements will work, if you use them in a condition block like i did.

 

that way the IF checks if you have MORE then the max ammo

if you DON"T then it checks if you have the applicable weapons

if not, it doesnt nothing

if you DO, it gives ammo = Maxammo - current ammount

 

then check with a differant if statement the next ammo

 

 

also could:

 

Check if has a weapon of given type

short tempnum
IF (player.getitemcount weapname >= 1) || (player.getitemcount weapname >= 1) || (player.getitemcount weapname >= 1) 
  if player.getitemcount AmmoName >= maxammo
   ;donothing
  elseif player.getitemcount ammoName < maxammo
    set tempnum to (Maxammo - player.getitemcount ammoname)
  endif
endif
;IF NEXT WEAPON STATEMENT

 

 

because mutiple weapons use the same ammo. (assualt rifle, chinese assualt rifle, infiltrator, perferator...), you should check for possession of any of them using || (or) conditions in the IF statement. you should check if the ammo is greater then or equal to max, and only execute if not (done using the IF/ELSEIF in second part). then end the statement and staart a new IF statement.

 

you start a NEW if statement because you actually want the script to check for every ammo type and do them all, not just the first one it succeeded with.

 

also note that math statements MUST BE MADE within delcarations...

 

you can't say

 

 player.additem caps001 (maxcaps - player.getitemcount caps001)

it will give you Maxcaps, and ignore the itemcount.

you have to use a temp variable, like tempcount. like i did in both my example scripts...

 

 set tempcount to (maxcaps - player.getitemcount caps001)
 player.additem tempcount

 

 

I agree with fakepersonality that this would be a easier script to re-write then just alter.

 

Yeah, I meant that, thanks for correcting me - I suck at scripting when im not actually doing it :)

Link to comment
Share on other sites

It would be easier to make a completely new script for this IMO

Here's of what I think would be a good idea for what you're trying to do:

 

 

 

scriptname insert something adequate to your mod - like yourname,nameofmod,functionofscript

 

begin onactivate

if isactionref player == 1

if player.getitemcount weap10mmpistol > 0 && player.getitemcount ammo10mm <= 0

player.additem ammo10mm 50

endif

end

 

Everything this color can be replaced with any value/id you want (Get weapon IDs from the object list, ect, if you make the ammo check higher than 0 you should use <= for that)

 

 

 

You can then apply that script to any activator you want, including the one from Anchorage, just make sure to re-name it. You can also add in more blocks (eg. include more weapons) by repeating the part in italics and renaming the if to elseif.

Hope this was of any help.

 

Computer programming 101.

 

IF < --- is the statement is true (or == 1) this will execute everything in the IF block.

DO THIS 1.

 

ELSEIF <-- if Conditions are failed for the IF block (And only if failed), do this IF another condition is met

DO THIS instead

 

ELSE <-- given that IF and ELSEIF failed, do this

DO THIS instead instead.

endif (end of conditional statement)

end (end of block)

 

proper format is a IF, ENDIF block for EACH.

I know this, because I've written the script your talking about.

elseif statements will work, if you use them in a condition block like i did.

 

that way the IF checks if you have MORE then the max ammo

if you DON"T then it checks if you have the applicable weapons

if not, it doesnt nothing

if you DO, it gives ammo = Maxammo - current ammount

 

then check with a differant if statement the next ammo

 

 

also could:

 

Check if has a weapon of given type

short tempnum
IF (player.getitemcount weapname >= 1) || (player.getitemcount weapname >= 1) || (player.getitemcount weapname >= 1) 
  if player.getitemcount AmmoName >= maxammo
   ;donothing
  elseif player.getitemcount ammoName < maxammo
    set tempnum to (Maxammo - player.getitemcount ammoname)
  endif
endif
;IF NEXT WEAPON STATEMENT

 

 

because mutiple weapons use the same ammo. (assualt rifle, chinese assualt rifle, infiltrator, perferator...), you should check for possession of any of them using || (or) conditions in the IF statement. you should check if the ammo is greater then or equal to max, and only execute if not (done using the IF/ELSEIF in second part). then end the statement and staart a new IF statement.

 

you start a NEW if statement because you actually want the script to check for every ammo type and do them all, not just the first one it succeeded with.

 

also note that math statements MUST BE MADE within delcarations...

 

you can't say

 

 player.additem caps001 (maxcaps - player.getitemcount caps001)

it will give you Maxcaps, and ignore the itemcount.

you have to use a temp variable, like tempcount. like i did in both my example scripts...

 

 set tempcount to (maxcaps - player.getitemcount caps001)
 player.additem tempcount

 

 

I agree with fakepersonality that this would be a easier script to re-write then just alter.

 

Yeah, I meant that, thanks for correcting me - I suck at scripting when im not actually doing it :)

 

its all good, a script like this can be pretty daunting for somebody that fairly new to modding (the OP), mostly cause it can be long. (bethesda script is 280 lines)

i would suggest only making it give one type of ammo at first (for all the weapons of that type) and test it and tweak it until it works perfectly for that ammo

and then add the other types one by one. (or all at once if you found 1 easy). then you can just copy/paste the if/endif blocks and change the names of the weapons and the maxammo variables.

i'd avoid doing the flicker effect until last (it runs on a gamemode block anyways). once everything else works, add the flicker, see if that breaks what worked before (happens).

 

heres the 10mm section redone

       set max10mm to 150
if (player.GetItemCount Weap10mmPistol >0) || (player.GetItemCount Weap10mmPistolSilenced >0) || (player.GetItemCount Weap10mmSubmachineGun >0) || (player.GetItemCount WeapChinesePistol >0) || (player.GetItemCount WeapUniqueColAutumns10mmpistol >0)|| (player.GetItemCount WeapUniqueColAutumns10mmpistol >0) || (player.GetItemCount Weap10mmSubMachineGun >0) || (player.GetItemCount WeapUniqueZhuRongChinesePistol >0) || (player.GetItemCount WeapUniqueSydneys10mmSubGun >0)

		if (player.GetItemCount Ammo10mm >= Max10mm)

			;Do Nothing

		elseif (player.GetItemCount Ammo10mm <  Max10mm)
			set hasAmmo to player.GetItemCount Ammo10mm
			set giveAmmo to Max10mm - hasAmmo
			player.AddItem Ammo10mm giveAmmo 1
			set ammoAdded to 1
		endif

	endif

 

notice that there are 9 weapons in the IF or statements, to cover every regular version, and every unique version. of the regular weapons available in vanilla FO3.

hope that helps.

good luck

Link to comment
Share on other sites

Kudos bossman. 7 or 8 years ago I could have done this; wrote in JAVA for three years total. Since joining the military however, I have been out of the loop. Everything has passed me by, so finding a skeleton code, or a starter code to kickstart the 'ol memory does absolute wonders. I was actually looking for this (and however many other basic scripts and shells that can be edited) to add to an armory section of what I am working on at the moment.

 

This will help... a lot. Thank you.

 

EDIT: kudos when I get home. work computers block all but the overall nexus forums :/

Edited by amullinix
Link to comment
Share on other sites

Due to work and PC repair I do on the side, I play FO3 on weekends. But I have to admit, I wasn't expecting to get these great tips and examples so quickly.. And I definitely need a lesson in scripting. And I got it. In fact, it even helped amullinix on his path. So thanks FakePersonality and xab666. I'm very excited to get started.

 

I'm not too crazy for forums. Someone starts with a valid topic and before you know it, there are like 1000 replies about anything else but the topic. And the history of replies are always filled with pissing contests between people who know the subject, and others that think they know. And to make things worse, by the time you find the correct forum, you're so pissed from your own failed attempts, you give up. But I don't want to start a tangent. So that's the last off topic comment I'll make :)

 

I'll definitely start with one weapon and tweak it till it works. After that, the other weapons will be easy to do.

 

I've always had a problem with if commands, and nested loops. I understand what they do and how to use them in MS Excel, batch files, and HTML, but I have to admit, they've always confused me. It's easier to write your own than change an existing one. I start to track what they're doing, and just before I get it, suddenly all of it turns Chinese. And I don't speak Chinese. lol

 

I am surprised I couldn't find a mod on the ammo dispenser. But I read somewhere that many mods are disappearing because more complex mods are replacing them.

 

Please, feel free to continue on topic with more suggestions and samples. I'll reply with my attempts, successes, and failures, this weekend.

 

Thanks again.

 

MrLostsoul.

Link to comment
Share on other sites

  • 2 weeks later...

Slight necro bump here, but I feel the need to ask this: Can someone versed in properly representing the script, and in wiki page creation, place these on the Nexus Wiki? I'm at work at the moment, and will be here for quite a few hours. If no one is available that is willing to do it, I will most likely try later on (probably within the next couple of days) but this really should be in there since there are a lot of mods that use sorters.

 

If this is already on the wiki (can't check it: it's blocked) please disregard this request.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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