const KIRI_SPRAYDISTANCE = 96; class Sprayer : HDWeapon { default { radius 2; height 4; +SpriteAngle; Scale 0.4; +hdweapon.fitsinbackpack; +weapon.wimpy_weapon; +INVENTORY.PERSISTENTPOWER; +INVENTORY.INVBAR; } states { spawn: KSPR B -1; stop; ready: KSPR A 1 { A_WeaponReady(WRF_ALL); A_WeaponBusy(false); } goto readyend; fire: KSPR A 2 { Actor spawnedThing; bool success; float zOffset = GunHeight() * 0.8; FLineTraceData lineTraceData; bool traceHit = LineTrace( angle, KIRI_SPRAYDISTANCE, pitch, flags : TRF_THRUACTORS, offsetz : zOffset, data : lineTraceData); if(traceHit) { if(lineTraceData.HitLine) { console.printf("spray spray spray"); [success, spawnedThing] = A_SpawnItemEx( "SprayerDecalSpawner", xofs : 0, yofs : 0, zofs : zOffset); if(success) { spawnedThing.A_SetPitch(pitch); spawnedThing.A_SetAngle(angle); spawnedThing.master = invoker.owner; } } } } goto waiting; waiting: KSPR A 5; KSPR A 0 A_Refire("waiting"); goto ready; } } class SprayerDecalSpawner : Actor { default { +nogravity; } states { spawn: TNT1 A 0; stop; } int timeSinceLastSpray; int thisSprayerId; override void PostBeginPlay() { Super.PostBeginPlay(); console.printf("SPRAY"); A_SprayDecal("KiriTestDecal", KIRI_SPRAYDISTANCE); // Figure out a new ID number. ThinkerIterator iter = ThinkerIterator.Create("SprayerDecalSpawner"); SprayerDecalSpawner otherSpawner; int maxId = 0; while(otherSpawner = SprayerDecalSpawner(iter.Next())) { if(otherSpawner == self) { continue; } // Keep track of the highest ID. if(otherSpawner.thisSprayerId > maxId) { if(otherSpawner.master == master) { maxId = otherSpawner.thisSprayerId; } } } thisSprayerId = maxId + 1; // Clear old sprayers. iter = ThinkerIterator.Create("SprayerDecalSpawner"); while(otherSpawner = SprayerDecalSpawner(iter.Next())) { if(otherSpawner == self) { continue; } if(otherSpawner.thisSprayerId < (thisSprayerId - 5)) { if(otherSpawner.master == master) { otherSpawner.Destroy(); } } } } override void Tick() { timeSinceLastSpray++; if(timeSinceLastSpray >= 35 * 60) { A_SprayDecal("KiriTestDecal", KIRI_SPRAYDISTANCE); timeSinceLastSpray = 0; } } }