Noob scripting question

Post » Sat Feb 19, 2011 12:03 pm

What's the most efficient way to assign a reference variable to == ANY NPC in the game? That includes friendly's creatures, and races.

The best I can come up with, in my noobness, is to assign a string to any ObjectID, if that ID has a minimum amount of characters, do something. But that will also apply to items and such, not just NPC's.
User avatar
leigh stewart
 
Posts: 3415
Joined: Mon Oct 23, 2006 8:59 am

Post » Sat Feb 19, 2011 6:19 am

What did you have in mind?
User avatar
Conor Byrne
 
Posts: 3411
Joined: Wed Jul 11, 2007 3:37 pm

Post » Sat Feb 19, 2011 11:21 am

Good 'ol HeyYou...

Well after writing that I discovered "GetObjectType". That changes things. Because creature and NPC are options to be used.

What I want to do is easier now. The only thing I haven't come up with is how to determine a collision with the ObjectType.

What do you think? People suggested "GetDistance" earlier. That should work, but there was mention of CPU intensiveness.
User avatar
Danel
 
Posts: 3417
Joined: Tue Feb 27, 2007 8:35 pm

Post » Sat Feb 19, 2011 7:53 am

No, it's still a little finicky, because you have to include a reference in GetObjectType. I could check the distance of something to the player, set that as the reference, then determine what it is.

But how do I determine anything that is a set distance from the player? Gotta go function hunting again.
User avatar
Tiff Clark
 
Posts: 3297
Joined: Wed Aug 09, 2006 2:23 am

Post » Sat Feb 19, 2011 1:40 am

OOOOOO! OBSE Ref Walking functions FTW
User avatar
djimi
 
Posts: 3519
Joined: Mon Oct 23, 2006 6:44 am

Post » Sat Feb 19, 2011 6:44 am

Keep in mind, walking thru all references in a cell, on a regular basis, WILL be CPU intensive, and could cause slow-downs.

another alternative might be to check thru references on cell change, add a token to the folks you are concerned with, and have a script on the token checking distance to the player. If that distance closes to some tiny amount...... do whatever it is you had in mind. Might be a bit less intensive. Maybe. Perhaps........
User avatar
Gracie Dugdale
 
Posts: 3397
Joined: Wed Jun 14, 2006 11:02 pm

Post » Fri Feb 18, 2011 7:29 pm

Great. Thanks, I'll keep that in mind.

What I'm doing is adding a perk to the athletics skill that allows you to stagger enemies when you are sprinting and run into them. The sprinting perk is added on level 125. Level 150 reduces fatigue consumption from sprinting, and level 175 gives you the ability to stagger enemies.

I have the ref walking functions running only when you hit level 175, they won't run an other time. That's how I've minimized it. But I may add it to a while loop so that it only happens when sprinting. That should reduce it further...Yeah, I think that's what I'll do.
User avatar
Quick Draw III
 
Posts: 3372
Joined: Sat Oct 20, 2007 6:27 am

Post » Fri Feb 18, 2011 10:40 pm

Got a question for you, HeyYou. One small problem I have with my sprinting script is when you're done sprinting, you reduced fatigue does not regenerate like it does for everything else. I am using "ModActorValue" to reduce fatigue while sprinting. I suspect that this is why the fatigue does not regenerate. The nature of ModActorValue. How can I restore the vanilla setting if fatigue regenerating like it's supposed (using the built-in formula)?
User avatar
louise hamilton
 
Posts: 3412
Joined: Wed Jun 07, 2006 9:16 am

Post » Sat Feb 19, 2011 5:20 am

use a drain effect instead? Or, modav2? I think does what you want it to. modav2 might be better.
User avatar
LADONA
 
Posts: 3290
Joined: Wed Aug 15, 2007 3:52 am

Post » Fri Feb 18, 2011 8:13 pm

You're right, HeyYou. The combination of getfirst/nextref + getdistance slows the game down to a slideshow, even while only using it in an while loop.

It only executes while I am sprinting and it still slideshows Oblivion.

I'm going to try what you recommended now.



EDIT

You ninja'd me. ModAV2 is bugged. Doesn't work for fatigue.
User avatar
Justin Hankins
 
Posts: 3348
Joined: Fri Oct 26, 2007 12:36 pm

Post » Sat Feb 19, 2011 10:22 am

I'll try a drain spell...
User avatar
Roanne Bardsley
 
Posts: 3414
Joined: Wed Nov 08, 2006 9:57 am

Post » Sat Feb 19, 2011 11:51 am

I'm always using GetFirst/NextRef "outside" of loops per say. I noticed it causes slowdown in just about "every" situation when done in a while or foreach loop. There's just too much stuff in my game world I guess.
What I'm doing is let the script do the looping for me. Scripts run every frame (unless specified differently), so each frame I obtain the NextRef, the first time I obtain the FirstRef, and when it's done and GetNextRef returns 0, or something else invalid, I'll make it so next frame it will start with FirstRef again. This makes only 1 of these function calls per frame (or less, if I also use a timer prior to advancing into the loop each frame). It's still done scanning quite quickly, but it never causes a noticable slowdown to me.
User avatar
~Sylvia~
 
Posts: 3474
Joined: Thu Dec 28, 2006 5:19 am

Post » Sat Feb 19, 2011 6:24 am

Interesting. I noticed that when I experienced the slide show, there were a lot of NPC's around. I tried it again, with only one NPC, and the slowdown didn't happen. Both times were in a "While" loop.
User avatar
Andrew Perry
 
Posts: 3505
Joined: Sat Jul 07, 2007 5:40 am

Post » Sat Feb 19, 2011 8:05 am

The more references it has to page thru, the more of a performance hit you will see. Inside, it wouldn't be as bad either.
User avatar
Taylrea Teodor
 
Posts: 3378
Joined: Sat Nov 18, 2006 12:20 am


Return to IV - Oblivion