]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Player templates: better random weapon code.
authorLyberta <lyberta@lyberta.net>
Mon, 7 Aug 2017 08:54:33 +0000 (11:54 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 7 Aug 2017 08:54:33 +0000 (11:54 +0300)
qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc

index a375d82af89b9567663833ea41055958f5fa5931..7748bf956ec2a32771622c58848383d1f52e0e0f 100644 (file)
@@ -326,24 +326,24 @@ void PlayerTemplate_PlayerSpawn(entity player, string template)
        }
        for (int i = 0; i < numrandomweapons; ++i)
        {
-               // Finding weapon which player doesn't have.
-               WepSet weaponbit = WEPSET(Null);
-               int numattempts = 0;
-               do
+               RandomSelection_Init();
+               for (int j = 0; j < numweapons; ++j)
                {
-                       string weapon = argv(floor(random() * numweapons));
+                       string weapon = argv(j);
                        FOREACH(Weapons, it != WEP_Null,
                        {
-                               if (it.netname == weapon)
+                               // Finding a weapon which player doesn't have.
+                               if (!(player.weapons & it.m_wepset) && (it.netname == weapon))
                                {
-                                       weaponbit = it.m_wepset;
-                                       break;
+                                       RandomSelection_AddEnt(it, 1, 1);
                                }
                        });
-                       ++numattempts;
                }
-               while ((player.weapons & weaponbit) && (numattempts < 10));
-               player.weapons |= weaponbit;
+               if (RandomSelection_chosen_ent == NULL)
+               {
+                       return;
+               }
+               player.weapons |= RandomSelection_chosen_ent.m_wepset;
        }
 }