Ok, so I'm working on a Mod that allows for placing Map Markers via Hotkey. Works pretty fine, except for the 'remove the marker' part where I want to remove the first placed marker. It will remove exactly one marker but then no more. I can place as much markers as I have though, except with the difference that when removing one marker, the number of available markers lowers to 8 (from default 9). Here's the script, I'm leaving most of the hotkey portion out to unclutter it a bit:
Scriptname MTW_MCMQuestScript extends SKI_ConfigBaseActor Property PlayerREF AutoFormList Property MTW_MarkerFormList AutoObjectReference Property MTW_XmarkerStorage AutoMessage Property MTW_InitMessage AutoInt[] MarkerIndexArrayint ArrayLengthint MarkerCount Event OnConfigInit() MarkerIndexArray = new int[128] RegisterForMenu("MapMenu")EndEventEvent OnGameReload() Parent.OnGameReload() LockMarker()EndEvent ... Event OnKeyDown(Int aiKeyCode) If aiKeyCode == KeyMarker && !Utility.IsInMenuMode() UnregisterForKey(KeyMarker) Int iButton = MTW_InitMessage.Show() as Int If iButton == 0 PlaceMarker() ElseIf iButton == 1 RemoveMarker() EndIf Utility.Wait(0.2) RegisterForKey(KeyMarker) EndIfEndEvent Event OnMenuClose(String MenuName) If MenuName == "MapMenu" LockMarker() EndIfEndEventint Function GetFreeMarker() int zero = 0 ArrayLength = MarkerIndexArray.length MarkerCount = MTW_MarkerFormList.getSize() If (MarkerCount < ArrayLength) ArrayLength = MarkerCount EndIf While (zero < ArrayLength && MarkerIndexArray[zero]) zero += 1 EndWhile If (zero == ArrayLength) return -1 EndIf Return zeroEndFunctionFunction RemoveMarker() int MarkerIndex = MarkerIndexArray[-1] as int ObjectReference MarkerRef = MTW_MarkerFormList.GetAt(MarkerIndex - 1) as ObjectReference MarkerRef.Disable() MarkerRef.MoveTo(MTW_XmarkerStorage) MarkerIndexArray[MarkerIndex - 1] = 2 EndFunction Function PlaceMarker() If PlayerREF.IsInInterior() Debug.Notification("You can't place markers inside interiors!") Return EndIf int FreeMarkerIndex = GetFreeMarker() If FreeMarkerIndex == -1 Debug.MessageBox("No more Markers available. Free one up first!") Return EndIf ObjectReference MarkerRef = MTW_MarkerFormList.GetAt(FreeMarkerIndex) as ObjectReference MarkerRef.MoveTo(PlayerREF) MarkerRef.Enable() MarkerIndexArray[FreeMarkerIndex] = 1 EndFunction Function LockMarker() int Zero = 0 ArrayLength = MarkerIndexArray.length MarkerCount = MTW_MarkerFormList.GetSize() If MarkerCount < ArrayLength ArrayLength = MarkerCount EndIf While Zero < ArrayLength If MarkerIndexArray[Zero] == 2 ObjectReference MarkerRef = MTW_MarkerFormList.GetAt(Zero) as ObjectReference MarkerRef.MoveTo(PlayerREF) MarkerIndexArray[Zero] = 0 EndIf Zero += 1 EndWhile EndFunctionFunction RestoreValues() RegisterForKey(KeyMarker)EndFunction