Add items to a body when the player loots it.

Post » Tue Jun 19, 2012 6:34 am

Hello everyone.

Anytime the player loots a body (any corpse, not specific ones), I want to forcefully add or remove items from/to the body.

Unfortunately I encountered unexpected difficulties and here I am, seeking some help.
  • I guess I need to modify the "actor" script, am I correct ? I couldn't find any other way to add an "activation hook". Notably, the "activation" entry point for perks and spells does not allow a script to be ran, it seems restricted to the "menu before loot" like in the "blood harvest" quest in Skyrim or cannibalism in New Vegas.
  • Since the "actor" script is not bound to a quest or a spell, it seems like there is no way for me to bind the script's properties to the forms of the items to add or remove. How can I manage to retrieve the item's form from within the script ?
  • OnActivate is fired after the activation. I tried OnTrigger and OnOpen but they weren't fired. How can I run the script before the loot window pops up ?

I would really appreciate some guidance for my first steps in Skyrim's modding.
User avatar
Cat Haines
 
Posts: 3385
Joined: Fri Oct 27, 2006 9:27 am

Post » Mon Jun 18, 2012 11:11 pm

I recently had a similar problem:
I wanted to remove a certain item (overpowered scimitar) from a certain unit type (guards), and replace it with another item (normal scimitar.)

I made a script that runs when the guard dies.
I can help you with a script like that if that's what you need.
User avatar
Rachael Williams
 
Posts: 3373
Joined: Tue Aug 01, 2006 6:43 pm

Post » Tue Jun 19, 2012 1:53 am

Unfortunately my own mod must run when the player interacts with the target because it changes its appearance. However, from what I read on other posts, I guess I could use your solution to put a magic effect with the required data on the target, that would solve 1) and 2). So, yes I would appreciate more details please. :=)
User avatar
maya papps
 
Posts: 3468
Joined: Mon Aug 07, 2006 3:44 pm

Post » Tue Jun 19, 2012 12:50 am

Since I have three different type of guard units (guard, guard02 and guard03) I use a template for certain things, such as scripts.
You can either do that, or add the script to each of your guard unit.


First I edited my three guard units; under the first tab (Traits), in the bottom left corner, under "Template Data" I changed "ActorBase" to my template unit, and checked the box "Scripts". -This means that all my guard units will use the same scripts as my template unit.

Then I edit my template unit. On the first tab (Traits) just above the Template Data, there's "Scripts".
Add a script, choose [New Script], name it whatever you like.
I use "ObjectReference" under "Extends".
I left the two boxes unchecked.
"Documentation String" is just a comment for you to know what the script does, I wrote: "A simple script that will replace the Alik'r Scimitar with a normal Scimitar when a Black Market Guard dies. To prevent the player from getting one of these powerful swords."

Now right-click on your new script and choose "edit properties".
Click the "Add property" button and choose the settings most suited for you. In my case I choose: "Type: WEAPON", "Name: BM_GuardWeapon", I left the rest as it was. I then created another just like the first one, except this one I named "BM_GuardNewWeapon"
Then select your properties and to the right choose "edit value". Here I choose my two weapons - the one that the guards have in their inventory (old) and the new weapon (the one I want to replace the old with).
Click ok.

Now (in the Actor window under the Traits-tab), right-click on your script again; this time choose "Edit Source".
At the top you will most likely see:

Scriptname  extends ObjectReference  Conditional{}WEAPON Property BM_GuardWeapon  AutoWEAPON Property BM_GuardNewWeapon  Auto


Now we can finally add the code, here's what my code looks like:

Event OnDeath(Actor akKiller)RemoveItem(BM_GuardWeapon, 1, true)AddItem(BM_GuardNewWeapon, 1, true)endEvent

What it does:
1. When the actor dies:
2. Removes item (BM_GuardWeapon) - which we set under properties.
3. Adds item (BM_GuardNewWeapon) - which we set under properties.
4. Done!



My complete script looks like this:

Scriptname BM_GuardReplaceWeaponScript extends ObjectReference  Conditional{A simple script that will replace the Alikr Scimitar with a normal Scimitar when a Black Market Guard dies. To prevent the player from getting one of these powerful swords.}WEAPON Property BM_GuardWeapon  AutoWEAPON Property BM_GuardNewWeapon  AutoEvent OnDeath(Actor akKiller)RemoveItem(BM_GuardWeapon, 1, true)AddItem(BM_GuardNewWeapon, 1, true)endEvent


When you are done with the script you must save it (File -> Save) or (ctrl+s).
When the script saves it must first compile, it does this automatically so it might take a few seconds.
User avatar
Kirsty Collins
 
Posts: 3441
Joined: Tue Sep 19, 2006 11:54 pm

Post » Tue Jun 19, 2012 12:06 pm

Thank you very much, Phrosen, I really appreciate all the details you provided. Unfortunately, this cannot work for my case since the changes I want should take effect for every actor in the game and not just specific ones.

Fortunately, I noticed something : contrary to what I thought, it *is* possible to use the "activate" entry point for a perk or a spell. I just needed to check the "run immediately" and, instead of being used to create a before-loot menu, it is then used to hook a script on on activation. So, I have been able to create a perk for the player, hook a script on it with the beforementioned entry point and achieve most of what I wanted to do.

However, there is still a problem : sometimes the script does not run and instead I get a cryptic "[magicsoultrapfxscript ] is finishing". I use an auto-soul trap weapon but I have no idea why my perk conflicts with the soul trap effect. Also, I don't really know how I can solve the activation order problem, I have an idea but it's clumsy.
User avatar
Hope Greenhaw
 
Posts: 3368
Joined: Fri Aug 17, 2007 8:44 pm


Return to V - Skyrim