Jump to content

Post your Scripts Here


Smosh

Recommended Posts

Another little something I put together to help someone out again:

 

First script should be applied to an NPC character placed in a cell. Second script resurrects the NPC if he's been killed upon a button press, script should be assigned to a button/switch/whatever. Useful for target practice or similar ideas.

 

scn PrisonerResurrectSCRIPT

BEGIN GameMode
PrisonerREF.GetDead ;checks every frame whether the ref is dead and returns a 1 if it is
END

 

scn PrisonerResurrectTRIGGER

BEGIN OnActivate
if PrisonerREF.GetDead == 1 ;if GetDead has returned a 1, ie the prisoner has been killed
	PrisonerREF.Resurrect ;resurrect him in the same spot he was killed
endif
END

 

You can add an optional PrisonerREF.MoveTo Location (using a XMarker placed in the GECK) after the Resurrect to always have him respawn at the same location.

 

Critique/Pointers/Optimizations welcome again :)

Link to comment
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

It's nice to see this thread again, I always enjoy seeing what people come up with here. Once again, nothing I say is intended to be offensive or a personal attack, so if it sounds like that then I apologise. Please let me know if I'm mistaken anywhere, or I haven't explained something particularly well.

 

 

==============================

 

 

Simple timed door script I put together earlier to help someone elsewhere on the forum. Any ideas for better ways to do it or for optimizations etc. are welcome, I'm still pretty noob to FO3 scripting :)

 

Just modify the GetCurrentTime values for whatever times you want the door to be open/closed. Placed door reference needs to be persistant and the door unlocked.

 

scn TimedDoorScript

BEGIN GameMode
if GetCurrentTime >= 8
	TimedDoorREF.Unlock 1
	TimedDoorREF.setOpenState 1
endif

if GetCurrentTime >= 20
	TimedDoorREF.setOpenState 0
	TimedDoorREF.Lock 255	;setting this to 255 = Requires Key.
				;If you want it pickable, 100 = Very Hard, 75 = Hard, 50 = Average, 25 = Easy, 0 = Very Easy
endif

if GetCurrentTime < 8
	TimedDoorREF.setOpenState 0
	TimedDoorREF.Lock 255
endif
END

I would normally use one the global variables relating to in-game time like "GameHour" or "GameDaysPassed" instead of GetCurrentTime. In fact I've almost never seen anyone use this function, presumably because there's really no need for it as far as I know.

 

Assuming that this script is attached to "TimedDoorREF", then you can use implied reference syntax, so the reference doesn't necessarily need to have an EditorRefID nor does it necessarily need to be set as persistent.

 

When creating conditional statements that are mutually exlusive (i.e. if one is true then the others are false), then "elseif" and "else" statements should be used instead of additional "if" statements. That way, if one of the previous conditions evaluates to true, the game won't waste time checking the other conditions. In this case, your conditions aren't actually mutually exclusive, but they are set up in a way that makes it look as though they should be (i.e. if GameHour >= 20, then the code run when GameHour >= 8 shouldn't run, although the way in which you've ordered your code prevents any bugs here).

 

You've also included duplicate code in here, after your second two conditions, which should always be avoided whenever possible so long as it doesn't affect the functionality of your script. Instead of just using the same code in multiple conditions, you can combine the conditions using a logical OR ("||"). Here is how the script could be rewritten using more efficient "if" structure and using "GameHour":

scn PrisonerResurrectSCRIPT

BEGIN GameMode
PrisonerREF.GetDead ;checks every frame whether the ref is dead and returns a 1 if it is
END

 

scn PrisonerResurrectTRIGGER

BEGIN OnActivate
if PrisonerREF.GetDead == 1 ;if GetDead has returned a 1, ie the prisoner has been killed
	PrisonerREF.Resurrect ;resurrect him in the same spot he was killed
endif
END

 

You can add an optional PrisonerREF.MoveTo Location (using a XMarker placed in the GECK) after the Resurrect to always have him respawn at the same location.

 

Critique/Pointers/Optimizations welcome again :)

The first script is completely pointless, as it doesn't actually do anything at all. The only thing it does is call GetDead, and the only thing that GetDead does is return either 1 or 0, depending on whether the reference that it was called on is dead or not. Obviously, just doing this won't actually have any effect on anything, so the script shouldn't be used. The second script, on the other hand, uses ResurrectActor as well as GetDead, so it will do something.

 

Instead of "hard-coding" the EditorRefID of "PrisonerREF", if your second script is an object script then you could (and probably should) use a linked reference instead so that the same script can be used for many different sets of references. To do this, you'll need to use a "ref" variable, as well as the GetLinkedRef function.

 

Because GetDead can only return 0 or 1, the " == 1" in your condition doesn't actually do anything. The "==" operator returns a value of 1 if both arguments are equal, and 0 if they are not, so your condition checks if the return value of GetDead is 1, and if it is then it returns a value of 1. If GetDead returns a value of 0 (the only possible value other than 1), then the "==" operator will return a value of 0. As you can see, this adds nothing to your condition, but makes it slightly less efficient, so you should remove " == 1" from your condition.

 

A bug has been observed with ResurrectActor where, if its single optional parameter is either absent or 0 (its default value), as in this case, Fallout 3 may crash. It's not clear what exactly it is about a reference that may cause this to occur, but you should make sure that you test its use very carefully to make sure that this will not occur.

 

This is what I would change your script to:

ScriptName PrisonerResurrectTRIGGERScript

ref rLinkedRef

Begin OnActivate
set rLinkedRef to GetLinkedRef
if rLinkedRef.GetDead
	rLinkedRef.ResurrectActor
endif
End

Just a very minor thing that you might notice - in the code that I've posted above I've change the EditorID of your script so that it has the "Script" suffix. I usually do this with all forms that I create as it helps to reduce the frequency issues cause by duplicate EditorIDs. Like I said though, this is just a very minor thing, and doesn't really have anything to do with the script.

 

Cipscis

Link to comment
Share on other sites

Wow, lots of nice tips there, thanks muchly Cipscis. I'd already tidied up the first script using || actually, I forgot you could do that when I first wrote the script (I haven't really done much scripting in a few years, last time was UT2004 unrealscript, so I'm a bit rusty heh). The other tips are great though, will take a look at that script again later and tidy it up a bit more.

 

As for the second script, I didn't realise the first script was pointless heh. So basically, the GetDead in the second script is doing what it should be doing in the first script, making the first one pointless? Interesting, I'll have a play around with adjusting that later as well.

 

Lastly yeah, I actually tend to use SCRIPT in big capitals in scripts if I'm working on something that has quite a lot of custom forms to avoid problems. I don't always if I'm only doing something quick and simple like this though. Thanks again for the tips :)

Link to comment
Share on other sites

  • 1 month later...

Sorry to resurrect a month-old thread, but I think it would be a shame to see this die.

 

For anyone interested in learning more about script optimisation, I've been doing some testing on the efficiency of various things and have posted the results over on the official GECK forum - Script Optimisation

 

If there are any methods or functions that you'd like me to test the efficiency of, just let me know and I'll test them for you. I've got a data file set up already for testing the efficiency of scripts so it's very easy for me to do so.

 

Cipscis

Link to comment
Share on other sites

I scavenged an object script from a Fallout Armoury and changed it a bit:

 

scn 0001KhanEntryDoorAlarm

 

short doOnce

 

;***************************************

Begin GameMode

 

if (doOnce == 0) && (player.GetInCell 0001KhanRaiderEntryRoom == 1)

set doOnce to 1

"0102C2F9".enable ; Klaxon Lens Activator

"0102C2FA".enable ; Klaxon Glow Light Effect

"0102C302".disable ;Nonfunctional Klaxon Lens

endif

End

 

Begin onTriggerEnter Player

 

if (doOnce == 1)

set doOnce to 0

"0102C2FB".enable ; Klaxon Sound

"0102C2F9".playgroup Left 0

"0102C2FA".playgroup Left 0

endif

End

;***************************************

 

Then linked it to my main Quest script with a few lines, because the object script seemed to stop working when I left the cell that the reference object is in:

 

 

;Khan Door Alarm **********************************************************

 

Begin GameMode

 

if (player.GetInCell 0001KhanRaiderHQInterior == 1)

"0102C2FD".disable ; Klaxon Alarm Trigger

"0102C2FB".disable

"0102C2F9".disable

"0102C2FA".disable

"0102C302".enable

endif

End

 

Begin GameMode

 

if ( player.GetInWorldSpace Wasteland == 1 )

"0102C2FB".disable

"0102C2F9".disable

"0102C2FA".disable

"0102C302".enable

if ( "0102C2FD".GetDisabled == 1 )

"0102C2FD".enable ; Klaxon Alarm Trigger

endif

endif

End

;***************************************

 

This triggers alarm lights and sounds when the player first enters an underground facility. When the player leaves the first interior cell and goes deeper into the facility the lights, sounds and trigger are disabled and a dummy klaxon lens is left in place of the active one. The trigger is reenabled only after you leave the facility completely, and will then retrigger the alarm lights and sounds upon re-entry.

 

The script could have been made simpler by using enable parents, but I was on a roll this morning and didn't stop to do that.

 

I like this better than hearing it nonstop each time I enter the guard room at the entrance while still inside the raider clubhouse ( conditional allies ). I like to think that the raider guards appreciate it too.

 

It seems that when I use a reference term like "KlaxonAlarmTriggerREF" the script will often not work, whereas if I use its corresponding 8 digit hexidecimal number the script will always work for me, so that is what I do.

Link to comment
Share on other sites

  • 11 months later...
  • 7 months later...
this is what Im talking about for a FSD Fallout Script Dictionary. People here are kind enough to contribute to a community. Thanks fellas and gals.
Link to comment
Share on other sites

  • 1 month later...

FORGOT SORRY WILL NOT ASK FOR HELP AGAIN

but i will post the script if i work it out.

 

i dont have a script but i need one

its for making a brahmin follow you for a short time if you hit it with a cattle prod or if its easier you hit it and it follows and then hit it again and it stops

 

but the script is for a mod i am making and i need help on where to start with this code because i have never writen any thing like this before.

here is the link

 

http://www.newvegasnexus.com/downloads/file.php?id=39607

 

also i will need another code and any one can make this with the idea and it is to make it possible to breed animals.

the story is you go to a vault and you find a prototype geck that makes clones of animals

"because you need meat to rebuild the world"

you take the geck set it up on your farm. you insert animal DNA and it makes a artificial insemination kit for that animal

you use it on the animal and it lays a egg or gives birth after about a week.

then you have to feed the animal to make it grow because you will get more meat from an adult

Edited by Odvic
Link to comment
Share on other sites

  • 1 year later...
  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...