Scripting Help Requested

Post » Tue May 17, 2011 12:23 pm

I'm trying to make the chance of a Nuka-Cola Quantum spawning in a vending machine depend on the player's luck attribute. However, I have never modded Fallout 3 or Oblivion before so I'm in need of some assistance. I went into the G.E.C.K. and made a script using information I could find from tutorials and such and I'm wondering if someone could take a look at it and tell me why it isn't working:

scn DecQuantumChanceScriptref NukaContainershort SpawnChanceshort PlayerLuckbegin OnOpen	set NukaContainer to GetParentRef	if IsActionRef player		set PlayerLuck to player.GetAv Luck		if PlayerLuck == 1			set SpawnChance to 0		elseif PlayerLuck == 2			set SpawnChance to 5		elseif PlayerLuck == 3			set SpawnChance to 10		elseif PlayerLuck == 4			set SpawnChance to 15		elseif PlayerLuck == 5			set SpawnChance to 20		elseif PlayerLuck == 6			set SpawnChance to 30		elseif PlayerLuck == 7			set SpawnChance to 45		elseif PlayerLuck == 8			set SpawnChance to 65		elseif PlayerLuck == 9			set SpawnChance to 90		elseif PlayerLuck == 10			set SpawnChance to 95		endif	endif	if GetRandomPercent <= SpawnChance		NukaContainer.AddItem MS05NukaColaQtm 1	endifend


In the Object Window, I went World Objects > Container > Clutter > VendingMachine and then double-clicked NukaVendingMachine. I removed the "ClutterNukaColaQuantum10" from the Item List and attached the above script to the container so that each time the player opens an unopenedNuka-Cola vending machine, the script will trigger and calculate the spawn probability for a Quantum and spawn it if the random calculated probability is less than or equal to the ghost variable "SpawnChance" which depends on the player's luck attribute.

Also, as written in italics, I want the script to run only on unopened vending machines to emulate vanilla behavior where the vending machines never respawn.

Thanks in advance. :)
User avatar
Beat freak
 
Posts: 3403
Joined: Thu Dec 14, 2006 6:04 am

Post » Tue May 17, 2011 9:33 am

ScriptName DecQuantumChanceScriptRef	rNukaContainerInt	iSpawnChanceInt	iPlayerLuckInt	bOpenedBegin OnOpen	Set rNukaContainer to GetParentRef	If (IsActionRef Player && IsOpened == 0)		Set iPlayerLuck to Player.GetAV Luck		If (PlayerLuck == 1)			Set SpawnChance to 0		ElseIf (PlayerLuck == 1)			Set SpawnChance to 5		ElseIf (PlayerLuck == 2)			Set SpawnChance to 10		ElseIf (PlayerLuck == 3)			Set SpawnChance to 15		ElseIf (PlayerLuck == 4)			Set SpawnChance to 20		ElseIf (PlayerLuck == 5)			Set SpawnChance to 30		ElseIf (PlayerLuck == 6)			Set SpawnChance to 45		ElseIf (PlayerLuck == 7)			Set SpawnChance to 65		ElseIf (PlayerLuck == 8)			Set SpawnChance to 90		ElseIf (PlayerLuck == 9)			Set SpawnChance to 95		EndIf		Set bOpened to 1	EndIf	If (GetRandomPercent <= SpawnChance)		NukaContainer.AddItem MS05NukaColaQtm 1	EndIfEnd


Look at the "bOpened" variable, it's kind of self explanatory. :)
"If (IsActionRef Player && IsOpened == 0)" checks if the ActionRef is the player AND "IsOpened" equals 0. If it doesn't equal 0, run the script.
At the end of the script, "Set bOpened to 1" is ran. Therefore, "IsOpened" doesn't equal 0 and "If (IsActionRef Player && IsOpened == 0)" will never evaluate true again.
Good luck!
User avatar
Samantha Mitchell
 
Posts: 3459
Joined: Mon Nov 13, 2006 8:33 pm

Post » Tue May 17, 2011 5:30 am

Look at the "bOpened" variable, it's kind of self explanatory. :)
"If (IsActionRef Player && IsOpened == 0)" checks if the ActionRef is the player AND "IsOpened" equals 0. If it doesn't equal 0, run the script.
At the end of the script, "Set bOpened to 1" is ran. Therefore, "IsOpened" doesn't equal 0 and "If (IsActionRef Player && IsOpened == 0)" will never evaluate true again.
Good luck!

Hi, thanks for replying. I tried a modified code but it isn't working; no Quantums are being spawned in vending machines. I'm testing this with a character with Luck at 10 at a location where I teleport to using the console and where I've never been before with this character (so the cell -- and therefore also the contents of the vending machine -- are loaded afresh every time I test). Your code had some inconsistencies so I modified it a bit, but like I said; it doesn't work.

ScriptName DecQuantumChanceScriptRef	NukaContainerInt	SpawnChanceInt	PlayerLuckInt	OpenedOnceBegin OnOpen	If (IsActionRef Player && OpenedOnce == 0)		Set PlayerLuck to (Player.GetAV Luck)		If (PlayerLuck == 1)			Set SpawnChance to 0		Elseif (PlayerLuck == 2)			Set SpawnChance to 5		Elseif (PlayerLuck == 3)			Set SpawnChance to 10		Elseif (PlayerLuck == 4)			Set SpawnChance to 15		Elseif (PlayerLuck == 5)			Set SpawnChance to 20		Elseif (PlayerLuck == 6)			Set SpawnChance to 30		Elseif (PlayerLuck == 7)			Set SpawnChance to 45		Elseif (PlayerLuck == 8)			Set SpawnChance to 65		Elseif (PlayerLuck == 9)			Set SpawnChance to 90		Elseif (PlayerLuck == 10)			Set SpawnChance to 95		Endif		Set OpenedOnce to 1		If (GetRandomPercent <= SpawnChance)			Set NukaContainer to GetParentRef			NukaContainer.AddItem MS05NukaColaQtm 1		Endif	EndifEnd

User avatar
Emily Martell
 
Posts: 3469
Joined: Sun Dec 03, 2006 7:41 am

Post » Tue May 17, 2011 5:58 am

ScriptName DecQuantumChanceScriptRef	NukaContainerInt	SpawnChanceInt	PlayerLuckInt	OpenedOnceBegin OnActivate	If (IsActionRef Player && OpenedOnce == 0)		Set PlayerLuck to (Player.GetAV Luck)		If (PlayerLuck == 1)			Set SpawnChance to 0		Elseif (PlayerLuck == 2)			Set SpawnChance to 5		Elseif (PlayerLuck == 3)			Set SpawnChance to 10		Elseif (PlayerLuck == 4)			Set SpawnChance to 15		Elseif (PlayerLuck == 5)			Set SpawnChance to 20		Elseif (PlayerLuck == 6)			Set SpawnChance to 30		Elseif (PlayerLuck == 7)			Set SpawnChance to 45		Elseif (PlayerLuck == 8)			Set SpawnChance to 65		Elseif (PlayerLuck == 9)			Set SpawnChance to 90		Elseif (PlayerLuck == 10)			Set SpawnChance to 95		Endif		Set OpenedOnce to 1		If (GetRandomPercent <= SpawnChance)			Set NukaContainer to GetParentRef			NukaContainer.AddItem MS05NukaColaQtm 1		Endif	Endif	ActivateEnd

User avatar
El Khatiri
 
Posts: 3568
Joined: Sat Sep 01, 2007 2:43 am

Post » Tue May 17, 2011 8:22 am

code


That was awesome, man. Thank you, it worked a treat! I used the OnActivate thingy in my very first code but I wasn't even able to open up the vending machine with that; I couldn't interact with it at all. I guess I was missing the "Activate" at the end.. Anyway, a big thanks to you!
User avatar
Logan Greenwood
 
Posts: 3416
Joined: Mon Jul 30, 2007 5:41 pm


Return to Fallout 3