]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapobjects/trigger/counter.qc
Improve support for per-player counters by spawning an entity to store the player...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / counter.qc
index db255ebb7aff0d80f596dfeb91cdf35a43cf988d..44cbd9045307f844f473b15e0895c4a959aebfa2 100644 (file)
@@ -5,11 +5,26 @@ void counter_reset(entity this);
 void counter_use(entity this, entity actor, entity trigger)
 {
        entity store = this;
-       if(this.spawnflags & COUNTER_PER_PLAYER) // FIXME: multiple counters in the map will not function correctly, and upon trigger reset the player won't be able to use it again!
+       if(this.spawnflags & COUNTER_PER_PLAYER)
        {
                if(!IS_PLAYER(actor))
                        return;
-               store = actor;
+               entity mycounter = NULL;
+               IL_EACH(g_counters, it.realowner == actor && it.owner == this,
+               {
+                       mycounter = it;
+                       break;
+               });
+               if(!mycounter)
+               {
+                       mycounter = new_pure(counter);
+                       IL_PUSH(g_counters, mycounter);
+                       mycounter.owner = this;
+                       mycounter.realowner = actor;
+                       mycounter.reset = counter_reset; // NOTE: this may be useless as the player deletes their counters upon respawning
+                       mycounter.counter_cnt = 0;
+               }
+               store = mycounter;
        }
 
        store.counter_cnt += 1;
@@ -27,8 +42,8 @@ void counter_use(entity this, entity actor, entity trigger)
 
                if(this.respawntime)
                {
-                       setthink(this, counter_reset);
-                       this.nextthink = time + this.respawntime;
+                       setthink(store, counter_reset);
+                       store.nextthink = time + this.respawntime;
                }
        }
        else