X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Ft_items.qc;h=c18d704097994fee0f13e924f562c21a02e09f42;hb=daea4b84ea67263f00814befde8f387466feaa2d;hp=95f315ad2714e0cf1ddbaedac0ecf26a56e299cc;hpb=9c765062f5aa52580c1896462d9593d70550c070;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 95f315ad2..c18d70409 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -838,6 +838,87 @@ void GivePlayerFuel(entity player, float amount) GivePlayerResource(player, RESOURCE_FUEL, amount); } +void GivePlayerRandomWeapons(entity player, int num_weapons, + string weapon_names, float shells, float bullets, float rockets, + float cells, float plasma) +{ + if (num_weapons == 0) + { + return; + } + int num_potential_weapons = tokenize_console(weapon_names); + for (int i = 0; i < num_weapons; ++i) + { + RandomSelection_Init(); + for (int j = 0; j < num_potential_weapons; ++j) + { + string weapon = argv(j); + FOREACH(Weapons, it != WEP_Null, + { + // Finding a weapon which player doesn't have. + if (!(player.weapons & it.m_wepset) && (it.netname == weapon)) + { + RandomSelection_AddEnt(it, 1, 1); + break; + } + }); + } + if (RandomSelection_chosen_ent == NULL) + { + return; + } + player.weapons |= RandomSelection_chosen_ent.m_wepset; + switch (RandomSelection_chosen_ent.ammo_field) + { + case (ammo_shells): + { + if (player.ammo_shells != 0) + { + break; + } + GivePlayerResource(player, RESOURCE_SHELLS, shells); + break; + } + case (ammo_nails): + { + if (player.ammo_nails != 0) + { + break; + } + GivePlayerResource(player, RESOURCE_BULLETS, bullets); + break; + } + case (ammo_rockets): + { + if (player.ammo_rockets != 0) + { + break; + } + GivePlayerResource(player, RESOURCE_ROCKETS, rockets); + break; + } + case (ammo_cells): + { + if (player.ammo_cells != 0) + { + break; + } + GivePlayerResource(player, RESOURCE_CELLS, cells); + break; + } + case (ammo_plasma): + { + if (player.ammo_plasma != 0) + { + break; + } + GivePlayerResource(player, RESOURCE_PLASMA, plasma); + break; + } + } + } +} + float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax) { if (!item.(ammotype))