Jump to content

How to: An activator that only works when you have a certain item


Zorkaz

Recommended Posts

Dear scripting gods, help me!

 

How am I able to make an activator that only works when you have a certain item in your possession?

 

 

Example:

-A water pump that starts working when you fix it with a certain screw

-An old generator that needs a battery

 

 

 

Optionally: The activator vanishes and gets replaced by a working one

Link to comment
Share on other sites

It compiles, but didn't test in game myself. Please try it out:

Scriptname Zorkaz_RequireItemToFix extends ObjectReference

; scripting by niston

Form Property ItemRequired Auto Const
{ Item required for fixing }

Bool Property ConsumeItem Auto Const
{ Consume the item when fixing? }

Auto State Broken
	Event OnInit()
		; block default activation
		BlockActivation(true)
                ; disable power on powered things
                SetOpen(true)
	EndEvent

	Event OnActivate(ObjectReference refAction)
		ObjectReference refPlayer = Game.GetPlayer()
		If (refAction == refPlayer)
			If (refPlayer.GetItemCount(ItemRequired) > 0)
				If (ConsumeItem)
					; consume item
					refPlayer.RemoveItem(ItemRequired)
				EndIf
				; enable default activation
				BlockActivation(false)
                                ; enable power on powered things
                                SetOpen(false)
				; go to fixed state
				GotoState("Fixed")
                        Else
                                ; might show a message here, informing the user they need <ItemRequired> to fix this activator before it will work
			EndIf
		EndIf
	EndEvent
EndState

State Fixed

EndState
Link to comment
Share on other sites

Here is my nearly finished version:

 

It now has the option

-To play a sound,

-To shake the camera,

-To choose how many items you need

-To display a message before and after

 

Only problem: The item doesn't get removed

 

 

Scriptname AWPPressButtonScriptNew extends ObjectReference

; scripting by niston
; and the dumb 1% by zorkaz or ElHa :P

MiscObject Property ItemRequired Auto Const
{ Item required for activation }

Bool Property ConsumeItem Auto Const
{ Consume the item when fixing? }


Bool Property ShakeCamera Auto Const
{Shake the Camera}


Message Property TheMessagetodisplayafter Auto Const
{Which message after the object is fixed}
Message Property Themessagetodisplaybefore Auto Const
{The message before the object is fixed}
ObjectReference Property AWPEnabletheObject Auto
{Actually disables the xmarker}
ObjectReference Property AWPDisabletheObject Auto
{Obsolete, don't use}
Int Property AWPItemCount Auto Const
{How many items will be needed}
Sound Property TheSound Auto Const
{Which sound gets played}



Auto State Broken
Event OnInit()
; block default activation
BlockActivation(true)
EndEvent

Event OnActivate(ObjectReference refAction)
ObjectReference refPlayer = Game.GetPlayer()
If (refAction == refPlayer)
If (refPlayer.GetItemCount(ItemRequired) > AWPItemCount)
TheSound.PlayAndWait(self)
Game.ShakeCamera(Game.GetPlayer(), 0.5, 1)
Game.ShakeController(0.5, 0.5, 1)
TheMessagetodisplayafter.Show()

AWPEnabletheObject.Disable()




If (AWPEnabletheObject.IsEnabled())
AWPEnabletheObject.Disable()


If (ShakeCamera)
; ShakeCamera
Game.ShakeCamera(Game.GetPlayer(), 0.5, 1)
Game.ShakeController(0.5, 0.5, 1)

EndIf

If (ConsumeItem)
; consume item
refPlayer.RemoveItem(ItemRequired)
refPlayer.RemoveItem(ItemRequired)




EndIf



EndIf

Else
Themessagetodisplaybefore.Show()
AWPEnabletheObject.Enable()
AWPDisabletheObject.Disable()

; enable default activation
BlockActivation(false)
; go to fixed state
GotoState("Fixed")
EndIf
EndIf
EndEvent
EndState

State Fixed

EndState

Link to comment
Share on other sites

  • Recently Browsing   0 members

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