Jump to content

Recommended Posts

Posted

Hello!

 

I need help with making a OnTriggerEnter script that will remove the players Weapons into a linked reference container.

 

Or alternatively, a script where the player can not use any weapons while being in said trigger box.

 

I'm not very good at making scripts myself so any and all help is appreciated!

Posted

Attach this script to your triggerbox object reference.

Scriptname YOURSCRIPTNAME extends ObjectReference Const

Keyword Property ObjectTypeWeapon Auto Const
{Every weapon should have this keyword.}
ObjectReference Property myWeaponContainer Auto Const
{Your weapon container.}


Event OnTriggerEnter(ObjectReference akActionRef)
	If akActionRef == Game.GetPlayer()
		RemoveWeapons()
	EndIf
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
	If akActionRef == Game.GetPlayer()
		AddWeapons()
	EndIf
EndEvent


Function RemoveWeapons()
	Actor PlayerRef = Game.GetPlayer()
	Int iWaponCount = PlayerRef.GetItemCount(ObjectTypeWeapon)
	If iWaponCount > 0
		PlayerRef.RemoveItem(ObjectTypeWeapon, iWaponCount, abSilent = true, akOtherContainer = myWeaponContainer)
	EndIf
EndFunction

Function AddWeapons()
	Actor PlayerRef = Game.GetPlayer()
	Int iWaponCount = myWeaponContainer.GetItemCount(ObjectTypeWeapon)
	If iWaponCount > 0
		myWeaponContainer.RemoveItem(ObjectTypeWeapon, iWaponCount, abSilent = true, akOtherContainer = PlayerRef)
	EndIf
EndFunction
Posted

Also make sure the target container is persistent or it will unload along with the items. The keyword "MustPersist" does help

  • Recently Browsing   0 members

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