Jump to content

Help with a script please


Job4aCowboy

Recommended Posts

Hey, I trying to write a script that allows players to dig up graves.

 

In the creation kit I have created a Burial Cairn Activator, this activator is Link Ref'd to a chest. When the player activates the Burial cairn the scripts checks to see if the player has a shovel in their inventory. If they don't a message appears telling them they need a shovel, if they do the chest activates.

I have done it this way so I can have one Activator but different chest inventories, this way I can change the inventory based on what I need it for.

 

I reverse engineered the "Mineorescript" and "activatelinkedchsetdummyscript"

 

Here is the scripts so far...

 

Scriptname SEEGraveRobbersScript extends ObjectReference
{Script attached to GraveActivator, checks to see if player has required items...}


formlist property SEEFORMLISTGravetools auto
{Player must have at least one item from this formlist to interact}
Message Property SEEMESSAGEGraverobfailure Auto  
{Message to say why you can't use this without RequiredWeapon}
Keyword Property linkedRefKeyword Auto
{Chest that is linked to Grave Activator}

Auto State Waiting
	event onActivate(objectReference akactivator)

		if akActivator as actor
		;if the actor is the player
			if akActivator == game.getPlayer()
			;if the player has the right item
				if playerHasTools() == false
				SEEMESSAGEGraverobfailure.Show()
				else
				gotostate("Activated")
			endif
		EndIf
	EndEVENT
EndState

State Activated
	EVENT onActivate(objectReference actronaut)
	; 	debug.trace("Sending "+getLInkedRef()+" an activate from "+actronaut)
		getLinkedRef(LinkedRefKeyword).activate(actronaut)
		gotostate("Waiting")
	endEVENT
endstate


bool function playerHasTools()
	if Game.GetPlayer().GetItemCount(SEEFORMLISTGravetools) > 0
; 		debug.Trace(self + ": playerHasTools is returning true")
		return true
	Else
; 		debug.Trace(self + ": playerHasTools is returning false")
		return false
	endIf
endFunction 

 

The script compiles OK, but in game it doesn't function as expected. The check for the shovel works, and you can only activate it with a shovel The problem is you have to activate it twice to bring up the chest's inventory.

I know this is because the second state "activated" begins with "event onactivate". I just don't know what to use instead, so that the chest opens up straight away. I have tried onbeginstate but it doesn't compile, saying that "actronaut" isn't defined or something like that.

 

If anyone can help that'd be appreciated.

 

Thanks

 

 

 

Job4aCowboy

Link to comment
Share on other sites

Only a couple things I noticed that stood out. Don't know if they are the cause of the problem; your checking if the activator is an actor then checking if the actor is the player. I just removed the actor check, and went straight to checking if the activator is the player.

 

That, and your function is at the bottom of your script. Don't know if that makes any difference, but I've always put functions before anything that would use them. I've been using that style as I've seen various scripts following that style.

 

May have put an extra 'endif' at the waiting state. Just remove one if the compiler throws up errors.

 

Scriptname SEEGraveRobbersScript extends ObjectReference
{Script attached to GraveActivator, checks to see if player has required items...}


formlist property SEEFORMLISTGravetools auto
{Player must have at least one item from this formlist to interact}

Message Property SEEMESSAGEGraverobfailure Auto  
{Message to say why you can't use this without RequiredWeapon}

Keyword Property linkedRefKeyword Auto
{Chest that is linked to Grave Activator}



bool function playerHasTools()

	if Game.GetPlayer().GetItemCount(SEEFORMLISTGravetools) > 0

; 		debug.Trace(self + ": playerHasTools is returning true")

		return true

	Else

; 		debug.Trace(self + ": playerHasTools is returning false")

		return false

	endIf

endFunction 



Auto State Waiting

	event onActivate(objectReference akActivator)


		if akActivator == game.getPlayer()

		;if the player has the right item

			if playerHasTools() == false

				SEEMESSAGEGraverobfailure.Show()

			else

				gotostate("Activated")

			endif

		Endif

	EndEVENT

EndState


State Activated

	EVENT onActivate(objectReference actronaut)

	; 	debug.trace("Sending "+getLInkedRef()+" an activate from "+actronaut)

		getLinkedRef(LinkedRefKeyword).activate(actronaut)

		gotostate("Waiting")

	endEVENT

endstate



Link to comment
Share on other sites

Thanks for the reply, it compiles OK and everything. But I still have the same problem.

 

When I activate is for the first time, it checks to see if i have the shovel. If I don't it shows the message. This is what I expect.

If however I do have the shovel, it does nothing, until I activate the grave again, then it shows the chest inventory. This is not what I want, I want it to open the inventory up straight away if the player has the required items.

 

I know what the problem is, its because of the two states. When "waiting" has finished it starts "activated". When the script is in the state "activated" its still waiting for an activate because of the "event onactivate"

 

I tried "event onstatebegin" but it doesn't compile as I'm not defining what actronaut is. and "event onstatebegin(objectreference actronaut)" doesn't work.

 

Hope this is understandable. It's confusing me lol :biggrin:

Link to comment
Share on other sites

It's "Event OnBeginState()"

 

Yeh, thats what I meant, it doesn't work.

 

"Event OnBeginState(objectreference actronaut)"

Failed to compile...

"object reference not set to an instance of an object"

 

"Event OnBeginState()"

Failed to compile...

"Variable actronaut is undefined"

Link to comment
Share on other sites

Well, what is this actronaut that you speak of? Don't see any properties of it in your script or anything.

its just what i pulled from the "activatelinkedchestdummyscript"...

Scriptname ActivateLinkedChestDummyScript extends ObjectReference  
 
EVENT onActivate(objectReference actronaut)
;  debug.trace("Sending "+getLInkedRef()+" an activate from "+actronaut)
getLinkedRef().activate(actronaut)
endEVENT

Basically you can activate something else, and it opens up the chest that's link ref'd to it.

Edited by Job4aCowboy
Link to comment
Share on other sites

Per fifty's note, I think you need to look back at where you got that example script and figure out what actronaut is supposed to be. Then, you need to declare that property and link it up in the CK.

 

Also, I would not use states for this. I think you can do everything you need just using the onactivate event.

 

I'm sorry, I would edit your script to give a better idea what I mean, but I'm on a qwerty keyboard right now.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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