===== Available Scripts/Tutorials =====



=== Activators ===

=== Changing Game Defaults ===

=== Containers ===

=== Magic Items & Objects ===

=== Manipulating Inventory (Items/Spells) ===

=== Multipurpose/Miscellaneous Scripts ===

=== Spells ===

=== Templates ===


===== My $0.02 =====

=== Posted 2007-02-03 @ 07:26 AM ===
Yeah, I know there are scripting & modding resources out there, as well as the CS Wiki, etc. But, I thought this forum's community might put together a collection of useful code snippets with a basic explanation of what they do and how to implement them. An archive of script/code/tricks as modding resources, including descriptions of AI packages and Quest/Dialog/Conditions (and scripts to manipulate them) for specific purposes.

I believe this should be on a "no credit necessary, but it's always nice" basis. We could also eventually release it for distribution on modding sites.

For one thing, whenever someone posts a question that's already been answered here, we could point them to this thread.

Of course, no need to duplicate the basic tutorials already available. The goal here is to be more specific than a general description of what is possible, generating a compendium of effective, useful and adaptable code for general modding purposes.

This is not meant to be another "Modding 101: How to Create a Quest" thing, but rather a "Useful Code/AI Packages for Creating a Companion Mod" (for example) kind of thing. Something along the lines of MentalElf's Companion AI, War Summons secrets revealed! But that would be just one entry, the goal is to get a bunch of different types of scripting/coding resources together.

It should go beyond comments like "just open the CS and see how this quest is done", or "open this mod and see how X modder did this", as it should attempt to walk the modder through the necessary steps. I'm not talking holding hands, just some more help than "figure it out dude" or "RTFM". Hey, I'm guilty of that sometimes, but at least I'm trying.

C'mon guys & gals, time to spill your Bag o' Tricks!

I volunteer to keep track of the contributions in an organized format available for download somewhere to be determined. In terms of format, I propose the following example as an initial contribution. I will strive to add more, as well as more advanced code.

=== Addendum 2007-02-04 @ 03:20 AM ===
Well, here's my second contrib, with thanks to TomWithTheWeather.

=== Addendum 2007-02-04 @ 09:25 PM ===
Thanks in advance to any other contributors:
I'd like to keep this thread bare of too much chatter.

=== Addendum 2007-02-06 @ 05:45 AM ===
Why ModFood? I'm a music FANATIC, and I was always impressed with the DJ Food concept:
rather than a real band, they put stuff together as "Food" for DJs. Hence this idea.

=== Addendum 2007-02-08 @ 04:38 AM ===
Why not just contribute to the CS Wiki? I just have a hard time finding what I need there. More often than not I have to revert to posting a question on this forum. The Wiki is a great resource for the basic Guides/Tutorials and as an all-encompassing encyclopedic list of everything in the CS, but is not intuitively organized for finding stuff like on this thread. As ModFood grows, it will have to be moved to a more organizable format, probably some website. But rather than try to be all encomapssing like the Wiki, I just want to compile a compact modder's resource with clear categories for commonly used code snippets. Where I see this thread (& its expansion) can be useful is in providing advanced snippets of code to accomplish specific things under certain conditions.



===== Credits/Thanks (I apologize if I forgot someone) =====

=== Thanks for your contributions & support! ===
Comandra
haama
J3X
Logam
TheMadMage
ThisIsUsMc
WillieSea

=== Thanks for the support & positive feedback! ===
Feek165
gibbo912
Kalibr
Qazaaq
Objective: Automatically adding items or spells upon loading a mod for the first time

Options

A. Creating a new mod to add standard game objects:
Open the CS with just Oblivion.esm selected in the Data Files.
Follow the steps below and save as a new esp file in the Data folder.

B. Using this in your mod or tweaking an existing mod:
Open the CS with the mod as the Active File and follow the steps below, then save the mod.

Steps

1. Create a new quest:
Click on the Q button, right-click in the list and add a new quest.
Name it aaaSomeQuestName so it's at the top of the list.
Make sure StartGameEnabled is checked, which it should be.
Close the window.

2. Create a new script:
Click on the pencil button, and select New from the Script menu.
Copy/type this code in the editor.

CODE
Scriptname aaaSomeQuestNameScript

Begin GameMode
    Player.AddItem EditorID, 1
    Player.AddSpell EditorID
; repeat above as needed
    StopQuest aaaSomeQuestName
End


Editor ID for the spell or item is listed in the Object Window, and aaaSomeQuestName is the name of your quest.

Select Quest in the Script Type drop down menu in the title bar of that window, and click the save button.
Close that window.

3. Select that script for the quest:
Click on the Q button again and select your quest (aaaSomeQuestName).
In the Script drop down, choose your script (aaaSomeQuestNameScript).
Close the window and save the mod.

Next time you play, the item(s)/spell(s) will be added automatically!
Objective: Create a door/portal that can take you to one of several locations

This is basically along the lines of Guild Guides from Cyrodiil Transportation Network where the script is called by the mage, and is adapted from TomWithTheWeather's All-in-one Basement mod.

Steps

1. Create a new door object by duplicating one that fits your purposes. This can be a regular door, trap door, dungeon/fort door, or even the Mage Guild Portal used in the Archmage's Tower in the Arcane University. Give the door an easy name to remember: I'm using aaaMyModPortal here.

2. Place markers where you want the portal to teleport the player to. To do this, you need to open the Cell you want to go to in the Render Window, and place an XMarkerHeading from WorldObjects>Static (XMarker works also, but doesn't show you the direction the player will face when s/he arrives). So let's say you want one of the locations to be the Chorrol Mage Guild: in the Cell View window, select Interiors and double click on ChorrolMagesGuild in the list. There's already an XMarker and an XMarkerHeading in the main room there, but you can place yours pretty much anywhere, and orient it the way you want the player to show up. Make sure it's flush with the floor, you don't want to show up in mid-air. Then double click on the marker and give it a specific name in the Reference Editor ID text box (aaaChorrolMGMarker). Close that window and go place the markers for the other locations you want your portal to go to, giving each one a unique name.

3. Create the following Object script, replacing the Location2 & Location3 with your locations & markers. Remember, you can only have 10 choices in a MessageBox; you can create sub-menus if you want more options, but let's leave that for another lesson.

CODE
ScriptName aaaMyModPortalScript

short Button

;== Display message box and options.

Begin OnActivate

    if IsActionRef Player == 1
        MessageBox "Where do you want to teleport to?", "Chorrol Mage Guild", "Location2", "Location3", "Cancel"
    endif

End

;== Move player to location markers.

Begin GameMode

    set Button to getButtonPressed

    if Button > -1

        if Button == 0
            Player.MoveTo aaaChorrolMGMarker
            Return
        elseif Button == 1
            Player.MoveTo aaaLocation2Marker
            Return
        elseif Button == 2
            Player.MoveTo aaaLocation3Marker
            Return
        elseif Button == 3
            Return
        endif

    endif

End


4. Attach the script to your door/portal: double click on aaaMyModPortal in the Object Window and in the Script dropdown menu select aaaMyModPortalScript.

5. Place the aaaMyModPortal where you want in the Render Window. Save and go play.

That's it!
Objective: Avoiding message spam

Option A - bullet-proof but has a side-effect
CODE

Message "Your message", 1;or you can make it blank, " "
Message "Your message", 1;these two lines need to be exactly the same
player.RemoveItem ... player.AddSpell... etc.


This disables Oblivion's ability to queue messages for a few seconds (the default duration) of the message (meaning, old messages will still show up, but any new messages, from any source, after these two lines fire, will be ignored). If you need to tell the player something afterwards, I would suggest using a messagebox.

Option B - less reliable but can show messages afterwards

Write a message in the frame following the spam. For example,
CODE

set Counter to 2
if Counter
  message "Your message"
  player.RemoveItem...
  set Counter to (Counter - 1)
  return
endif


Showing a message afterwards should not be a problem in and of itself. However, there are some things that will either: do nothing, display the message queue from the beginning, or display the message queue from it's current position (these two are different - when the message can safely be displayed afterwards should make a difference). So far, these things seem to include:
Having a message beforehand and then displaying a message afterwards
Having a few frames for the message to be displayed between the multiple uses
i.e., The above code is part of a OnActivate block on a container - activating that container continously and rapidly will cause the spam to be displayed (I guess this is related to the reason above)
Objective: Remove Items from the Player's Inventory Quickly and Safely (Req OBSE 9a)

The quick part:
This is the standard code for taking all item's from the player's inventory using the OBSE 9 looping functions. Looping functions are still considered beta, so this code should be considered beta also (however, since the 9a fix, there doesn't seem to be any problems with it). All thanks should go to those who've worked on this before (the OBSE team, phoenix amon, and kea, and probably others).

The safe part:
No quest items are removed from the player
No Nirnroot is removed from the player (the quest adds the Nirnroot a second time when the player takes it back)
Odd stacks of items won't be left in the player's inventory (seems scripted/modified ingredients had this problem)
Won't remove equipment the player is wearing (delete && (player.GetEquipped rInvObj == 0) if you don't want this)
I'm working on avoiding onAdd blocks - I'll add it if I can get it to work. onAdd blocks will fire when added to the container.

Side effects:
If the variables on a scripted item have been set, then this will erase the set variables.
This will erase the stolen flag from all of the items.
To prevent message spam I'll use this, which does have a side effect.
OnAdd blocks on each item will fire.

Options

This code is for a container. Just attach it to a container and place it in the world.
This can be used on an unplayable token with a few modifications. I've put in a few comments on how to set up the token script.


CODE

short Working
short Choice
short InvPosition
short InvTotal
short InvObjAmount
ref    rInvObj
ref    rContainer;necessary if you put this script on an item instead of a container

begin OnActivate
  if IsActionRef player == 1
    messagebox "What would you like to do?" "Store Items";... whatever other options you want
    DisablePlayerControls;looks smoother if you disable player controls here, just make sure to re-enable
    set Working to 1
    set Choice to -1
    set InvPosition to (player.GetNumItems - 1)
    set rContainer to GetSelf;or GetContainer for a token
  endif
end

begin GameMode;or MenuMode 1008
    if Working != 1
      return
    else
      if Choice == -1
        set Choice to GetButtonPressed
        return
      elseif Choice == 0;Store Items
        message " ", 1
        message " ", 1;leave both of these blank to remove message spam

                set InvPosition to (player.GetNumItems - 1)    
        Label 1
        if (InvPosition >= 0)
          set InvTotal to (player.GetNumItems)
          set rInvObj to (player.GetInventoryObject InvPosition)
          if (IsQuestItem rInvObj == 0) && (rInvObj != MS39Nirnroot) && (player.GetEquipped rInvObj == 0)
            set InvObjAmount to (player.GetItemCount rInvObj)
            if InvObjAmount > 0
              player.RemoveItem rInvObj InvObjAmount
              rContainer.AddItem rInvObj InvObjAmount
              Label 2
              if (InvTotal == player.GetNumItems)
                set InvObjAmount to (player.GetItemCount rInvObj)
                player.RemoveItem rInvObj InvObjAmount
                Goto 2
              endif
            endif
          endif
          set InvPosition to (InvPosition - 1)
          Goto 1
        else
          set Working to 0
          set Choice to -1
          EnablePlayerControls
          return
        endif
      elseif Choice == ...;whatever other options you want to make
        ...
      endif
    endif
end
This is a brilliant idea. I used to be a VB programmer and relied on code snippets all the time. This should be a sticky.
Objective: Create an activator that activates on Frost damage

Put your activator in the required spot and then code it thusly:
CODE

Scn MagickaActivated

short DoOnce

Begin OnActivate
Messagebox "This Item will only activate when hit with a Frost spell.", "Ok"
end

Begin OnMagicEffectHit FRDG
If DoOnce == 0
;Your code here
Set DoOnce to 1
endif
end


You can actually replace frost with any other type of spell but i've forgotten where the list it.

EDIT:: Found It! Magic Effect List!
Happy Coding!
$nickahz

Edit:: Just for Logam I put a period in there. BTW Logam, you made a mistake in yours too! tongue.gif You forgot to comma-ize it.
Nice work everyone! This is a great idea for people to post scripts and the like on how to achieve things in the CS. smile.gif

Agree this should be stickied happy.gif

EDIT: TIUM you don't need a comma tongue.gif
Spoke with a mod and suggested that either this or a thread based on this idea be pinned.

She's looking into it.
QUOTE(ThisIsUsMc @ Feb 5 2007, 03:46 PM) *
Spoke with a mod and suggested that either this or a thread based on this idea be pinned.

Oh fine, steal my idea! cry_smile.gif

Just kidding, all credit goes to the contributors.
But if someone else is going to manage the thread, I hope they're committed.
If this thing grows, it's going to need some maintenance so it's not too hard to sift through.
Objective: Avoiding message spam on additem II

You need a persistence container with a unique ID placed some were in the world.
This version don't block any important messages.

CODE
scn J3XAddItems

begin onactivate;Or something
   J3XUniqeConatiner.additem J3XItems 50;Replace it with your items
   J3XUniqeConatiner.removeallitems player
end




Objective: Make a activator cast a spell on the player when it's being hit with a arrow

CODE
scn J3XFantasticScript

Begin OnHitWith J3XFantasticArrow;You can skip the item Id and it will work with any arrow;)
   PME ReHe;Restore Health effect
   cast J3XRestoreHealthSpell player
end




Objective: Reanimates a NPC that is lying on a Altar and make it look like a ghost

Of course it don't have to be an altar, any creepy stuff will to it, just as long you can drag a NPC upon it.
Please not that this just brings the NPC back to life, no other AI or things like that.
You need : a spell & 2 activators (one invisible and one alter thing)

The altar script:
CODE
scn J3XAltarScript

ref self
ref caster
float temp

begin Onload
   pms effectReanimate; Adds a bit of atmosphere with a nice shader
end

begin onactivate;whatever you want
   set caster to placeatme J3XCaster
   set temp to caster.getpos z
   set temp to (temp + 200);Change this if you want to cast it indoors, like 50 or something.
   set self to getself
   caster.cast J3XSpell self
   caster.disable
end


The Scripted spell effect code:
CODE
scn J3XSpellEffect

begin onscripteffectstart
   reanimate 1;Including rez animation!
   addspell AbGhostNPC";Ghostly appearance!
end


Edit: Added more scripts
Edit: Typos


We should add this to the CS wiki.
QUOTE(Felic @ Feb 5 2007, 11:50 PM) *

Oh fine, steal my idea! cry_smile.gif

Just kidding, all credit goes to the contributors.
But if someone else is going to manage the thread, I hope they're committed.
If this thing grows, it's going to need some maintenance so it's not too hard to sift through.


Felic, you and I could manage it! We are always on the forums tongue.gif
I Could Help Manage, I'm On The Forums A Lot Daily And I Come To This Thread At Least Twice Daily, I Could Help. Besides, Felic Helped Me On My Thread, He Rocks. (And So Does His Icon.)
QUOTE(J3X @ Feb 6 2007, 12:43 AM) *
We should add this to the CS wiki.

Yeah, some people might wonder why or be silently criticizing me for not just contributing to the CS Wiki, but I just have a hard time finding what I need there. More often than not I have to revert to posting a question on this forum. The Wiki is a great resource, but not intuitively organized for finding stuff like on this post. As this grows, it will have to be moved to a more organizable format, probably some website. But rather than try to be all encomapssing like the Wiki, I just want to make a compact modder's resource with clear categories for commonly used code snippets: Companions/Quests/Triggers/etc. It's a WiP, and your suggestions are more than welcome.

QUOTE(Logam @ Feb 6 2007, 05:03 AM) *
Felic, you and I could manage it! We are always on the forums tongue.gif

Thanks dude! If and when we expand this beyong a single thread, I'll be sure to remind you of your kind offer. But at this time, organization means editing my initial post, and I'm not about to share my login with anyone. emot-ninja1.gif

QUOTE(Comandra @ Feb 6 2007, 05:11 AM) *
I Could Help Manage, I'm On The Forums A Lot Daily And I Come To This Thread At Least Twice Daily, I Could Help. Besides, Felic Helped Me On My Thread, He Rocks. (And So Does His Icon.)

Only if you stop with the Title Case! tongue.gif
QUOTE(Felic @ Feb 6 2007, 06:38 AM) *

Thanks dude! If and when we expand this beyong a single thread, I'll be sure to remind you of your kind offer. But at this time, organization means editing my initial post, and I'm not about to share my login with anyone. emot-ninja1.gif


Ofcourse, i would never ask for login details as it is against forum rules and regulations... disapprove.gif

I meant when this gets beyond one thread or if it gets stickied or something, we could both manage it and add stuff in, ect. happy.gif
QUOTE(J3X @ Feb 5 2007, 04:43 PM) *

CODE
scn J3XAddItems

begin onactivate;Or something
   J3XUniqeConatiner.additem J3XItems 50;Replace it with your items
   J3XUniqeConatiner.removeitems player  <-- THERE --
end

It should be removeallitems IIRC.

fing34.gif This is a great idea, it's much easier for people to add code a forum thread than the cswiki. It's good for gathering information, but eventually someone should copy it to the wiki.
I don't know, the wiki is difficult to navigate. I find it easier to use the "What links here" button then to look through the tutorials/solutions/useful code/etc. I think adding this page would just add to the confusion right now.

@Felix - so should this thread be chatty? Your hyperlink solution does wonders.
Chat away! biggrin.gif

What I meant with the chatter comment is to focus on posting snippets. Discuss the workings of a script on another thread, then post the solution here. This will allow this thread to be a repository rather than a discussion on scripting in general.

When I noticed a minor error on one of the scripts posted, I PM'd the author rather than comment on this thread. However, discussing what to do with this thread is essential, especially at this point.

@Qazaaq: People who post here can add their snippets to the wiki if they feel like it. I'm not going to do it for them.
Ojective: Simple Scripts. Fire And Teleport Spell


Two things:

1: I've stopped the caps thing wink.gif
2: I have a few good scripts that are kinda fun, the only problem is they are kinda' basic.

CODE

Begin ScriptEffectStart
   GetFlames
End


See how basic they are, here's another one:
Requirements:
- A cell.
- The ability to read.

CODE

Begin ScriptEffectStart
   coc "cell name here"
End


- OR - (this is the better choice. Way better.)

CODE

Begin ScriptEffectStart
   Player.MoveTo "markerRefID"
End

where markerRefID is the name you give the XMarker or XMarkerHeading you place in the cell.


You will also have to have a teleport marker where you want to teleport to. This may used for a container cell. I am an ameteur, but hey, I might be better than some.

Lastly, can you post race things and other stuff than scripting on this thread, perhaps create a new thread for that? (by the way, this would have been here by 5:30 if i didn't have to go to the store.)
Logam, don't forget me, I'll be more than happy to help manage this thread, if it gets stickied that is.
Comandra with the teleport spell it would be more effective to place a marker and then have the player move to that marker, otherwise with COC it could randomly place the player in buildings, ect.

Also a mark and recall script would just call an activator too the player then when you cast re-call, your player is moved to that... smile.gif
QUOTE(Comandra @ Feb 6 2007, 01:16 AM) *

CODE

Begin ScriptEffectStart
   coc "cell name here"
End



Something like this?

CODE

Begin ScriptEffectStart
   player.moveto MarkerName
End
Logam & J3X, I PM'd Comandra about that right after he posted it.

EDIT: Gender fix! Sorry!!! blush.gif
QUOTE(J3X @ Feb 6 2007, 04:18 PM) *

Something like this?

CODE

Begin ScriptEffectStart
   player.moveto MarkerName
End



Just like that smile.gif

QUOTE(Felic @ Feb 6 2007, 04:25 PM) *

Logam & J3X, I PM'd Comandra about that right after she posted it.


Oh, ok then... tongue.gif
Objective: Make a drop able misc item turn to a container when you drop it and activate it

You need a: Misc item and a container item. (and 2 scripts)
You pick up the container by sneak and activate it, it will add all items left in the container to the players inventory (no message spam smile.gif)

Misc Item Script:
CODE
scn J3XMiscItemScript

float temp
ref cont

begin onactivate
   set cont to placeatme J3XContainer 1

   set temp to getpos x
   cont.setpos x to temp
   set temp to getpos y
   cont.setpos y to temp
   set temp to getpos z
   cont.setpos z to temp
end


Container Script:
CODE
scn J3XContainerScript

ref self

begin onactivate
   if player.IsSneaking == 1
      set self to getself
      self.additem J3XMiscItem 1
      self.removeallitems player
   else
      activate
   endif
end


Edit: Script errors and things like that, thanks to Haama for letting me know.
Such a helpful thread can't be lost so I'm posting this. Anyways, is this thread used for just helping people, or only helping with scripting, maybe if it gets stickied or something it can be an all-round guide. I'm an O.k scriptor, can't even import or export into blender, but I am good at retexturing and i'm good at overall help.
Request: Quest Making

I think that it would be nice if somebody put a written guide here on how to create a quest, that would be nice. Also, could somebody put quest functions like (it would be a miracle if these acctually existed.)

SkipQuestStage x - Replace The 'x' with a number and after that script, it will skip however many quest stages you put as the number. For example:
CODE

Begin OnActivate
   Player.MoveTo 'ref ID'
   SkipQuestStage 2
   Messagebox "You Have Been Teleported To An Unknown Hall."
End


Obviously, before you try it, i am almost certain that SkipQuestStage is not a real command because it was off the top of my head, but I might be psychic wink.gif
QUOTE(Comandra @ Feb 6 2007, 09:35 PM) *
Anyways, is this thread used for just helping people, or only helping with scripting, maybe if it gets stickied or something it can be an all-round guide.

The intention of this thread was initially solely to gather snippets of code with explanations on how to implement them. Some people are suggesting expanding it to other mod resources, which I consider a longer-term goal while we discuss it.

QUOTE(Comandra @ Feb 7 2007, 12:00 AM) *
Request: Quest Making
I think that it would be nice if somebody put a written guide here on how to create a quest, that would be nice.

Well, this is where the CS Wiki has its strengths. It does have a pretty complete guide on basic Quest creation. Where I see this thread (& its expansion) can be more useful is in providing more advanced snippets of code to accomplish specific things within a certain type of quest.

QUOTE(Comandra @ Feb 7 2007, 12:00 AM) *
Also, could somebody put quest functions like (it would be a miracle if these acctually existed.)
SkipQuestStage x [snip] Obviously, before you try it, i am almost certain that SkipQuestStage is not a real command because it was off the top of my head, but I might be psychic

This is for the Cheats forum, and defeats the purpose of creating Quests in the first place.

But, here's what you're looking for: wink_smile.gif
GetStage QuestFormID (this will show you the current stage in the quest)
SetStage QuestFormID Stage# (this will advance you to a certain stage in the quest)
CAQS (this will complete all stages of the active quest)
MoveToQT (this will move the player to the active quest target)
This is all I have to say:

Thanks Felic,
O.k, The CS wiki is good for that,
3: Taken care of, thanks
QUOTE(Comandra @ Feb 7 2007, 06:27 AM) *
I'M NOT A GIRL!

Oops, so soz 'bout that! See my fix:

Gender fix
Objective: Creating an Options Button Inside of a Container

This is a pet peeve of mine. There are some containers that you usually want to open, and occasionally want to fool around with the options. So...

Options

A. Use an arrow - this ensures the options are the top-most item/button in the container menu.
Shortfall - will have a very brief remove item spam, which can be avoided.
B. Use a weapon - this can have a script placed on it so no remove item message
Shortfall - may not always be the top-most item

Steps

1. Create or extract an icon image for your options
2. Edit an item - in the ID slot call it OptMenu, " Options" (note the space!) for the name, set the icon image
3. Place at least 2 of the item in the container
4.A. Add this script to the container

CODE

begin MenuMode 1008
  if (player.GetItemCount OptMenu == 0)
    return
  else
    player.RemoveItem OptMenu 1
    AddItem OptMenu 1
    messagebox "Your options"
    ...


4.B. Add this script to the weapon

CODE

begin onAdd player
  YourContainer.Activate YourWeapon, 1
  YourContainer.AddItem YourWeapon 1
  RemoveMe
end


and this to the container

CODE

begin onActivate
  if (IsActionRef YourWeapon == 1)
  messagebox "Your options"
  ...
Objective: Make a ring that adds a spell when it's worn by the player

This script adds another spell if a NPC wear it. And display a message only when the player wear it.
You need a ring or any other clothing and some spells.

Ring Script:
CODE
scn J3Xringscript

ref userref

begin onequip
   set UserRef to GetContainer
   if userref != player
      userref.addspell J3Xringspell
   else
      userref.addspell J3Xringspell2
      message "You have gained a ability"
   end
end

begin onunequip
   set UserRef to GetContainer
   if userref != player
      userref.removespell J3Xringspell
   else
      userref.removespell J3Xringspell2
      message "You have no longer a ability"
   end
end
VERY helpful topic - Thanks for making it. fing34.gif
Thanks Feek.

OK peeps, this is my first attempt at adding some style & organization to the index, let me know if you hate it. wink_smile.gif
Objective: Menu Template (MessageBox) for lazy people like me

CODE
Scriptname aaaMenu

short Choice
short Chosen

Begin OnActivate

    if IsActionRef Player

        MessageBox "Template", "Button00", "Button01", "Button02", "Button03", "Button04", "Button05", "Button06", "Button07", "Button08", "Cancel"

        set Chosen to 1

    endif

End

Begin GameMode; or use MenuMode

    if Chosen
    
        set Choice to getButtonPressed

        if Choice > -1

            set Chosen to 0

            if Choice == 0
                ResultingCode

            elseif Choice == 1
                ResultingCode

            elseif Choice == 2
                ResultingCode

            elseif Choice == 3
                ResultingCode

            elseif Choice == 4
                ResultingCode

            elseif Choice == 5
                ResultingCode

            elseif Choice == 6
                ResultingCode

            elseif Choice == 7
                ResultingCode

            elseif Choice == 8
                ResultingCode

            elseif Choice == 9
                Return

            endif

        endif

    endif

End
Switch gamemode to menumode tongue.gif

Good Job Felic!!! smile.gif
Just a little bump to simulate a sticky!
Bound Arrows Tutorial

From The Elder Scrolls Construction Set Wiki - Written by Logam

Hi,

We all know that bound arrows are not included in the original oblivion esm. And being an archer with hundreds of arrows can add a bit of weight to your maximum weight limit. This tutorial requires:

CODE
Basic Scripting Knowledge
Fair Knowledge of the TES Construction Set


I am going to teach you how to create a mod which will add the spell bound arrows to your character so that you do not need to carry lots of arrows around.

Let Us Start::

1. Open up the Construction Set and load up the Oblivion esm.

Creating the items for the scripts:

Firstly, go to the objects window and select ITEMS then AMMO the click DAEDRIC. Next, right click on
CODE
arrow8daedric
and click edit.

This should bring up the arrows properties...

Next, we edit the properties so change the following things to the same as i have.

CODE
ID - aaaBoundArrow (aaa so that it is at top of list)
Name - Bound Arrow Enchantment - NONE
Make sure that IgnoresNormalWeaponResistance is ticked
Weight - 0
Value - 0
Speed - Leave as it is
Damage - 20


Click OK and if it asks to create new form ID then click OK!!!

Hold mouse over arrow to get a code that has a combination of numbers and letters. Write it down.

Go to the MAGIC tab in the object window, then SPELL and then SPELL again...

Create a new spell by right clicking on an spell and click NEW.

Make sure the spell properties are as the following.

CODE
ID - aaaBoundArrowsSpell
Name - Bound Arrows
Make sure every box is ticked except Area Effect Ignore LOS
Make sure auto calculate is unchecked and put spell level NOVICE and spell cost 30.
Click OK and then say OK to the create new form ID box...


Hold mouse over spell to get a code that has a combination of numbers and letters right that down.

NOW FOR THE SCRIPTS -

Go to gameplay - edit scripts - then click on script and new.

Type the following in to the box.

CODE
scn aaaBoundArrowSpellScript

Begin ScriptEffectStart

    PlayMagicVisualShaders SummonMythicDawn 5
    player.additem 'arrows code' 50
    player.equipitem 'arrows code' 50
End

Begin ScriptEffectFinish

    player.unequipitem 'arrowscode'
    player.removeitem 'arrows code' 50
End


EQUIPPING THE SCRIPT TO THE SPELL -

Now go back to the spell we made and right click then edit it again... On the right it should have a box that says 'effects'.

Right click in the box and click new.

Change the Effect to Script Effect.'Keep range as self and make duration 30 seconds, this will make it so the spell will cast on the player and last for 30 seconds before removing the bound arrows.

Change script to aaaBoundArrowSpellScript Change Script Name to Bound Arrow Change school to Conjuration Visual Effect to bound bow
Then un-check the effect is hostile box.

Click OK and then save the mod as BoundArrowSpellMod. Load up the game without any mods except our arrow mod. When in the game open the console by pressing ~ and type:

CODE
player.addspell 'spell code' and then press enter.


You have just created your own spell mod that adds magic arrows through a spell, good work and happy modding.

--------------------------------------------------------------------------------

CODE
this spell code looks like this: yyxxxxxx.

yy is used to reference the plugin, xxxxxx to reference the item inside the plugin (and does not change), in this case its the xxxxxx of the editorid of the spell. yy changed depending on your mod load order, if its the first loaded its 01, second 02... (remember that this coding is in Hex!)


--------------------------------------------------------------------------------
Objective: Soulgem soulevel detection Script

A script that detects the soul level from a soulgem, request OBSE 0.9a

The soullevels:
CODE
0:    None
1:    Petty
2:    Lesser
3:    Common
4:    Greater
5:    Grand - Humanoid


Example Script:
CODE
ref yoursoul
short soullevel

set soullevel to GetSoulLevel yoursoul

if soullevel == 5
   message "You have stealed a humans soul!"
   modpcinfamy 2
  ; Do thing
elseif soullevel > 0
   message "It's just a normal soul"
else
   message "No soul in the soulgem"
endif
Objective: Mark & Recall Teleportation Spells

Make two spells that allow you to mark a spot that you can return to via the recall spell from anywhere in the game.

Thanks to weasel93 for the script.

Place a teleport marker somewher in Tamriel and give it a Reference ID (let's use "aaaMarkRecallTeleport").
Create a "Mark" spell and attatch this script via Script Effect (and give it a cool visual effect):

CODE
Scn aaaMarkSpellScript

Begin ScriptEffectStart
    aaaMarkRecallTeleport.MoveTo player
    MessageBox "You have marked this location."
End


Then make a "Recall" spell and attatch this script to it:

CODE
Scn aaaRecallSpellScript

Begin ScriptEffectStart
    Player.MoveToMarker aaaMarkRecallTeleport
End


Fini!
Hey Felic, I changed the title of my first post (Avoiding remove item....) to a more general title. Could you please update the head post to reflect it. Thanks.

p.s. I did so after finally finding some conformation deep in the bowels of the wiki.
About the Bound Arrow spell: you don't need to use the Form ID within scripts, use the Editor ID instead.
QUOTE(pwijnands @ Feb 11 2007, 07:04 AM) *

About the Bound Arrow spell: you don't need to use the Form ID within scripts, use the Editor ID instead.


I wrote that tutorial about 1 week after i started modding tongue.gif
QUOTE(Logam @ Feb 10 2007, 10:16 PM) *

I wrote that tutorial about 1 week after i started modding tongue.gif


That's not bad after 1 week of scripting experience.
QUOTE(Logam @ Feb 10 2007, 04:16 PM) *

I wrote that tutorial about 1 week after i started modding tongue.gif


Hmm... same here, odd. Did we scare away the vanguards? Please come back! I'm tired of noticing the mistakes in my code myself (they're minor! but still there).
QUOTE(haama @ Feb 11 2007, 08:09 AM) *

Hmm... same here, odd. Did we scare away the vanguards? Please come back! I'm tired of noticing the mistakes in my code myself (they're minor! but still there).


Haama, can you please explain what you are saying???

I can't figure out what you mean by your previous post blush.gif
QUOTE(Logam @ Feb 10 2007, 09:32 PM) *

Haama, can you please explain what you are saying???

I can't figure out what you mean by your previous post blush.gif


Oh, and I came here to post a snippet request. The best I remember I meant that it's kind-of odd that only 5 people have posted anything so far. More snippets or even comments on snippets would be much appreciated! Anyway, on to buisness:

I'd like to request a snippet that has an item find the nearest object along it's front/back axis, orients itself to the face of that object, and plants itself on that object. For me, I'm trying to allow players to construct their own desks by placing drawer face plates onto the surface (hopefully the side surface). Thanks in advance. If no one has anything like this, then expect to see it here in a few weeks.
Felic can i link this thread in my Modders Resource???
Yes, I said that in my last post in your ModRes thread.
Went on a very awkward vacation, don't ask why we did it in Febuary cuz I don't know, but I'm back now smile.gif

B.T.W, why do you change your sig like, every other week logam.
QUOTE(Comandra @ Feb 15 2007, 11:25 PM) *

Went on a very awkward vacation, don't ask why we did it in Febuary cuz I don't know, but I'm back now smile.gif

B.T.W, why do you change your sig like, every other week logam.


I do it for a bit of change i guess tongue.gif

Same with my avatar... 24.gif

Felic, i added your thread to Modders Resource. smile.gif
I'm busy collating all there is in the wiki and the forums into a word document at the moment, at present time it's almost all links to either the wiki, this forum, or one other site i managed to find during a web trawl.

BTW, I can't seem to tell if this Word Document is Macro'd or not, so I'll save it once as a word document, and once as an Open Office Document. DL either, and if you wish to email me, I'll open up my gmail addy on request (I'm weary of spammers...)
Please use PDF, I'll convert for you...

EDIT: NVM, found it. Dizzy from all the threads... wacko.gif
QUOTE(Felic @ Feb 19 2007, 04:26 PM) *

Please use PDF, I'll convert for you...


It turns out that Open Office will do it gladly smile.gif It's the second last one down. Also, if you *do* have word (or open Office) and you want to contribute, simply edit away biggrin.gif

Making the thing you want as a title a heading 1 will have the biggest title in the Table of contents.
A Heading 2 will be the Second Biggest
And a heading 3 will be a side title.

Imagine a large book with many mini-stories in it. The mini-story is the Story, Heading 2 the Chapter and heading 3 the.... page?

All similarity is lost, will take some headache tablets now tongue.gif
No worries, I got years of experience as a temp and web developer, so can create stylesheets in word in my sleep, I just hate it.
Cool, I just do whatever the teacher tells me to tongue.gif but needless to say, I'm learning all the time eh?
Objective: Making a realistic creature statue when you don't know 3D modeling

NOTE: I edited this as I found it doesn't really work with NPCs, just creatures.

Thanks to Reznod for a lot of ideas and solutions!

Wanna make a custom statue, or stuffed actor laugh.gif, for your über house mod? Cool, but before we get started, there's one drawback with this method: the animation plays when the player enters the cell, so you have to place the statue out of the PoV the player has when they enter the cell. Around a corner, in an alcove, or something along those lines.

OK, there are several steps to be taken here. First, pick your creature and dupe it. Check No Low Level Processing, remove any packages from the AI, remove Factions and any unnecessary Inventory and Spells. Then pick your spot, maybe add a pedestal of some sort, and position your statue.

Now let's build the scripts. One thing we need to take care of is disabling the Detect Life visuals on the statue. This is done via an Ability with Script Effect. So first create a new script, and select Magic Effect in the drop down menu at the top. Then enter this code and save.

CODE
Scn aaaStatueDDLV

Begin ScriptEffectUpdate

    StopMagicShaderVisuals LifeDetected

End


Now create a new spell with ID aaaStatueAb and Type Ability (name it what you want). Check the options Disallow Spell Absorb/Reflect, Script Effect Always Applies, and Immune to Silence just to be safe. Now right-click in the Effects and choose Script Effect. Select the Script we just created and uncheck Effect is Hostile (you can also give it a name if you want). Add this spell to your statue's spell list.

OK, now the script that plays an animation group and freezes the creature in place. You'll need to pick an animation group. There's a complete list here (note most creatures don't have all of these: you can see the groups available for the actor you're using in their Animation tab). You're also going to have to experiment a little to get the exact pose you want by changing the timer check value. In this script, you will also have to change the 0 values for the setPos x,y,z,angle lines to the position you chose for your actor (double-click on the actor in the Render Window to get these values; it's best to round them). So create a new script (using default Object type), and paste in this code (you can remove the comments), then change the values as mentioned just above:

CODE
Scn aaaNoMoveScript

Float Timer
Short doOnce

Begin onLoad

; resets timer for current cell load
    set Timer to 0

; resets var for current cell load, so setRestrained/setGhost aren't called every frame
    set doOnce to 0

; need to input values for these or else actor will spawn in between path grid nodes
    setPos x 0
    setPos y 0
    setPos z 0
    setAngle z 0

; turn on for weapon drawn anim; use 0 for no weapon drawn
    SetAlert 1

; pick group from list provided
    PlayGroup AttackForwardPower, 1

End

Begin GameMode

; change value for desired pose
    if ( Timer < 0.5 )

; this increments timer var to be able to stop anim
        set Timer to ( Timer + GetSecondsPassed )

    else

; these only need to be set once when player enters cell
        if doOnce == 0

            set doOnce to 1

; Unconscious actors do not "think" at all; this is not absolutely necessary, but can't hurt
            setUnconscious 1

; Restrained actors will not move from their current position, but will continue to "think" (pick packages, run detection so they could yell alarms) & go into dialogue
            setRestrained 1

; no combat, not harmed by hits/spells, will talk, cannot be pickpocketed
            setGhost 1

        endif

; causes the current animation to not be played for this frame
    skipAnim

    endif

End


Now attach this script to your statue by opening the actor window and selecting the script from the drop down menu. Go in the game and check the result, and adjust the Anim Group and Timer stop value to get the pose you want.

Fini!
This is definitely going into the tutorial section happy.gif. Very cool Felic.
Objective: Locking items in place

Do you want to place a weapon or shield on the wall and it keeps falling down in game when you get near it? Or do your books fly out of whack coz you placed them like they should look on a shelf but the Havok engine doesn't account for that? Try attaching this script to a dupe of the object (you don't want to lock all the same objects in the game; also does not work on actors, see the tutorial on making a statue in this thread for that).

CODE
Scn aaaNoMoveScript

Float MyX
Float MyY
Float MyZ
Float MyAx
Float MyAy
Float MyAz

Begin onLoad

    Set MyX to GetPos X
    Set MyY to GetPos Y
    Set MyZ to GetPos Z
    Set MyAx to GetAngle X
    Set MyAy to GetAngle Y
    Set MyAz to GetAngle Z

    setPos x MyX
    setPos y MyY
    setPos z MyZ
    setAngle x MyAx
    setAngle y MyAy
    setAngle z MyAz

End
Neat trick. Now I ask, is there a way to do the same to npc's? Like a ragdoll poser or something? That'll be a fun thing to add.
It's the previous tutorial, see just above.
No, when I mean pose them, I mean "grab their leg and freeze it" Then move their arm and freeze it. What I want is to make them statues in-game. If possible, they should be unlockable. Basically the it's going to be a Gmod posergun.
Ah, I see now. Don't think that's possible, since the skeleton is a single mesh. Actors in Charge and Rez's Mannequins both use animation files (.kf) to pose actors.
Hmm, I might have a look at them...
QUOTE(Felic @ Feb 10 2007, 10:26 AM) *

Objective: Mark & Recall Teleportation Spells

Make two spells that allow you to mark a spot that you can return to via the recall spell from anywhere in the game.

Thanks to weasel93 for the script.

Place a teleport marker somewher in Tamriel and give it a Reference ID (let's use "aaaMarkRecallTeleport").
Create a "Mark" spell and attatch this script via Script Effect (and give it a cool visual effect):

CODE
Scn aaaMarkSpellScript

Begin ScriptEffectStart
    PlaceAtMe aaaMarkRecallTeleport 1, 0, 0
    MessageBox "You have marked this location."
End


Then make a "Recall" spell and attatch this script to it:

CODE
Scn aaaRecallSpellScript

Begin ScriptEffectStart
    Player.MoveToMarker aaaMarkRecallTeleport
End


Fini!


Can you use PlaceAtMe with references? I always thought it would have to be an Object ID, not a unique reference. It's probably safer to use a MoveTo command:
CODE

Begin ScriptEffectStart
    aaaMarkRecallTeleport.MoveTo player
    MessageBox "You have marked this location"
End
Right, thanks for the heads up, I'll fix that.
QUOTE
QUOTE(Felic @ Feb 26 2007, 05:18 PM)

Hey Logam, I'll bump yours if you bump mine!


Official Requested Bump tongue.gif

Good Thread Felic, Keep up the great work! ^__^
Objective: Wearing an Amulet that makes Wildlife (or anything) Passive towards you

=============================================================
Works great to make certain animals not attack you when worn.
=============================================================

1. Create 'Spell' called 'HeroPeaceAbility' that is an ability. Give it effects if you like.
-Example: Resist disease @ 100%

2. Create a 'Faction' called 'HeroPredators'.
- Give it a name, 'Peaceful Wildlife'.
- In the 'Interfaction Relations' box, add the 'HeroPredators' and make the Disposition Modifier '100'.

3. Add the new faction 'HeroPredators' to all the creatures you want to be passive when the amulet is worn.

4. Create a new Script:
CODE

scn HeroAmuletPeaceScript
begin OnEquip player
    Player.SetFactionRank HeroPredators 0
    Player.AddSpell HeroPeaceAbility
end
begin OnUnequip player
    Player.SetFactionRank HeroPredators -1
    Player.RemoveSpell HeroPeaceAbility
end


5. Create a new amulet Items+Clothing+Amulets.
- Give it an ID, Name, add the script 'HeroAmuletPeaceScript', value, and make sure it is checked playable.

6. Drop the amulet into the gameworld where you want to pick it up.
Thanks WillieSea. Added it to the index. smile.gif
Right, so I've written my own Mark/Recall spells using the information here. Took me a while to figure out how to make the doors, and make them invisible, and make them non-usable except for the spells, but I did it. Maybe there's a magical "place teleport reference here" button, but I couldn't find it. sad.gif

Now I just need to figure out how to disable changes to the weather when I recall (and re-enable them afterwards, I think). ><

After that I'm gonna write myself a bound arrows spell too. I'd been thinking along those lines recently and then I saw someone else's thread about it. smile.gif Thanks for the great info here guys!