Optimizing this script

Post » Sat Jul 05, 2014 11:23 pm

I have a script attached to a quest that will, all in all, prevent the player from looting things in combat and allow them some options when activating downed essential NPCs.

However, I have one problem (there must be a better way to figure out if an actor is a downed essential NPC -- GetKnockedState returns 0 and not 1 when the NPC is ragdolled upon KO) and otherwise muse that there must be a more optimal means of handling this than a GameMode block running at short intervals.

Here's the script:

Spoiler

scn PSLootScriptref Crosshairref MyIDfloat fQuestDelayTimefloat Timerfloat Bountyfloat Dispfloat Healthshort Timedshort Buttonshort Lootingshort LootEssentials ;If 0, the ability to loot essential actors is disabled.short NoCombatLoot ;If 0, the inability to loot while in combat is disabled.short ShowMessages ;If 0, no messages when trying to loot while in combat.ref Keyref LinkedDoorbegin Menumode 1008 if (Looting != 2)  RETURN else  if (Timer > 0)   set Timer to Timer - GetSecondsPassed   RETURN  else   PSEssentialInventoryChestRef.RemoveAllItems Crosshair   Crosshair.Resurrect 1   CloseAllMenus   if (Crosshair.IsActorEvil == 0)    set Bounty to (GetGameSetting iCrimeGoldPickpocket - GetGameSetting iCrimeGoldTrespass)    Player.ModCrimeGold Bounty    Crosshair.SendTrespassAlarm Player   endif   set Disp to (GetGameSetting fCrimeDispPickpocket - GetGameSetting fCrimeDispTresspass)   Crosshair.ModDisposition Player Disp   Crosshair.SayTo Player Pickpocket  endif endifendbegin Gamemode if (Timed == 0)  set fQuestDelayTime to 0.001  set Timed to 1 endif if (GetGameRestarted == 1)  if (FileExists "Data\ini\Looting Mechanics Overhaul.ini" == 1)   RunBatchScript "Data\ini\Looting Mechanics Overhaul.ini"  endif endif if (Looting == 2)  PSEssentialInventoryChestRef.RemoveAllItems Crosshair  Crosshair.AddItem PSEssentialEquipObject 1  Crosshair.EquipItem PSEssentialEquipObject  Crosshair.RemoveItem PSEssentialEquipObject 1  set Looting to 0 endif if (OnControlDown 5 == 1)  set Crosshair to (GetCrosshairRef)  if (Crosshair == 0)   RETURN  elseif (Player.IsInCombat == 1) && (NoCombatLoot == 2) && (Crosshair.GetLocked == 1) && (Crosshair.IsDoor == 0)   CloseAllMenus   if (ShowMessages == 1)    Message "You cannot pick locks when enemies are nearby."   endif  elseif (Player.IsInCombat == 1) && (NoCombatLoot == 2) && (Crosshair.GetLocked == 1) && (Crosshair.IsDoor == 1)   set Key to Crosshair.GetOpenKey   if (Key == 0) ;check linked door    set LinkedDoor to Crosshair.GetLinkedDoor    if (LinkedDoor != 0)     set Key to LinkedDoor.GetOpenKey     if (Key != 0)      if (Player.GetItemCount Key == 0)       CloseAllMenus       if (ShowMessages == 1)        Message "You cannot pick locks when enemies are nearby."       endif      endif     else      CloseAllMenus      if (ShowMessages == 1)       Message "You cannot pick locks when enemies are nearby."      endif     endif    endif   elseif (Player.GetItemCount Key == 0)    CloseAllMenus    if (ShowMessages == 1)     Message "You cannot pick locks when enemies are nearby."    endif   endif  elseif (Crosshair.IsContainer == 1) && (Player.IsInCombat == 1) && (NoCombatLoot != 0)   CloseAllMenus   if (ShowMessages == 1)    Message "You cannot search containers when enemies are nearby."   endif  elseif (Crosshair.IsActor == 1) && (Crosshair.GetDead == 1) && (Player.IsInCombat == 1) && (NoCombatLoot != 0)   CloseAllMenus   if (ShowMessages == 1)    Message "You cannot search bodies when enemies are nearby."   endif  elseif (Crosshair.IsActor == 1) && (Crosshair.IsEssential == 1) && (Crosshair.IsInCombat == 0) && (Crosshair.HasMagicEffect PARA == 0) && (Crosshair.GetUnconscious == 0) && (Crosshair.GetIsGhost == 0) && (Crosshair != SESheogorathRef) && (Crosshair.GetKnockedState == 1) || (Crosshair.GetKnockedState == 0 && Crosshair.IsAnimPlaying == 0) ;In case of bug in engine where NPC is KO'd and knocked state is not 1.   if (NoCombatLoot != 0) && (Player.IsInCombat == 1)    if (ShowMessages == 1)     Message "You cannot search bodies when enemies are nearby."    endif    RETURN   endif   if (Crosshair.GetIssix Male == 1)    Messagebox "What will you do with him?" "Search his belongings." "Wake him up." "Finish him off." "Nothing."    set Looting to 1   elseif (Crosshair.GetIssix Female == 1)    Messagebox "What will you do with her?" "Search her belongings." "Wake her up." "Finish her off." "Nothing."    set Looting to 1   else ;Probably a creature.    Messagebox "What will you do?" "Search its body." "Wake it up." "Finish it off." "Nothing."    set Looting to 1   endif  endif endif if (Looting == 1)  set Button to (GetButtonPressed)  if (Button > -1)   if (Button == 0)    set Looting to 2    set Timer to (GetGameSetting fEssentialDeathTime)    Crosshair.RemoveAllItems PSEssentialInventoryChestRef    set MyID to (Crosshair.GetBaseObject)    PSEssentialInventoryChestRef.SetOwnership MyID    PSEssentialInventoryChestRef.Activate Player   elseif (Button == 1)    set Health to 1 - (GetGameSetting fEssentialHealthPercentReGain)    set Health to (Crosshair.GetBaseActorValue Health * Health)    set Health to (-1 * Health)    Crosshair.Resurrect 1    Crosshair.ModAv2 Health Health   elseif (Button == 2)    Crosshair.Resurrect 1 ;"Kill" doesn't work on unconscious actors for some reason...    Crosshair.SetRefEssential 0    Crosshair.kill Player    endif  endif endifend
User avatar
April D. F
 
Posts: 3346
Joined: Wed Mar 21, 2007 8:41 pm

Return to IV - Oblivion