Trouble with a script to set up a camp

Post » Sat Dec 29, 2012 8:03 pm

Hello everyone,

I'm struggling with a very simple script to set up a fireplace. I intended the script to run once the player activates a cold fireplace. If the player has the item "Camping-Kit" in the inventory, he gets a message-box, asking him whether he wants to set up a camp here. It all works well to the point where the camp is set up and the "Abandon"-Messagebox should show up. Nothing happens, even the Debug.MessageBox doesn't appear - I'm absolutely clueless why. I wanted to use a Global so that companions can respond to the camp as well. My guess is that the problem isn't the global, however.

I'd appreciate every bit of help! I'm sorry for the horrible formatting, I'm not much of a coder myself, but there was no way around it. :wink:

Scriptname _00E_CampingScript extends ObjectReference
{This script is intended to be placed on the fireplace
which serves as the activator to set up and abandon
a camp.}

Event OnActivate(ObjectReference akActionRef)

float Camping = CampingGlobal.Getvalue()
int CampingInt


if Camping == 0
if (Game.GetPlayer().GetItemCount(Camp) == 0)
Debug.MessageBox("Euch fehlt die Ausrüstung, um hier ein Lager aufzuschlagen.")

elseif (Game.GetPlayer().GetItemCount(Camp) &--#62;= 1)
if Camping == 0

int ibutton = Messagebox.Show() ; Displays the "Set Up-Camp" Message Box

if ibutton == 0
Game.GetPlayer().RemoveItem(Camp, 1)
Fade.Apply(1)
UnpackCamp.play(self)
Utility.Wait(5.3)
CampingGlobal.Setvalue(1)
CampingInt = 1
Tent.Enable()
Bedroll.Enable()
Spit.Enable()
Pot.Enable()
Chest.Enable()
Fire.Enable()
FlameCrackle.Enable()

elseif ibutton == 1
return

if Camping == 1
Debug.MessageBox("Da isse!")

int abutton = MessageBoxAbandon.Show() ; Displays the "Abandon-Camp" Message-Box

if abutton == 0 ;If the player hits "Abandon-Camp", everything will be disabled and the Global is reset to 0
Game.GetPlayer().AddItem(Camp, 1)
Fade.Apply(1)
Utility.Wait(5.3)
UnpackCamp.play(self)
CampingGlobal.Setvalue(0)
CampingInt = 0
Tent.Disable()
Bedroll.Disable()
Spit.Disable()
Pot.Disable()
Chest.Disable()
Fire.Disable()
FlameCrackle.Disable()


elseif abutton == 1
return



endif
endif
endif
endif
endif
endif

EndEvent

MiscObject Property Camp Auto

ObjectReference Property Tent Auto

ObjectReference Property Bedroll Auto

ObjectReference Property Spit Auto

ObjectReference Property Pot Auto

ObjectReference Property Chest Auto

ObjectReference Property Fire Auto

ImageSpaceModifier Property Fade Auto

ImageSpaceModifier Property FadeBack Auto

Sound Property UnpackCamp Auto

ObjectReference Property FlameCrackle Auto

Message Property MessageBox Auto

Message Property MessageBoxAbandon Auto

GlobalVariable Property CampingGlobal Auto
User avatar
Liv Staff
 
Posts: 3473
Joined: Wed Oct 25, 2006 10:51 pm

Post » Sat Dec 29, 2012 4:25 pm

Have you tried replacing the float (Camping) with a more direct GetValue() function on the global? Maybe the float value isn't getting updated whenever the Global is changed for whatever reason.

So basically, instead of:

float Camping = CampingGlobal.Getvalue()if Camping == 1;Do stuffendif

I would try:

if CampingGlobal.GetValue() == 1;Do stuffendif
User avatar
Marcus Jordan
 
Posts: 3474
Joined: Fri Jun 29, 2007 1:16 am

Post » Sat Dec 29, 2012 5:01 am

Try:
Spoiler
Scriptname _00E_CampingScript extends ObjectReference{This script is intended to be placed on the fireplace which serves as the activator to set up and abandon a camp.}Actor Property PlayerREF AutoGlobalVariable Property CampingGlobal AutoImageSpaceModifier Property Fade AutoImageSpaceModifier Property FadeBack AutoMessage[] Property kMessageArray Auto ; 0 = MessageBox, 1 = MessageBoxAbandonMiscObject Property Camp AutoObjectReference[] Property kCampArray Auto ; Order does not matterSound Property UnpackCamp AutoEvent OnActivate(ObjectReference akActionRef)	Int iButton = kMessageArray[CampingGlobal.GetValue() As Int].Show()	If iButton		Return	Else		CampingGlobal.SetValue((!CampingGlobal.GetValue() As Bool) As Int)			SetUpCamp(CampingGlobal.GetValue() As Bool)	EndIfEndEventFunction SetUpCamp(Bool abCamping)	Fade.Apply(1.0)	Int iInstanceID = UnpackCamp.Play(Self)	Sound.SetInstanceVolume(iInstanceID, 1.0)	UnpackCamp.Play(Self)	Int iIndex = kCampArray.Length	Utility.Wait(5.3)	If abCamping		Debug.MessageBox("Da isse!")		PlayerREF.RemoveItem(Camp)		While iIndex > 0			iIndex -= 1			kCampArray[iIndex].Enable()		EndWhile	Else		PlayerREF.AddItem(Camp)		While iIndex > 0			iIndex -= 1			kCampArray[iIndex].Disable()		EndWhile	EndIf	FadeBack.Apply(1.0)EndFunction
Also, you'll find indenting your scripts is invaluable and please post scripts in [Spoiler][Code]legible code here[/Code][/Spoiler].
User avatar
flora
 
Posts: 3479
Joined: Fri Jun 23, 2006 1:48 am

Post » Sat Dec 29, 2012 5:41 am

Hi,

Wow, thanks for your quick help. Your script works perfectly fine, JustinOthers, however, it is not dependant on whether the player owns a camping kit or not - How can I add that? To be quite honest, I'd try to add it myself since it is probably just a line, but I have to admit that I don't understand all of your script - 'm a complete novice at scripting, as you can see. :wink: However, I indented the script, the formatting just wasn't pasted here. I'll post them in spoilers in the future!

All the best,
Latiro
User avatar
Batricia Alele
 
Posts: 3360
Joined: Mon Jan 22, 2007 8:12 am

Post » Sat Dec 29, 2012 3:12 pm

But that's why the abandon message never showed. Try:
Spoiler
ScriptName _00E_CampingScript Extends ObjectReferenceActor Property PlayerREF AutoBool Property bIsCampSetUp AutoImageSpaceModifier Property Fade AutoImageSpaceModifier Property FadeBack AutoMessage[] Property kMessageArray AutoMiscObject Property Camp AutoObjectReference[] Property kCampArray AutoSound Property UnpackCamp AutoEvent OnActivate(ObjectReference akActionRef)	If bIsCampSetUp || PlayerREF.GetItemCount(Camp)		Int iButton = kMessageArray[bIsCampSetUp As Int].Show()		If !iButton			bIsCampSetUp = !bIsCampSetUp				SetUpCamp(bIsCampSetUp)		EndIf	EndIfEndEventFunction SetUpCamp(Bool abCamping)	Fade.Apply(1.0)	Int iInstanceID = UnpackCamp.Play(Self)	Sound.SetInstanceVolume(iInstanceID, 1.0)	UnpackCamp.Play(Self)	Int iIndex = kCampArray.Length	Utility.Wait(5.3)	If abCamping		PlayerREF.RemoveItem(Camp)		While iIndex > 0			iIndex -= 1			kCampArray[iIndex].Enable()		EndWhile	Else		PlayerREF.AddItem(Camp)		While iIndex > 0			iIndex -= 1			kCampArray[iIndex].Disable()		EndWhile	EndIf	FadeBack.Apply(1.0)EndFunction
You can shed the GLOB.
User avatar
maddison
 
Posts: 3498
Joined: Sat Mar 10, 2007 9:22 pm

Post » Sat Dec 29, 2012 9:15 am

Once again, thanks for your quick help. :)

Now I understand why the abandon-box didn't show up! This version works great! Is there any way to set the global to 1, however? I need it in order to set a condition for NSC-Packages. Also, where should I place the Debug.Messagebox that appears when the player doesn't have a camp at all?
User avatar
Eric Hayes
 
Posts: 3392
Joined: Mon Oct 29, 2007 1:57 am

Post » Sat Dec 29, 2012 5:09 pm

To set a global variable, use:

MyGlobal.SetValue(#)

Replace MyGlobal with property name of your global, and # with the number you want to set it to.
User avatar
Richard Dixon
 
Posts: 3461
Joined: Thu Jun 07, 2007 1:29 pm

Post » Sat Dec 29, 2012 11:56 am

Once again, thanks for your quick help. :)
No prob :)
Now I understand why the abandon-box didn't show up! This version works great! Is there any way to set the global to 1, however? I need it in order to set a condition for NSC-Packages. Also, where should I place the Debug.Messagebox that appears when the player doesn't have a camp at all?
You still won't need the global. Just make the script and bIsCampSetUp property Conditional, then use GetVMScriptVariable in the AI Packages' condition dropdown boxes after pointing to the scripted campfire:
Spoiler
ScriptName _00E_CampingScript Extends ObjectReference ConditionalActor Property PlayerREF AutoBool Property bIsCampSetUp Auto ConditionalImageSpaceModifier Property Fade AutoImageSpaceModifier Property FadeBack AutoMessage[] Property kMessageArray AutoMiscObject Property Camp AutoObjectReference[] Property kCampArray AutoSound Property UnpackCamp AutoEvent OnActivate(ObjectReference akActionRef)	If bIsCampSetUp || PlayerREF.GetItemCount(Camp)		Int iButton = kMessageArray[bIsCampSetUp As Int].Show()		If !iButton			bIsCampSetUp = !bIsCampSetUp				SetUpCamp(bIsCampSetUp)		EndIf	Else		Debug.MessageBox("Euch fehlt die Ausrüstung, um hier ein Lager aufzuschlagen.")	EndIfEndEventFunction SetUpCamp(Bool abCamping)	Fade.Apply(1.0)	Int iInstanceID = UnpackCamp.Play(Self)	Sound.SetInstanceVolume(iInstanceID, 1.0)	UnpackCamp.Play(Self)	Int iIndex = kCampArray.Length	Utility.Wait(5.3)	If abCamping		Debug.MessageBox("Da isse!")		PlayerREF.RemoveItem(Camp)		While iIndex > 0			iIndex -= 1			kCampArray[iIndex].Enable()		EndWhile	Else		PlayerREF.AddItem(Camp)		While iIndex > 0			iIndex -= 1			kCampArray[iIndex].Disable()		EndWhile	EndIf	FadeBack.Apply(1.0)EndFunction
That should do it all.
User avatar
ladyflames
 
Posts: 3355
Joined: Sat Nov 25, 2006 9:45 am


Return to V - Skyrim