Script to check for an item, needs some help.

Post » Sat Feb 19, 2011 6:51 am

Good evening Oblivion Community,

I am a new user to the CS, and have only been tinkering with it for a few days, started out designing my first dungeon and after finishing that project started messing with scripting objects. With a few programming courses from college under my belt, oblivion scripting still befuddles me a bit however I did manage to make a few successful scripts for my needs during dungeon creation. However my current endeavor is turning up a little sour.

What I am trying to do is make a script for a locked gate to check for the existence of a key in the players inventory (I know by default it does this, but I want to remove the key upon gate activation which is why I am trying to script it into the gate itself). I got the script to work for unlocking, removing the key and opening/closing the gate after, however it runs regardless of the keys existence so I need to check for the key. After doing some searching I tried the HasVariable (It sounded like what I was looking for) but could never get it to work.

Here is what I have so far:
scn TestWorkspaceKeyRemoveSCRIPTshort DoOnceref mySelfbegin OnActivate	if DoOnce == 0		if player.HasVariable 01001216 == 1			myself.unlock			myself.activate			player.RemoveItem 01001216 1			set DoOnce to 1		else			message "This gate requires a key."		endif			else		myself.activate		return	endifend


I know I am probably doing it wrong, but I have tried calling for HasVariable in many different ways. FormID, RefID, String, etc. Nothing has worked so far, HasVariable has never returned a 1 and the wiki entry for HasVariable is a little vague (to me anyway, being new to the CS) as far as proper syntax is concerned. My only indication that tells me I am on the right track is the fact that the CS Script Editor doesn't pop up with an error when I save the script for testing. If there is some other function that would be better for what I am trying to do, or if I need to use a different begin sequence to check for the key(GameMode, MenuMode, etc) I haven't a clue.

Many thanks to anyone who can shed some light on what I am doing wrong here.
User avatar
Rowena
 
Posts: 3471
Joined: Sun Nov 05, 2006 11:40 am

Post » Sat Feb 19, 2011 4:32 am

Ok it looks to me your trying to use a triggeronce type script on a door when you don't need to.

If i'm understanding you correctly, you need a script more akin to this:

scn AADoorScriptbegin OnActivate ("fire this when door used")if (player.GetItemCount AADoorKey == 1)    Unlock    player.RemoveItem AADoorKey 1   Activateendifend


That's at its very basic to work but you'll need to add additional conditions to test for is door already unlocked then just 'activate' otherwise once youve used the door the first time with the key, due to the nature of that if statement it won't open again because its looking for the key so you'll need 'elseif'' as well but hope thats pointed you in the right direction!



EDIT: I DO APOLOGISE! lol sorry, obviously not woken up fully yet. I'm so used to 'triggeronce' scripts using shorts and ref's. As you can see I don't tend to. Ok, your on the right track, i'll just tweak mine into yours.

scn TestWorkspaceKeyRemoveSCRIPTshort DoOnceref mySelfbegin OnActivate        if DoOnce == 0                if player.GetItemCount AADoorKey == 1 ("I would advocate GetItemCount")                        unlock ("Dont really need 'myself.'  it will run on the calling object anyway")                        player.RemoveItem AADoorKey 1                        set DoOnce to 1                        Activate ("For security, I would activate the door last cos its going to load a new cell when you do")                else                        message "This gate requires a key."                endif                        else                activate                return        endifend


That SHOULD work, i think your main issue was the HasVariable....to chekc for items in your inventory use 'player.GetItemCount [ObjectID]'
User avatar
Natalie J Webster
 
Posts: 3488
Joined: Tue Jul 25, 2006 1:35 pm

Post » Sat Feb 19, 2011 9:20 am

Awesome, that works exactly like I was looking for.

I didn't know that unlock and activate could be used without referencing the gate. But that would make sense, since it is the gate running the script so its used on itself by default.

Thanks very much :celebration: , I have big plans for this type of script in creating a dungeon more akin to Zelda-esque exploration.
User avatar
Mackenzie
 
Posts: 3404
Joined: Tue Jan 23, 2007 9:18 pm

Post » Sat Feb 19, 2011 10:20 am

Oh, one more question.

I am planning on using a script like this in a resettable dungeon.

I currently have

begin OnReset	set DoOnce to 0end


at the end of my code, but my question is do I need to relock the gate on reset or do gates just automatically do that on cell reset?
User avatar
Prohibited
 
Posts: 3293
Joined: Tue Jun 12, 2007 6:13 am

Post » Sat Feb 19, 2011 4:55 am

I think doors, chests, whathaveyou, re-lock when the cell respawns.
User avatar
He got the
 
Posts: 3399
Joined: Sat Nov 17, 2007 12:19 pm

Post » Fri Feb 18, 2011 10:49 pm

I think doors, chests, whathaveyou, re-lock when the cell respawns.


It's been my experience they don't re-lock. For instance, I used the CS to maake the Arena Box resettable but while the money respawns you can just open it! So in answer to FLCL, yes you will need to also re-lock your gate.
User avatar
Mashystar
 
Posts: 3460
Joined: Mon Jul 16, 2007 6:35 am

Post » Sat Feb 19, 2011 6:06 am

Alright, thanks for the response.

I can't wait to dive headfirst into the project that I have been inspired to create.
User avatar
Esther Fernandez
 
Posts: 3415
Joined: Wed Sep 27, 2006 11:52 am

Post » Fri Feb 18, 2011 11:10 pm

It's been my experience they don't re-lock. For instance, I used the CS to maake the Arena Box resettable but while the money respawns you can just open it! So in answer to FLCL, yes you will need to also re-lock your gate.


Might just be my game. I am not precisely 'vanilla' anymore......
User avatar
Kat Lehmann
 
Posts: 3409
Joined: Tue Jun 27, 2006 6:24 am

Post » Sat Feb 19, 2011 8:43 am

Now as I am sitting here thinking about what I want to do, I keep running in to thoughts about preventing exploits and questions about this and that. Now I don't want to keep bombarding the forums with questions, and I should probably just test it myself and find out but one question really stands out in my mind.

Lets say I have an interior space, in this space I have 4 chests with 4 keys of the same name. A dungeon setup which requires 1 key to unlock a gate, to access another key to open the following gate.
I am thinking someone could exploit this by taking the first key, leaving the dungeon and waiting for it to reset, and picking up the 1st key again. Having 2 keys where they should only have one. So they could completely ignore finding one of the keys in the dungeon and proceed. I want to prevent that.

I thought about having the entrance of the dungeon remove the key, but that would mean leaving the dungeon at any point after acquiring a key would make the dungeon in-completable.

Would I be able to say, OnReset of a gate, or maybe even an invisible object in the dungeon.

To do:
begin OnReset	Lock	player.removeitem AAGateKey 1	set DoOnce to 0end

and have it removed from the players inventory even if they are on the other side of the world?

Might just be my game. I am not precisely 'vanilla' anymore......


I think it might be because the gate is modified by the script, so it probably doesn't follow normal game parameters. Since putting a blank script on a gate then activating that gate, doesn't even open the gate normally. So its probably along those lines as to why you would need to specify to lock it explicitly on cell reset.
User avatar
Madeleine Rose Walsh
 
Posts: 3425
Joined: Wed Oct 04, 2006 2:07 am

Post » Sat Feb 19, 2011 7:11 am

If you have different objects that require keys, use a different key for each object.

Disposing of keys that were acquired before a cell reset gets a bit more tricky. You method may work, but, I am not completely sure on that....
User avatar
BRIANNA
 
Posts: 3438
Joined: Thu Jan 11, 2007 7:51 pm

Post » Sat Feb 19, 2011 8:36 am

If you have different objects that require keys, use a different key for each object.

Disposing of keys that were acquired before a cell reset gets a bit more tricky. You method may work, but, I am not completely sure on that....


I was originally thinking of this, but I didn't want to see 3 separate instances of "Gate Key" in the players inventory. Instead I want Gate Key x3, so I want the keys to be disposed of by either being used on any gate within the dungeon or upon reset of the interior cell.

EDIT - I just tested it with removing the item on cell reset, It works. Not as I was expecting it to, but works regardless.
Instead of removing the key from my inventory after 72 hours had passed. I waited 80 hours and re-entered my testing grounds, and upon entering the zone the key was then removed from my inventory and the zone had been reset since I was able to pick up a new one. Horray!
User avatar
Hilm Music
 
Posts: 3357
Joined: Wed Jun 06, 2007 9:36 pm

Post » Sat Feb 19, 2011 2:03 am

If you are willing to require OBSE.....

Set up a quest script (if you don't already have one running) thats sole purpose is a place holder for variables. When the player enters the dungeon, have the entrance check a variable in the quest script to see if the player has been there before, and, if so, when. Grab the value of cellresethours, have a look at how much time has passed since the last visit, and if it is greater than cell reset time, check to see if the player has any keys on them. If they do, yank 'em. :D
User avatar
Gwen
 
Posts: 3367
Joined: Sun Apr 01, 2007 3:34 am

Post » Sat Feb 19, 2011 1:35 am

Re-locking on cell reset will not happen if you mark the door as persistent. "Persistent" basically means "add the state of this object to the save game", but it also makes that state survive a cell reset.
User avatar
Sarah Kim
 
Posts: 3407
Joined: Tue Aug 29, 2006 2:24 pm

Post » Fri Feb 18, 2011 8:16 pm

I have been tinkering a way for a while on a project of mine, when suddenly a question occurred to me.

I was reading the CS Wiki and it states that OnLoad command does: "Run once when object's 3D is loaded "

Now I had been assuming that OnLoad was run when you load into a Cell, like an Interior Cell.
However this has me thinking that might not be the case.

Does this mean, say if I have an object in a Cell. Initially Disabled, that the OnLoad will run as soon as it becomes Enabled by a calling object?
User avatar
Kill Bill
 
Posts: 3355
Joined: Wed Aug 30, 2006 2:22 am

Post » Sat Feb 19, 2011 12:10 am

On reading it, looks to me like you are interpreting it correctly. I would test that theory first though, with just a short script that prints a console message or some such when you purposely hit some activator to enable it.
User avatar
James Baldwin
 
Posts: 3366
Joined: Tue Jun 05, 2007 11:11 am

Post » Sat Feb 19, 2011 2:20 am

I have run into another snag with a script I am trying to right.

Trying to make use of my first timer, but it isn't working out to well.

I have a gate, that is open initially. The trig zone is beyond the gate, what I want to happen is have the gates closing animation happen behind the player, then lock itself.
Originally it was activating the gate properly by closing it, but never locking it. Now it's just closed before I even encounter the trig zone, I don't know what happened or why the timer isn't locking the gate properly =/

short triggeredshort DoOncefloat timerref targetref myselfbegin onTrigger player	if triggered == 0		set triggered to 1		set myself to GetSelf		set target to GetParentRef		set timer to 2		target.Activate myself 1	endifendbegin GameMode		set myself to GetSelf	set target to GetParentRef	if ( timer <= 0 ) && DoOnce == 0		target.lock		set DoOnce to 1	endif		if timer > 0		set timer to timer - getSecondsPassed	endifendbegin onReset	target.UnLock	Activate	set triggered to 0	set DoOnce to 0end


On reading it, looks to me like you are interpreting it correctly. I would test that theory first though, with just a short script that prints a console message or some such when you purposely hit some activator to enable it.


After testing it, the message appeared both when the cell loaded and when the object was enabled.
User avatar
Erin S
 
Posts: 3416
Joined: Sat Jul 29, 2006 2:06 pm

Post » Sat Feb 19, 2011 12:11 am

Instead of 'activating' the gate to make it close, why don't you use the open state instead?

What if I, the player am OCD and I close the gate myself after passing through. Your script would then 'open' it.

http://cs.elderscrolls.com/constwiki/index.php/SetOpenState


I would also remove the setting of 'myself' and 'target' from the gamemode block of code. I would set it once in the 'onTrigger' block of code.
User avatar
Nick Jase Mason
 
Posts: 3432
Joined: Sun Jul 29, 2007 1:23 am

Post » Fri Feb 18, 2011 11:25 pm

Instead of 'activating' the gate to make it close, why don't you use the open state instead?

What if I, the player am OCD and I close the gate myself after passing through. Your script would then 'open' it.

http://cs.elderscrolls.com/constwiki/index.php/SetOpenState


I would also remove the setting of 'myself' and 'target' from the gamemode block of code. I would set it once in the 'onTrigger' block of code.


Alright, I'll give it a try. I had a feeling that setting 'myself' and 'target' only needed to be done once, but thought that might have been why it wasn't working.

EDIT: I got the script to working using SetOpenState, I also decided to make sure DoOnce was set to 0 by specifically setting it in the OnTrigger section (Though I am fairly positive it should be zero by default). However regardless, it closed and locked my gate flawlessly this time, horray
User avatar
anna ley
 
Posts: 3382
Joined: Fri Jul 07, 2006 2:04 am

Post » Fri Feb 18, 2011 9:27 pm

*Grumble*

I don't know why I can't call a sound file to play properly. The sound file itself works in the game, I had it as a ambient sound object looping and it played just fine when I loaded the game. But when I try to call for the sound to play OnLoad or OnActivate I get nothing. Checked the wiki to make sure I had proper format, and it looks correct. Also tried using PlaySound3D to the same results =/

Have tried
short DoOncebegin OnActivate		If DoOnce == 0			PlaySound SoundID ("Also tried using the FormID, both of which were accepted into the script editor as valid format")		set DoOnce to 1	else		Activate	endif	end


and just plain

begin OnLoad	PlaySound SoundIDend

User avatar
Naomi Lastname
 
Posts: 3390
Joined: Mon Sep 25, 2006 9:21 am

Post » Sat Feb 19, 2011 12:01 am

Did you try using http://cs.elderscrolls.com/constwiki/index.php/PlaySound3D?
User avatar
MR.BIGG
 
Posts: 3373
Joined: Sat Sep 08, 2007 7:51 am

Post » Sat Feb 19, 2011 4:30 am

Did you try using http://cs.elderscrolls.com/constwiki/index.php/PlaySound3D?


Yes I did, Its in the post. Teehee :P
User avatar
CSar L
 
Posts: 3404
Joined: Fri Nov 09, 2007 9:36 pm

Post » Fri Feb 18, 2011 11:58 pm

After changing the soundfile that I was trying to play, I found out that its the soundfile I was trying to use that won't play when called by the PlaySound function. But I can't figure out for the life of me why, they are both .wav files. I know Oblivion can play the sound because when I put it into the render window it shows up as an Ambient object and I hear the sound as ambiance when I load the game. I just don't understand why I can't make it play the sound otherwise =/
User avatar
Pants
 
Posts: 3440
Joined: Tue Jun 27, 2006 4:34 am

Post » Sat Feb 19, 2011 12:28 am

Is the sound file rendered at 32000 Hz, 16 bit, Mono PCM Wave file?
User avatar
Krystal Wilson
 
Posts: 3450
Joined: Wed Jan 17, 2007 9:40 am

Post » Sat Feb 19, 2011 11:46 am

Is the sound file rendered at 32000 Hz, 16 bit, Mono PCM Wave file?


I don't know about the PCM part, but its Stereo 32000 Hz, and I would assume 16 bit.

EDIT: I also have one that is Mono 32000 Hz, and had the same result with that. Works as Ambient but not when called by PlaySound

EDIT2: I found more of the file info you were asking about, it is PCM

Format                           : WaveFile size                        : 87.3 KiBDuration                         : 1s 396msOverall bit rate                 : 512 KbpsAudioID                               : 0Format                           : PCMCodec ID                         : 1Codec ID/Hint                    : MicrosoftDuration                         : 1s 396msBit rate                         : 512 KbpsChannel(s)                       : 1 channelSampling rate                    : 32.0 KHzBit depth                        : 16 bitsStream size                      : 87.2 KiB (100%)

User avatar
sophie
 
Posts: 3482
Joined: Fri Apr 20, 2007 7:31 pm

Post » Fri Feb 18, 2011 9:53 pm

Problem solved, apparently I can't link the sound to an external folder when trying to call it with PlaySound and it has to be in the fx folder.
But Ambient noises can be played from outside the fx folder
User avatar
Karl harris
 
Posts: 3423
Joined: Thu May 17, 2007 3:17 pm

Next

Return to IV - Oblivion