Ok, I did a bit of testing and the bug actually has nothing to do with the detection event, it's even still there when the respective line is commented out. The problem is the token, when adding it, it seems that sometimes the actors weapon selection gets messed up. When saving/loading, the actor resets and it works again, and when removing the token and adding a different one you can actually see pretty nicely that there's something not right because this causes every actor to randomly switch weapons.
I made numerous attempts to fix this, but nothing worked yet:
- a forced unequip of the token
- changing some flags/equip slot
- changing health
- skip getGameLoaded frame
- removing and adding the token every iteration (just for fun, actually made the problem much worse)
I made a new version that uses lists instead and only adds the token once the actor is dead. I think this is better than the first approach anyway.
So additionally needed are 2 empty form lists RKRDetectionListA and RKRDetectionListB.
Modified scripts:
Quest script (execute every 3 seconds)
scn RKRMainQuestScriptshort depthref objref oldListref newListshort phaseshort size;-------------------------------------------------------------------------------------------Begin GameModeif phase == 0 set phase to 1 set oldList to RKRDetectionListA set newList to RKRDetectionListBelse set phase to 0 set oldList to RKRDetectionListB set newList to RKRDetectionListAendif; Phase 1 - Create detection events for actors that were previously alive and record still living actorsset depth to (player.isInInterior == 0)set obj to appleset obj to (getFirstRef 200 depth 0)Label 1if obj != 0 if obj.getDead == 1 if (listRemoveForm oldList obj) != -1 && obj.isKiller player == 1 ;PrintToConsole "Adding detection token" obj.addItem RKRDetectToken 1 endif else obj.listAddReference newList endif set obj to apple set obj to getNextRef goto 1endif; Phase 2 - Clear any elements left in old list so it can be reused as new listset size to (listGetCount oldList)Label 2if size > 0 listRemoveNthForm oldList 0 set size to size - 1 goto 2endifEnd
Token script:
scn RKRDetectTokenScriptfloat timershort countref actorshort start;-------------------------------------------------------------------------------------------Begin OnAddset actor to getContainerset start to 1End;-------------------------------------------------------------------------------------------Begin GameModeif start == 0 returnendifif timer > 0 set timer to timer - getSecondsPassed returnendifset timer to 10set count to count + 1;PrintToConsole "Creating detection event %.0f" countactor.createDetectionEvent player 100if count < 3 returnendifremoveMereturnEnd