No doubt somebody has used a similar method at some point, but don't recall having seen any examples like
this for Uscript. I am probably re-writing something I forgot I read the 1st time. It is so simple.....
(Let me know.) I believe this could easily be adapted to other applications.
In this case, I was needing pawns to do a RadiusActor check for other pawns in the area, both when they are 1st spawned, and
when they take damage from anything. This check had to be as efficient as possible, and I also wanted it to adjust in real
time to both the size of the map, and the number of pawns in it, and where the pawns were at.
Obviously this technique can't be used in cases when you have to find a target in every check, but it seems to adjust
to the ideal radius after only a few checks in most cases I have tested so far.
I came up with a way that requires 2 variables and 1 If statement.
1 Global variable:
Code: Select all
var float attackRadius;
1 local variable in the function you are doing the foreach RadiusActors() check.
Code: Select all
local int racnt;
Code: Select all
foreach RadiusActors(class'Pawn', aVictim, attackRadius, V)
{
if (..whatever checks on aVictim you need....)
{
racnt++;
... do all your cool stuff
}
}
Code: Select all
if (racnt == 0) attackRadius += attackRadius * 0.25; else attackRadius -= attackRadius * 0.25;
If there is a chance in your application where the attackRadius might get out of usable range, you could add
a check on the attackRadius value right after the above statement.
In testing, the value has never gotten out of range yet, but I will probably add a check before final release just to cover
unforeseen circumstances.
Check this slightly trimmed down version of a log file with the above working in real time with log statements.
3 maps, all different sizes. 1st, a very small CTF map. 2nd a large sniper type map. 3rd Good old DM-Curse][.
This is from a test of the current unreleased BadNews! v4. It is doing the above check in 2 different functions.
1. When BadNews itself spawns a monster. (The SetupMonster log entries.)
2. Whenever a monster kills something, it will look for a new victim. (The MTD log entries.)
Tests all ran with my UTSPFix gametypes, and 3 other mutators you will see in the log:
Code: Select all
Log: Game class is 'CTF_SPGame'
Log: Level is Level CTF-2on2-Crates.MyLevel
Log: Bringing Level CTF-2on2-Crates.MyLevel up for play (0)...
ScriptLog: InitGame: ?Game=UTSPFix2.CTF_SPGame?Mutator=BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG?Name=Player?Class=Botpack.TMale2?team=255?skin=SoldierSkins.blkt?Face=SoldierSkins.Othello
ScriptLog: Base Mutator is CTF-2on2-Crates.DMMutator0
ScriptLog: Mutators BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG
ScriptLog: Add mutator BN4.BN
ScriptLog: *** Initializing BadNews!
ScriptLog: Add mutator DoubleJumpUT.DoubleJumpUT
ScriptLog: Add mutator MoreBloodOS.MB
ScriptLog: MaxBleeders = 13 BleedTime = 8.312583 BDLifeSpan = 19.950453 BDDrawScale = 0.288357 SpurtLevel = 34.763248
ScriptLog: Add mutator MGP2.MG
ScriptLog: Found CTF-2on2-Crates.Armor0 at 1312.000000,863.999939,-494.575592
ScriptLog: Found CTF-2on2-Crates.Armor1 at -32.000061,-1631.999634,-497.363434
ScriptLog: Initiating local logging...
Log: Spawning new actor for Viewport WindowsViewport0
ScriptLog: Team 255
ScriptLog: Login: Player
Log: Possessed PlayerPawn: TMale2 CTF-2on2-Crates.TMale2
Init: Initialized moving brush tracker for Level CTF-2on2-Crates.MyLevel
DevAudio: Galaxy SetViewport: WindowsViewport0
ScriptLog: DJ: Keys that were changed by DoubleJumpUT can be restored by typing "restorejumpkeys" in the UT console when DoubleJumpUT is running.
ScriptLog: SetupMonster -> attackRadius: 750.000000 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 562.500000 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 421.875000 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 527.343750 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 395.507813 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 296.630859 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 222.473145 racnt: 1
ScriptLog: MTD --> attackRadius: 166.854858 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 208.568573 racnt: 0
ScriptLog: MTD --> attackRadius: 156.426422 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 117.319817 racnt: 1
ScriptLog: MTD --> attackRadius: 146.649765 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 109.987320 racnt: 1
ScriptLog: DJ: Keys that were changed by DoubleJumpUT can be restored by typing "restorejumpkeys" in the UT console when DoubleJumpUT is running.
ScriptLog: SetupMonster -> attackRadius: 82.490494 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 103.113113 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 128.891388 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 161.114227 racnt: 0
ScriptWarning: Slith CTF-2on2-Crates.Slith2 (Function Engine.Pawn.AdjustHitLocation:003A) GetAnimGroup: Sequence 'Fighter' not found in Mesh 'Slith1'
ScriptLog: MTD --> attackRadius: 120.835670 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 151.044586 racnt: 0
ScriptLog: DJ: Keys that were changed by DoubleJumpUT can be restored by typing "restorejumpkeys" in the UT console when DoubleJumpUT is running.
ScriptLog: SetupMonster -> attackRadius: 188.805725 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 236.007156 racnt: 0
ScriptLog: botmatchstep 1 done
Log: URL: Adding default option Name=Player
Log: URL: Adding default option Class=Botpack.TMale2
Log: URL: Adding default option team=255
Log: URL: Adding default option skin=SoldierSkins.blkt
Log: URL: Adding default option Face=SoldierSkins.Othello
Log: Browse: DM-Bathroom-Cow-Beta6.unr?Game=UTSPFix2.DM_SPGame?Mutator=BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG?Name=Player?Class=Botpack.TMale2?team=255?skin=SoldierSkins.blkt?Face=SoldierSkins.Othello
Log: LoadMap: DM-Bathroom-Cow-Beta6.unr?Game=UTSPFix2.DM_SPGame?Mutator=BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG?Name=Player?Class=Botpack.TMale2?team=255?skin=SoldierSkins.blkt?Face=SoldierSkins.Othello
DevAudio: Galaxy SetViewport: WindowsViewport0
Init: Shut down moving brush tracker for Level CTF-2on2-Crates.MyLevel
Log: Collecting garbage
Log: Purging garbage
Log: -0.0ms Unloading: Package CTF-2on2-Crates
Log: -0.0ms Unloading: Package Razor-ub
Log: -0.0ms Unloading: Package BN4
Log: -0.0ms Unloading: Package DoubleJumpUT
Log: -0.0ms Unloading: Package MGP2
Log: -0.0ms Unloading: Package CommandoSkins
Log: -0.0ms Unloading: Package FCommandoSkins
Log: -0.0ms Unloading: Package AmbOutside
Log: -0.0ms Unloading: Package UTcrypt
Log: -0.0ms Unloading: Package Indus6
Log: -0.0ms Unloading: Package NaliFX
Log: -0.0ms Unloading: Package skybox
Log: -0.0ms Unloading: Package DoorsAnc
Log: -0.0ms Unloading: Package DM-Agony
Log: -0.0ms Unloading: Package Crypt2
Log: -0.0ms Unloading: Package NaliCast
Log: -0.0ms Unloading: Package shanechurch
Log: -0.0ms Unloading: Package Course
Log: Garbage: objects: 30232->26026; refs: 374060
Log: Game class is 'DM_SPGame'
Log: Level is Level DM-Bathroom-Cow-Beta6.MyLevel
Log: Bringing Level DM-Bathroom-Cow-Beta6.MyLevel up for play (0)...
ScriptLog: InitGame: ?Game=UTSPFix2.DM_SPGame?Mutator=BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG?Name=Player?Class=Botpack.TMale2?team=255?skin=SoldierSkins.blkt?Face=SoldierSkins.Othello
ScriptLog: Base Mutator is DM-Bathroom-Cow-Beta6.DMMutator1
ScriptLog: Mutators BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG
ScriptLog: Add mutator BN4.BN
ScriptLog: *** Initializing BadNews!
ScriptLog: Add mutator DoubleJumpUT.DoubleJumpUT
ScriptLog: Add mutator MoreBloodOS.MB
ScriptLog: MaxBleeders = 24 BleedTime = 4.665010 BDLifeSpan = 15.785951 BDDrawScale = 0.598534 SpurtLevel = 19.076519
ScriptLog: Add mutator MGP2.MG
ScriptLog: Found DM-Bathroom-Cow-Beta6.Suits0 at 1701.930176,451.610840,-1496.899170
ScriptLog: Found DM-Bathroom-Cow-Beta6.SCUBAGear0 at 501.919952,-2830.068848,-4411.184082
ScriptLog: Initiating local logging...
Log: Spawning new actor for Viewport WindowsViewport0
ScriptLog: Team 255
ScriptLog: Login: Player
Log: Possessed PlayerPawn: TMale2 DM-Bathroom-Cow-Beta6.TMale3
Init: Initialized moving brush tracker for Level DM-Bathroom-Cow-Beta6.MyLevel
DevAudio: Galaxy SetViewport: WindowsViewport0
ScriptLog: DJ: Keys that were changed by DoubleJumpUT can be restored by typing "restorejumpkeys" in the UT console when DoubleJumpUT is running.
ScriptLog: SetupMonster -> attackRadius: 1250.000000 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1562.500000 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1953.125000 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1464.843750 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 1831.054688 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2288.818359 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2861.022949 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2145.767090 racnt: 1
ScriptLog: MTD --> attackRadius: 1609.325317 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 1206.994019 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 905.245483 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 678.934082 racnt: 1
ScriptLog: MTD --> attackRadius: 509.200562 racnt: 1
ScriptLog: MTD --> attackRadius: 636.500732 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 795.625916 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 994.532410 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 745.899292 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 932.374146 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1165.467651 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1456.834595 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1821.043213 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2276.303955 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1707.228027 racnt: 1
ScriptLog: MTD --> attackRadius: 2134.035156 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2667.543945 racnt: 0
ScriptLog: MTD --> attackRadius: 3334.429932 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2500.822510 racnt: 1
ScriptLog: MTD --> attackRadius: 3126.028076 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2344.520996 racnt: 1
ScriptLog: MTD --> attackRadius: 2930.651367 racnt: 0
ScriptLog: MTD --> attackRadius: 2197.988525 racnt: 1
ScriptLog: MTD --> attackRadius: 2747.485596 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2060.614258 racnt: 4
ScriptLog: MTD --> attackRadius: 2575.767822 racnt: 0
ScriptLog: MTD --> attackRadius: 3219.709717 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2414.782227 racnt: 1
ScriptLog: MTD --> attackRadius: 3018.477783 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 3773.097168 racnt: 0
ScriptLog: MTD --> attackRadius: 4716.371582 racnt: 0
ScriptLog: MTD --> attackRadius: 3537.278809 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 2652.958984 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 1989.719238 racnt: 1
ScriptLog: MTD --> attackRadius: 2487.148926 racnt: 0
ScriptLog: MTD --> attackRadius: 1865.361694 racnt: 4
ScriptLog: SetupMonster -> attackRadius: 2331.702148 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1748.776611 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 2185.970703 racnt: 0
ScriptLog: MTD --> attackRadius: 2732.463379 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 2049.347656 racnt: 1
ScriptLog: MTD --> attackRadius: 2561.684570 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 1921.263428 racnt: 1
ScriptLog: Game ended at 1453.576660
ScriptLog: !!!!!!!!!!!!!!! CALC END STATS
ScriptLog: SetupMonster -> attackRadius: 2401.579346 racnt: 0
ScriptLog: ProcessServerTravel: DM-Curse][.unr
Log: Server switch level: DM-Curse][.unr
Log: Browse: DM-Curse][.unr?Game=UTSPFix2.DM_SPGame?Mutator=BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG?Name=Player?Class=Botpack.TMale2?team=255?skin=SoldierSkins.blkt?Face=SoldierSkins.Othello
Log: LoadMap: DM-Curse][.unr?Game=UTSPFix2.DM_SPGame?Mutator=BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG?Name=Player?Class=Botpack.TMale2?team=255?skin=SoldierSkins.blkt?Face=SoldierSkins.Othello
DevAudio: Galaxy SetViewport: WindowsViewport0
Init: Shut down moving brush tracker for Level DM-Bathroom-Cow-Beta6.MyLevel
Log: Collecting garbage
Log: Purging garbage
Log: -0.0ms Unloading: Package FCommandoSkins
Log: -0.0ms Unloading: Package SGirlSkins
Log: -0.0ms Unloading: Package MGP2
Log: -0.0ms Unloading: Package DoorsMod
Log: -0.0ms Unloading: Package DoubleJumpUT
Log: -0.0ms Unloading: Package DM-Bathroom-Cow-Beta6
Log: -0.0ms Unloading: Package BRdmSE
Log: -0.0ms Unloading: Package SkyCity
Log: -0.0ms Unloading: Package Starship
Log: -0.0ms Unloading: Package Coret_FX
Log: -0.0ms Unloading: Package hubeffects
Log: -0.0ms Unloading: Package Slums
Log: -0.0ms Unloading: Package Scripted
Log: -0.0ms Unloading: Package AmbModern
Log: -0.0ms Unloading: Package eol
Log: -0.0ms Unloading: Package Liquids
Log: -0.0ms Unloading: Package GenIn
Log: -0.0ms Unloading: Package Pan1
Log: -0.0ms Unloading: Package BN4
Log: Garbage: objects: 30328->25332; refs: 346177
Log: Game class is 'DM_SPGame'
Log: Level is Level DM-Curse][.MyLevel
Log: Bringing Level DM-Curse][.MyLevel up for play (0)...
ScriptLog: InitGame: ?Game=UTSPFix2.DM_SPGame?Mutator=BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG?Name=Player?Class=Botpack.TMale2?team=255?skin=SoldierSkins.blkt?Face=SoldierSkins.Othello
ScriptLog: Base Mutator is DM-Curse][.DMMutator2
ScriptLog: Mutators BN4.BN,DoubleJumpUT.DoubleJumpUT,MoreBloodOS.MB,MGP2.MG
ScriptLog: Add mutator BN4.BN
ScriptLog: *** Initializing BadNews!
ScriptLog: Add mutator DoubleJumpUT.DoubleJumpUT
ScriptLog: Add mutator MoreBloodOS.MB
ScriptLog: MaxBleeders = 25 BleedTime = 4.639814 BDLifeSpan = 17.850388 BDDrawScale = 0.350416 SpurtLevel = 37.687088
ScriptLog: Add mutator MGP2.MG
ScriptLog: Initiating local logging...
Log: Spawning new actor for Viewport WindowsViewport0
ScriptLog: Team 255
ScriptLog: Login: Player
Log: Possessed PlayerPawn: TMale2 DM-Curse][.TMale4
Init: Initialized moving brush tracker for Level DM-Curse][.MyLevel
DevAudio: Galaxy SetViewport: WindowsViewport0
ScriptLog: SetupMonster -> attackRadius: 750.000000 racnt: 1
ScriptLog: DJ: Keys that were changed by DoubleJumpUT can be restored by typing "restorejumpkeys" in the UT console when DoubleJumpUT is running.
ScriptLog: DJ: Keys that were changed by DoubleJumpUT can be restored by typing "restorejumpkeys" in the UT console when DoubleJumpUT is running.
ScriptLog: SetupMonster -> attackRadius: 562.500000 racnt: 1
ScriptLog: MTD --> attackRadius: 421.875000 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 527.343750 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 659.179688 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 494.384766 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 617.980957 racnt: 0
ScriptLog: MTD --> attackRadius: 463.485718 racnt: 1
ScriptLog: DJ: Keys that were changed by DoubleJumpUT can be restored by typing "restorejumpkeys" in the UT console when DoubleJumpUT is running.
ScriptLog: MTD --> attackRadius: 579.357178 racnt: 0
ScriptLog: MTD --> attackRadius: 724.196472 racnt: 0
ScriptLog: MTD --> attackRadius: 905.245605 racnt: 0
ScriptLog: MTD --> attackRadius: 678.934204 racnt: 1
ScriptLog: MTD --> attackRadius: 509.200653 racnt: 1
ScriptLog: MTD --> attackRadius: 636.500793 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 795.625977 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 994.532471 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 745.899353 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 559.424500 racnt: 1
ScriptLog: MTD --> attackRadius: 419.568359 racnt: 1
ScriptLog: MTD --> attackRadius: 524.460449 racnt: 0
ScriptLog: MTD --> attackRadius: 655.575562 racnt: 0
ScriptLog: MTD --> attackRadius: 819.469482 racnt: 0
ScriptLog: SetupMonster -> attackRadius: 614.602112 racnt: 1
ScriptLog: SetupMonster -> attackRadius: 460.951599 racnt: 1
ScriptLog: Game ended at 754.859802
ScriptLog: !!!!!!!!!!!!!!! CALC END STATS
*Edit. In the above example, attackRadius was initalized to 1000. Probably too high, but as you can see from the log file, it doesn't matter much either....