Jump to content

Would like some help with a script


KingFeraligatr

Recommended Posts

I have written a script to constantly reset an actor's Essential status to "true" no matter what. I wrote it because I know people are crafty and I'm a bit paranoid about people setting the Essential status of someone I've deemed permanently Essential to "false". Now the script works well as intended, but I did it sort of sloppy. The "reset essential" part of the script is stuck in an unbreakable while loop (intentional for now) and it makes the script processed constantly. This in turn causes quite a bit of script lag. Here's the source:

Scriptname z_reset_essential extends Actor
{constantly makes an actor essential}

;can't say I like how this script works right now. It hogs other scripts' processing and slows down script proccesing in general. I'd like some help with making
;this script better. Tell me if you know a better way to make this idea work.
;actor SelfRef
int looping = 1

Event OnInit() ;continuous checking start
RegisterForSingleUpdate (1.0)
EndEvent

Event OnUpdate()
ActorBase myself = GetActorBase () as ActorBase
looping = 1
while( looping != 0 || looping == 0 );this creates the endless loop. this unbreakable while loop is intentional until I can find a better way to do this
looping = 1
if( myself.IsEssential () == false );here's the the essential check
myself.SetEssential (true)
endif
endwhile
RegisterForSingleUpdate (1.0)
EndEvent

----------------
I'd like some help optimizing the script so it doesn't hog up script processing while still achieving the effect of making an actor constantly Essential not matter what the circumstance with the script being unable to be broken. Anything you can contribute would be nice. Thank you.

Link to comment
Share on other sites

As you stated yourself, it's never a good idea to make an infinite loop. Wouldn't it be enough to check for the essential state every few seconds with OnUpdate? Your script already does this, you just need to remove the while loop.

 

Another possibilty would be to check if the actor is essential whenever he enters combat, using OnCombatStateChanged. If he's not, for whatever reason, make him essential.

Edited by Ghaunadaur
Link to comment
Share on other sites

  • Recently Browsing   0 members

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