Jump to content

Activate traps all npc creatures and playeron distance


Recommended Posts

How can i make a script for activate a trap for all npc, creatures and the player on getdistance? I can only make it work on player getdistance, but i dont know what to put in the script for npc or creatures.

Any help please,

Link to comment
Share on other sites

For example;

If getdistance player > 200 (this is for the player)

If i want the trap react to humans or creatures,

What word i need to put in the script?

If getdistance npcref? Humans? Everybody?

Please, if someone know how to do it, helpme, thanks.

Sorry for my poor english.

Link to comment
Share on other sites

good idea the trigger box, I think it might work, what would the script for the trigger look like?

Sorry for do more questions :)

 

if triiggered == 1

activate myparent ?

 

I'll try it tomorrow. the scripts are so complicated ... Thanks for the advice, and your mods, specially Optimized VWD, it's a must have mod. Greetings.

Edited by lavatumente
Link to comment
Share on other sites

Hey lavatumente, ask questions, that's great - yes, scripting may seem complicated but it's just a matter of time, each penny will drop.

Sorry guys but a trigger won't cut the mustard. It will run hundreds of times in under a second then cut out for around 1-2 seconds - around 600-900 times/second on a pc I have here.
What if you want several traps in a room?

The way to find Actors in cell(s) is to use 'GetFirstRef 69 [n]' where Optional [n] is CellDepth, n is not used for Interior. n==1 will be 9 cells, n==2 49 cells and so on. ForEach does not apply to this btw.

69 is OBSE Form Type ID for Actor which covers NPC, LeveledCreature and Creature but not Player.

The next thing to consider is performance hit. If there is just 1 of these traps in our adjacent N E S W cells then at n==1 our pc is trying to process 21 cells worth of actors, at n==2 85 cells worth of actors -_-
Please, just use 1.
GameMode will try to run hundreds of times/second - please put a throttle on it.

 

Working example - use Console 'cow WSTrapOnDistance 0 0'.

 

Code:

scn TrapGasCloud01Script ;call this whatever

;____GameMode, a constant looping, can fire hundreds times/second on the average machine
;    fDelay used to stop this one from hogging the processor
float fDelay
ref refActor

Begin GameMode
    
    let fDelay += GetSecondsPassed ; a grain of sand in the sandpit of processing

    if fDelay < 0.2 ; processing 5 times a second is more than we need for this
        
    ;___stop wasting processor and get the heck out of this script
        return
        
    else

    ;___good practice to do this first            
        let fDelay := 0

    ;___Form Type ID 69 does not include player - even though referred to as 'Actor'
        if PlayerRef.GetDead == 0
        ;___logically same as GetSelf.GetDistance PlayerRef
            if GetDistance PlayerRef < 300
                PlayerRef.kill
            endif
        endif
        
    ;___Object.IsInInterior - Object has to be Actor and we only 'know' of player
        if PlayerRef.IsInInterior
            let refActor := GetFirstRef 69 ;logically same as GetSelf.GetFirstRef 69
        else
            let refActor := GetFirstRef 69, 1
        endif
        
        while refActor != 0
            
        ;___Don't keep killing the same actor over and over.
            if refActor.GetDead == 0
            ;___logically same as GetSelf.GetDistance Object
                if GetDistance refActor < 300
                    refActor.kill
                endif
            endif
            
            let refActor := GetNextRef ; OBSE already knows the FormTypeID (Actor) and [CellDepth]

        loop

    endif
    
End

;NOTES
;  This does not try to stop itself on PlayerRef.kill - it's not a problem
;  It does, however, make sure to ONLY KILL each Actor/Player ONCE

 

Link to comment
Share on other sites

Thanks for the answers, I will try, although I know that with obse I have more options, but I think that in the end I will use a persistent reference, so I will avoid possible problems, in any case I am very grateful for the answer, thanks glowplug. ;)
Link to comment
Share on other sites

We often need to get to the other side of the river to get water in Oblivion. It is very frustrating to not be able to target stuff immediate. The GetFirstRef, GetNextRef is used in many mods and situations like these. I will use them for my library, placing books in random dungeons but first search the dungeon with these functions and if the target is not available, then place a book at a table with Placatme and Setpos. This might cause a bloat but that ref will get deleted when you hand the book in as the original book will be a persistent ref behind an transparent collision mesh. The positive side of that loop is that is very fast. I use it to refill my wine/bottle cabinet as one example. Another example is to clean up the surroundings like the Broom in MOO. The backside of a triggerbox is that it will be kept triggering as long as something is inside it, so be very careful with how many trigger boxes you add to the game. I will use them for turning light on and off later in my library and what bothers me most now is:

  • Where shall I add the scripts? To the chairs where the NPC and I will sit? I do have 8 chairs, that's 8 triggers. A triggerbox will do the job but it might act as a bloody electric chair instead, killing the performance. :wink:
  • To the Dwemer lamps? I do have 24 lamps and what impact will 24 scripts have on the game? I do plan to add the scripts to quests but still. Will timers give higher performance? The backside of using the lamps as the trigger is that they are 3m up in the air and will look for NPC's and the player up in the bloody ceiling.
  • Light + Scripts + Collisions is a performance killer. Damn game... :wink:
  • Be very restricted with Strings as they will cause String bloats.

My Companion, the Jaguar I made not long ago use these 2 functions to get the target that the player is attacked by. I also use the cross air to add my position to the Jaguar and then the Jaguar will contact my tamed kittycat, so it use the same databases to faster get new targets. I do hate when the tamed animals do not act immediate and I do not know how to force them to act faster than they already do. To allow the Jaggy to get exp, I add the targets to a database, and array that is dynamic and I delete the array when the cell updates or the Jaggy gets the exp. I did try to use that system for the tamed Kittycat but failed so I edited the MOO esp, to force the tamed animal to get the same exp as the player. It is so frustrating to just watch that animal fight but also that it only gets 10% exp when the player kills the target. That is nuts.

 

By the way. One thing I do hate is that so many modders forget to add pathing into their mods. Companions and NPCs will walk into the walls and stop following you when they are lacking. I had to edit so many dungeons lately because of the lack of pathways and editing them is not fun at all but then the mods are not playable if you skip it. It seems that very few are using companions as otherwise they would know the problem. It is therefor I had to make a companion friendly home in the first place as there is none as far as I know.

Edited by Pellape
Link to comment
Share on other sites

We often need to get to the other side of the river to get water in Oblivion. It is very frustrating to not be able to target stuff immediate. The GetFirstRef, GetNextRef is used in many mods and situations like these. I will use them for my library, placing books in random dungeons but first search the dungeon with these functions and if the target is not available, then place a book at a table with Placatme and Setpos. This might cause a bloat but that ref will get deleted when you hand the book in as the original book will be a persistent ref behind an transparent collision mesh. The positive side of that loop is that is very fast. I use it to refill my wine/bottle cabinet as one example. Another example is to clean up the surroundings like the Broom in MOO. The backside of a triggerbox is that it will be kept triggering as long as something is inside it, so be very careful with how many trigger boxes you add to the game. I will use them for turning light on and off later in my library and what bothers me most now is:

  • Where shall I add the scripts? To the chairs where the NPC and I will sit? I do have 8 chairs, that's 8 triggers. A triggerbox will do the job but it might act as a bloody electric chair instead, killing the performance. :wink:
  • To the Dwemer lamps? I do have 24 lamps and what impact will 24 scripts have on the game? I do plan to add the scripts to quests but still. Will timers give higher performance? The backside of using the lamps as the trigger is that they are 3m up in the air and will look for NPC's and the player up in the bloody ceiling.
  • Light + Scripts + Collisions is a performance killer. Damn game... :wink:
  • Be very restricted with Strings as they will cause String bloats.

My Companion, the Jaguar I made not long ago use these 2 functions to get the target that the player is attacked by. I also use the cross air to add my position to the Jaguar and then the Jaguar will contact my tamed kittycat, so it use the same databases to faster get new targets. I do hate when the tamed animals do not act immediate and I do not know how to force them to act faster than they already do. To allow the Jaggy to get exp, I add the targets to a database, and array that is dynamic and I delete the array when the cell updates or the Jaggy gets the exp. I did try to use that system for the tamed Kittycat but failed so I edited the MOO esp, to force the tamed animal to get the same exp as the player. It is so frustrating to just watch that animal fight but also that it only gets 10% exp when the player kills the target. That is nuts.

 

By the way. One thing I do hate is that so many modders forget to add pathing into their mods. Companions and NPCs will walk into the walls and stop following you when they are lacking. I had to edit so many dungeons lately because of the lack of pathways and editing them is not fun at all but then the mods are not playable if you skip it. It seems that very few are using companions as otherwise they would know the problem. It is therefor I had to make a companion friendly home in the first place as there is none as far as I know.

I agree with you very much Pellape. In addition, I find it frustrating when testing my mod against others, that I have to waste my time rewriting their code in order to do so.

 

If anyone looks at my code, they may well think "why does glowplug use so many functions?"...

  1. Readability
  2. Factoring
  3. Reuse - the rule of 'write it once'
  4. Function variables are not stored in the save game.

As far as 4, it can be used to avoid string bloat. Now, a thing to consider might be allocation time. Local is once, Function is every loop, right?

Testing on tens of thousands of loops I can find no difference in performance.

Remember, it is an Interpretor which will allocate 'As and When' - correct me if I am wrong.

 

You mentioned PlaceAtMe bloat which is something I don't use.

I usually keep a utilities cell with any objects that would otherwise have to be instantiated.

In testing I've used PositionCell, PositionWorld and SetPos on these objects within thousands of loops with no noticable change in save game size. I would expect this as an object's Transform is a matter of bytes - again, correct me if I am wrong.

Link to comment
Share on other sites

  • 1 month later...

Sorry for writing something late, but I want to thank you for your help, I finally got it !. Thank you all very much for your time and sharing your wisdom.

a cordial greeting.

Here is the mod

https://www.nexusmods.com/oblivion/mods/51467

Edited by lavatumente
Link to comment
Share on other sites

  • Recently Browsing   0 members

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