From 62cdb2f1fefd9c3cd65387dbc1658b302e4ec46b Mon Sep 17 00:00:00 2001 From: Lyberta Date: Mon, 7 Aug 2017 11:54:33 +0300 Subject: [PATCH] Player templates: better random weapon code. --- .../playertemplates/sv_playertemplates.qc | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc index a375d82af8..7748bf956e 100644 --- a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc +++ b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc @@ -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; } } -- 2.39.5