Jump to content

Dynamically adding a death item to certain faction via script?


Recommended Posts

I'm a little bit new to how leveled list work, but basically I'm trying to add a custom death item to every single type of bandit. I would like to do this via script rather than manually going into every bandit entry in the NPC category and editing the drop down list.

 

I thought about using the function 'GetInFaction', but I'm having a little trouble trying to utilize it.

Edited by DavaScript
Link to comment
Share on other sites

There are many ways to do so. One I can think of is to use a dummy spell caster applying a scripted spell that checks if the "hit" NPCs are part of the bandit faction using, as you mentioned, GetInFaction and then add a token item (If they don't have one yet), which is scripted to add your item upon the containers (=NPCs) death and then remove itself.

 

This is probably one of the more difficult ways to do it, but it should provide maximum compatibility.

Edited by mixxa77
Link to comment
Share on other sites

A much easier way would be to utilize "OnDeath" event handler (and that would still have no compatibility issues).

 

I agree that this 'is' the way to do it for compatibility but not all that easy to do so cleanly - not just keep adding to loaded NPCs regardless.

What if we can't even hit 80+% NPCs in loaded cells?

Indornia does this for the custom black soul gem but makes sure to remove as NPCs go out of range. It just maintains a walking 9 cells centered on player.

Link to comment
Share on other sites

PS: The link to the documentation for OBSE Event Handlers, note the warning to use RemoveEventHandler.

I chose the immediate cells around Player as that is about as far as we can kill anything without cheating. More importantly, it is well within minimal loaded cells to ensure RemoveEventHandler gets run.

 

As you mention Leveled List, I would expect something like "AddItem LL2NPCArmorCombHeavyCuirass100, 1", as well as custom, to level to player as usual.

 

As you mention having trouble implementing GetInFaction, a number of NPCs double up on factions, for example, all BlackBowFaction are in BanditFaction.

It is not a simple case of "if endif" or "if elseif" logic.

It is a question of breaking it down into logical steps of what you want.

  • What 'Factions' is the player 'Supposed' to be killing?
  • What priority would you give those 'Factions' for 'Bonus Loot'?
  • How do you want to logically categorize in terms of loot - 'Warrior, Mage, Archer, Thief'?
  • What about || and && logic?

The other thing is 'How' to add/remove the EventHandler to NPCs within loaded cells.

If you want to work this out then kvQstBeifirDarkRunScript in Indornia could give you some clues.

 

Either way, this is a great idea and if you're stuck, feel free to message me.

 

Link to comment
Share on other sites

The OnDeath event handler sounds like a good idea, but doesn't really work well for adding death items. The reason is that it triggers after the actor properly ends up on the floor, a few seconds after the actor died. This is a problem as you could loot the actor before the item is added.
Link to comment
Share on other sites

The OnDeath event handler sounds like a good idea, but doesn't really work well for adding death items. The reason is that it triggers after the actor properly ends up on the floor, a few seconds after the actor died. This is a problem as you could loot the actor before the item is added.

I can't believe I forgot that having hit it on my latest mod.

I used GetDead due to it being instantanious.

 

The reason I don't suggest the following on player inventory item is that it can be dropped/sold regardless of Quest Item ticked.

 

Quest scripts can suffer latency, however, I think this is an optimal solution.

 

For this example I saved DaedricHelmet as NonAccumulation (Playable unticked) then again as BonusDaedricHelmet (Playable ticked).

The non playable NonAccumulation is intended to stop repeated AddItem on repeated loot per actor.

 

As Creatures and NPCs share Factions I did it as 1 function to be passed their Form Type ID

scn QstOnDeathNPCScript
;Quest called QstOnDeathNPC, priority 100, Start Game Enabled ticked.

float fQuestDelayTime

Begin GameMode
    if GetGameLoaded
        let fQuestDelayTime := 0.1
    endif

    call FnDeadActorAddItem 35 ;NPC
    call FnDeadActorAddItem 36 ;Creature
    ;call FnDeadActorAddItem 37 NO LeveledCreature is instantiated as 36
End
scn FnDeadActorAddItem

int iFormTypeID
ref refActor

Begin Function { iFormTypeID }
    
    if PlayerRef.IsInInterior
        let refActor := GetFirstRef iFormTypeID
    else
    ;___GetFirstRef FormTypeID, CellDepth - 1 resulting in local + 8 surrounding
        let refActor := GetFirstRef iFormTypeID, 1
    endif

    while refActor != 0
        if refActor.GetDead
        ;___NonAcumulation armor: Playable unticked, player can't loot ensuring bonus item(s) added once only
            if refActor.GetItemCount NonAccumulation == 0
                refActor.AddItem NonAccumulation, 1
                if refActor.GetInFaction ConjurerFaction || refActor.GetInFaction DaedraFaction
                    refActor.AddItem LL2NPCStaff100 1
                elseif refActor.GetInFaction DremoraFaction || refActor.GetInFaction BanditFaction
                    refActor.AddItem BonusDaedricHelmet, 1
                elseif refActor.GetInFaction CreatureFaction || refActor.GetInFaction VampireFaction
                    refActor.AddItem Gem4SapphireBonus 1
                endif
            endif
        endif
        let refActor := GetNextRef
    loop

End

Link to comment
Share on other sites

What was that portal thingy at 0:19 on the left side? (It is also the entrance point to my house exact at that spot... :wink:)

 

Very nice script :)

Edited by Pellape
Link to comment
Share on other sites

What was that portal thingy at 0:19 on the left side? (It is also the entrance point to my house exact at that spot... :wink:)

 

Very nice script :smile:

Thanks, I enjoy tackling challenges with CSS+OBSE.

 

The portal 'was' the starting point to my latest mod Harodich.

I 'knew' I shouldn't have put an entrance in Tamriel :facepalm:

 

Update 1.02 has portal etcetera removed with esp cleaned using TES4Edit.

It adds the spell '+Harodich Travel' for Play/Exit

  • On first enter, the start.
  • In/Out from wherever you are to wherever you were except...
  • If already inside the mod, on update, the exit defaults to Anvil main gate.
Link to comment
Share on other sites

  • Recently Browsing   0 members

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