| 06-16-2009, 04:09 PM | #1 |
Basically a GroupUtils, but with forces instead: Library:library GroupUtils globals //* Group for use with all instant enumerations group ENUM_FORCE = CreateGroup() //* Temporary references for GroupRefresh private boolean Flag = false private force Refr = null //* Assorted constants private constant integer MAX_HANDLE_COUNT = 408000 private constant integer MIN_HANDLE_ID = 0x100000 //* Arrays and counter for the group stack private force array Forces private integer array Status[MAX_HANDLE_COUNT] private integer Count = 0 endglobals private function H2I takes handle h returns integer return h return 0 endfunction private function AddEx takes nothing returns nothing if Flag then call ForceClear(Refr) set Flag = false endif call ForceAddPlayer(Refr, GetEnumPlayer()) endfunction function GroupRefresh takes force f returns nothing set Flag = true set Refr = f call ForForce(Refr, function AddEx) if Flag then call ForceClear(f) endif endfunction function NewForce takes nothing returns force if Count == 0 then set Forces[0] = CreateForce() else set Count = Count - 1 endif set Status[H2I(Forces[Count])-MIN_HANDLE_ID] = 1 return Forces[Count] endfunction function ReleaseForce takes force f returns boolean local integer stat = Status[H2I(f)-MIN_HANDLE_ID] if f == null then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Null forces cannot be released") return false elseif stat == 0 then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Force not part of stack") return false elseif stat == 2 then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Forces cannot be multiply released") return false elseif Count == 8191 then debug call BJDebugMsg(SCOPE_PREFIX+" Error: Max forces achieved, destroying force") call DestroyForce(f) return false else call ForceClear(f) set Forces[Count] = f set Count = Count + 1 set Status[H2I(f)-MIN_HANDLE_ID] = 2 endif return true endfunction endlibrary |
| 06-16-2009, 04:39 PM | #2 |
You mean a group of forces ? Well, I know 1 thing, this uses the return bug. Having in mind patch 1.23b will be out sooner or later, I advise you to find another solution that doesn't use it ... Meanwhile... personally I intend to make a "StructGroup" ... so I think this may be useful for some people, however I don't need it right now. Seems more useful then the Integer to Roman Script Vex made xD |
| 06-16-2009, 04:59 PM | #3 | ||
Quote:
Quote:
@OP: I don't know if forces feature the same bugs and leaks as groups but if they do then I could imagine this library to be quite useful actually. |
| 06-16-2009, 06:11 PM | #4 | |
Quote:
|
| 06-16-2009, 07:21 PM | #5 |
This script would not be useful because: * There are very few times when forces have to be created dynamically. * Refreshing forces is useless, since players can't be destroyed. |
