SERVER: Only allow one player to hold the Wunderwaffe DG-2 at a time

This commit is contained in:
cypress 2023-09-14 20:56:59 -04:00
parent b374fdcfca
commit 6d03beca80
3 changed files with 41 additions and 4 deletions

View file

@ -420,6 +420,7 @@ var struct mbox_struct
float weapon_id; // ID for the relevant weapon. float weapon_id; // ID for the relevant weapon.
float allowed; // 1 for allowed, 0 for denied. float allowed; // 1 for allowed, 0 for denied.
float rarity; // 0-100 (float) percent change for obtaining. -1 for normal. float rarity; // 0-100 (float) percent change for obtaining. -1 for normal.
float already_obtained; // true if only one allowed and a client already holds it.
} mystery_box_weapons[MAX_BOX_WEAPONS] = {}; } mystery_box_weapons[MAX_BOX_WEAPONS] = {};
float mystery_box_count; float mystery_box_count;

View file

@ -135,7 +135,8 @@ float(entity user) MBOX_GetRandomBoxWeapon =
{ {
float weapon_index = rint((random() * (MAX_BOX_WEAPONS - 1))); float weapon_index = rint((random() * (MAX_BOX_WEAPONS - 1)));
float weapon_id = mystery_box_weapons[weapon_index].weapon_id; float weapon_id = mystery_box_weapons[weapon_index].weapon_id;
float weapon_allowed = mystery_box_weapons[weapon_index].allowed; float weapon_allowed = mystery_box_weapons[weapon_index].allowed &&
!mystery_box_weapons[weapon_index].already_obtained;
if (weapon_allowed == true && !Weapon_PlayerHasWeapon(user, weapon_id, true)) if (weapon_allowed == true && !Weapon_PlayerHasWeapon(user, weapon_id, true))
return weapon_id; return weapon_id;
@ -620,6 +621,22 @@ void() mystery_box_tp_spot =
mystery_box_count++; mystery_box_count++;
}; };
void() MBOX_UpdatePosessionStatus =
{
entity player = find(world, classname, "player");
while(player != world) {
for(float i = 0; i < MAX_BOX_WEAPONS; i++) {
float weapon_id = mystery_box_weapons[i].weapon_id;
mystery_box_weapons[i].already_obtained = false;
if (Weapon_PlayerHasWeapon(player, weapon_id, true) && WepDef_OnlyOneAllowed(weapon_id)) {
mystery_box_weapons[i].already_obtained = true;
}
}
player = find(player, classname, "player");
}
}
void() MBOX_Touch = void() MBOX_Touch =
{ {
entity tempe; entity tempe;
@ -654,6 +671,7 @@ void() MBOX_Touch =
self.owner = other; self.owner = other;
MBOX_PlayOpenAnimation(); MBOX_PlayOpenAnimation();
Create_Floating_Weapon(); Create_Floating_Weapon();
MBOX_UpdatePosessionStatus();
self.spins++; self.spins++;
} }
else { else {

View file

@ -4253,6 +4253,24 @@ float(float wep) GetWeaponZoomAmount =
return 0; return 0;
} }
//
// WepDef_OnlyOneAllowed(weapon)
// Returns true if server is only allowed to distribute
// this weapon to one player at a time (e.g., from Box).
//
float(float weapon) WepDef_OnlyOneAllowed =
{
switch(weapon) {
case W_TESLA:
case W_DG3:
return true;
default:
return false;
}
return false;
}
// //
// WepDef_GetWeaponIDFromName(weapon) // WepDef_GetWeaponIDFromName(weapon)
// Takes a string input and returns the weapon ID // Takes a string input and returns the weapon ID