1 #include "sv_weaponarena_random.qh"
3 // WEAPONTODO: rename the cvars
4 REGISTER_MUTATOR(weaponarena_random, true);
6 MUTATOR_HOOKFUNCTION(weaponarena_random, SetStartItems)
9 g_weaponarena_random = cvar("g_weaponarena_random");
11 g_weaponarena_random = 0;
13 g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
16 MUTATOR_HOOKFUNCTION(weaponarena_random, PlayerSpawn)
18 if (!g_weaponarena_random) return;
19 entity player = M_ARGV(0, entity);
21 if (g_weaponarena_random_with_blaster) STAT(WEAPONS, player) &= ~WEPSET(BLASTER);
22 STAT(WEAPONS, player) = W_RandomWeapons(player, STAT(WEAPONS, player), g_weaponarena_random);
23 if (g_weaponarena_random_with_blaster) STAT(WEAPONS, player) |= WEPSET(BLASTER);
26 MUTATOR_HOOKFUNCTION(weaponarena_random, GiveFragsForKill)
28 if(!g_weaponarena_random) return;
29 entity attacker = M_ARGV(0, entity);
30 entity targ = M_ARGV(1, entity);
31 float deathtype = M_ARGV(3, float);
32 entity wep_ent = M_ARGV(4, entity);
33 .entity weaponentity = wep_ent.weaponentity_fld;
35 if(targ == attacker) return; // not for suicides
37 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
38 Weapon culprit = DEATH_WEAPONOF(deathtype);
39 if(!culprit) culprit = wep_ent.m_weapon;
40 else if(!(STAT(WEAPONS, attacker) & (culprit.m_wepset))) culprit = wep_ent.m_weapon;
42 if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER)
49 static entity GiveFrags_randomweapons;
50 if(!GiveFrags_randomweapons)
52 GiveFrags_randomweapons = new_pure(GiveFrags_randomweapons);
56 STAT(WEAPONS, GiveFrags_randomweapons) = WARMUP_START_WEAPONS;
58 STAT(WEAPONS, GiveFrags_randomweapons) = start_weapons;
60 // all others (including the culprit): remove
61 STAT(WEAPONS, GiveFrags_randomweapons) &= ~STAT(WEAPONS, attacker);
62 STAT(WEAPONS, GiveFrags_randomweapons) &= ~(culprit.m_wepset);
64 // among the remaining ones, choose one by random
65 STAT(WEAPONS, GiveFrags_randomweapons) = W_RandomWeapons(GiveFrags_randomweapons, STAT(WEAPONS, GiveFrags_randomweapons), 1);
67 if(STAT(WEAPONS, GiveFrags_randomweapons))
69 STAT(WEAPONS, attacker) |= STAT(WEAPONS, GiveFrags_randomweapons);
70 STAT(WEAPONS, attacker) &= ~(culprit.m_wepset);
74 // after a frag, choose another random weapon set
75 if (!(STAT(WEAPONS, attacker) & WepSet_FromWeapon(wep_ent.m_weapon)))
76 W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker, weaponentity), weaponentity);