diff --git a/source/server/defs/custom.qc b/source/server/defs/custom.qc index ed2c3c9..26e4f18 100644 --- a/source/server/defs/custom.qc +++ b/source/server/defs/custom.qc @@ -417,9 +417,10 @@ float isPowerOn; var struct mbox_struct { - float weapon_id; // ID for the relevant weapon. - float allowed; // 1 for allowed, 0 for denied. - float rarity; // 0-100 (float) percent change for obtaining. -1 for normal. + float weapon_id; // ID for the relevant weapon. + float allowed; // 1 for allowed, 0 for denied. + 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] = {}; float mystery_box_count; diff --git a/source/server/entities/mystery_box.qc b/source/server/entities/mystery_box.qc index f9f5ce3..80acf5f 100644 --- a/source/server/entities/mystery_box.qc +++ b/source/server/entities/mystery_box.qc @@ -135,7 +135,8 @@ float(entity user) MBOX_GetRandomBoxWeapon = { float weapon_index = rint((random() * (MAX_BOX_WEAPONS - 1))); 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)) return weapon_id; @@ -620,6 +621,22 @@ void() mystery_box_tp_spot = 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 = { entity tempe; @@ -654,6 +671,7 @@ void() MBOX_Touch = self.owner = other; MBOX_PlayOpenAnimation(); Create_Floating_Weapon(); + MBOX_UpdatePosessionStatus(); self.spins++; } else { diff --git a/source/shared/weapon_defines.qc b/source/shared/weapon_defines.qc index 3d58da5..64ee7dc 100644 --- a/source/shared/weapon_defines.qc +++ b/source/shared/weapon_defines.qc @@ -4253,6 +4253,24 @@ float(float wep) GetWeaponZoomAmount = 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) // Takes a string input and returns the weapon ID