diff --git a/source/server/entities/doors.qc b/source/server/entities/doors.qc index a6b6a75..67145d8 100644 --- a/source/server/entities/doors.qc +++ b/source/server/entities/doors.qc @@ -60,12 +60,7 @@ void() print_need_power = { if(other.classname == "player" && !other.downed) { - /*if (self.owner.message) - centerprint(other, self.owner.message); - else - centerprint(other, "Power must be activated first");*/ - - useprint (other, 8, 0, 0); + Player_UseprintWithWait(other, self, 8, 0, 0); } }; @@ -191,11 +186,7 @@ void() door_fire = { if(other.classname == "player" && !other.downed) { - /*if (self.message) - centerprint(other, self.message); - else - centerprint(other, "Power must be activated first");*/ - useprint (other, 8, 0, 0); + Player_UseprintWithWait(other, self, 8, 0, 0); return; } } @@ -258,17 +249,13 @@ if (self.state == STATE_TOP || self.state == STATE_UP) { if(other.classname == "player" && !other.downed) { - /*if (self.message) - centerprint(other, self.message); - else - centerprint(other, "Power must be activated first");*/ - useprint (other, 8, 0, 0); + Player_UseprintWithWait(other, self, 8, 0, 0); return; } } } - if (other.button7 && !(other.semi_actions & SEMIACTION_USE)) + if (Player_UseButtonPressed(other, self) && !(other.semi_actions & SEMIACTION_USE)) { other.semi_actions |= SEMIACTION_USE; if (other.points >= self.cost) @@ -311,18 +298,14 @@ if (self.state == STATE_TOP || self.state == STATE_UP) } } } - else if (!other.button7) + else if (!Player_UseButtonPressed(other, self)) { if(other.classname == "player" && !other.downed) { - /*if (!self.message) - centerprint3(other, "press use to open door for ", b = ftos (self.cost), " points\n"); - else - centerprint (other, self.message);*/ if (self.spawnflags & DOOR_DEBRIS) - useprint (other, 2, self.cost, 0); + Player_UseprintWithWait(other, self, 2, self.cost, 0); else - useprint (other, 1, self.cost, 0); + Player_UseprintWithWait(other, self, 1, self.cost, 0); return; } } diff --git a/source/server/entities/func.qc b/source/server/entities/func.qc index 17aff9a..bff06f9 100644 --- a/source/server/entities/func.qc +++ b/source/server/entities/func.qc @@ -339,7 +339,7 @@ void() button_touch = centerprint(other,ftos(self.cost)); centerprint(other,"]\n"); - if (other.button7 && !(other.semi_actions & SEMIACTION_USE)) { + if (Player_UseButtonPressed(other, self) && !(other.semi_actions & SEMIACTION_USE)) { other.semi_actions |= SEMIACTION_USE; if(other.points >= self.cost) { self.enemy = other; @@ -414,9 +414,9 @@ void() touch_ending = if (other.classname != "player" || self.activated) return; - useprint(other, 20, self.cost, 0); + Player_UseprintWithWait(other, self, 20, self.cost, 0); - if (other.button7) { + if (Player_UseButtonPressed(other, self)) { if (other.points < self.cost) return; diff --git a/source/server/entities/mystery_box.qc b/source/server/entities/mystery_box.qc index 91e34bb..6d892b0 100644 --- a/source/server/entities/mystery_box.qc +++ b/source/server/entities/mystery_box.qc @@ -668,7 +668,7 @@ void() MBOX_Touch = return; if (!self.boxstatus) { - useprint (other, 6, mystery_box_cost, 0); + Player_UseprintWithWait(other, self, 6, mystery_box_cost, 0); } if (self.boxstatus == 2 && self.owner == other) { @@ -678,10 +678,10 @@ void() MBOX_Touch = #endif // FTE - useprint (other, 7, 0, self.boxweapon.weapon); + Player_UseprintWithWait(other, self, 7, 0, self.boxweapon.weapon); } - if (other.button7 && !(other.semi_actions & SEMIACTION_USE)) + if (Player_UseButtonPressed(other, self) && !(other.semi_actions & SEMIACTION_USE)) { other.semi_actions |= SEMIACTION_USE; if (!self.boxstatus) diff --git a/source/server/entities/pack_a_punch.qc b/source/server/entities/pack_a_punch.qc index bc49f9a..de033d5 100644 --- a/source/server/entities/pack_a_punch.qc +++ b/source/server/entities/pack_a_punch.qc @@ -264,7 +264,7 @@ void() PAP_Touch = // Power is not turned on. if (self.requirespower == true && !isPowerOn) { - useprint (other, 8, 0, 0); + Player_UseprintWithWait(other, self, 8, 0, 0); return; } @@ -274,14 +274,14 @@ void() PAP_Touch = return; } - useprint (other, 12, self.cost, 5); + Player_UseprintWithWait(other, self, 12, self.cost, 5); // Player has enough points, begin Upgrade process - if (other.points >= self.cost && other.button7 && other.weapon) { + if (other.points >= self.cost && Player_UseButtonPressed(other, self) && other.weapon) { PAP_UpgradeWeapon(self, other); } // They're broke! Notify. - else if (other.button7 && other.weapon && !(other.semi_actions & SEMIACTION_USE)) { + else if (Player_UseButtonPressed(other, self) && other.weapon && !(other.semi_actions & SEMIACTION_USE)) { other.semi_actions |= SEMIACTION_USE; centerprint (other, STR_NOTENOUGHPOINTS); Sound_PlaySound(other, "sounds/misc/denybuy.wav", SOUND_TYPE_ENV_CHING, SOUND_PRIORITY_PLAYALWAYS); @@ -297,9 +297,9 @@ void() PAP_Touch = #endif // FTE - useprint (other, 7, 0, EqualPapWeapon(self.weapon)); + Player_UseprintWithWait(other, self, 7, 0, EqualPapWeapon(self.weapon)); - if (other.button7) { + if (Player_UseButtonPressed(other, self)) { entity tempe = self; self = other; Weapon_GiveWeapon(EqualPapWeapon(tempe.weapon), 0, 0); diff --git a/source/server/entities/perk_a_cola.qc b/source/server/entities/perk_a_cola.qc index 69179f6..cef07f0 100644 --- a/source/server/entities/perk_a_cola.qc +++ b/source/server/entities/perk_a_cola.qc @@ -246,7 +246,7 @@ void() touch_perk = // Power's off! Nothing to do here. if (self.requirespower == true && !isPowerOn) { - useprint (other, 8, 0, 0); + useprint(other, 8, 0, 0); return; } @@ -272,9 +272,9 @@ void() touch_perk = price = self.cost; // sequence = perk ID in client - useprint(other, 9, price, self.sequence); + Player_UseprintWithWait(other, self, 9, price, self.sequence); - if (other.points >= price && other.button7 && !(other.semi_actions & SEMIACTION_USE)) { + if (other.points >= price && Player_UseButtonPressed(other, self) && !(other.semi_actions & SEMIACTION_USE)) { Player_RemoveScore(other, price); // Play the sound of the bottle "vending" @@ -316,7 +316,7 @@ void() touch_perk = Perk_MachineGoAway(); other.semi_actions |= SEMIACTION_USE; - } else if (other.button7 && !(other.semi_actions & SEMIACTION_USE)) { + } else if (Player_UseButtonPressed(other, self) && !(other.semi_actions & SEMIACTION_USE)) { // We tried to use, but we don't have the cash.. centerprint(other, STR_NOTENOUGHPOINTS); Sound_PlaySound(other, "sounds/misc/denybuy.wav", SOUND_TYPE_ENV_CHING, SOUND_PRIORITY_PLAYALWAYS); diff --git a/source/server/entities/power_switch.qc b/source/server/entities/power_switch.qc index a826eb6..aff4f87 100644 --- a/source/server/entities/power_switch.qc +++ b/source/server/entities/power_switch.qc @@ -92,8 +92,8 @@ void() Power_Touch = entity tempe; entity old_self; - useprint (other, 10, 0, 0); - if (other.button7 && !isPowerOn) { + Player_UseprintWithWait(other, self, 10, 0, 0); + if (Player_UseButtonPressed(other, self) && !isPowerOn) { // Animate the handle programmatically. if (!(self.spawnflags & POWER_SPAWNFLAG_NOHANDLE)) diff --git a/source/server/entities/teleporter.qc b/source/server/entities/teleporter.qc index f3544cc..df6ba89 100644 --- a/source/server/entities/teleporter.qc +++ b/source/server/entities/teleporter.qc @@ -213,21 +213,21 @@ void() teleport_pad_touch = return; if (!isPowerOn) { - useprint(other, 8, 0, 0); + Player_UseprintWithWait(other, self, 8, 0, 0); return; } if (self.host.waitLink) { - useprint(other, 19, 0, 0); + Player_UseprintWithWait(other, self, 19, 0, 0); - if (other.button7) { + if (Player_UseButtonPressed(other, self)) { self.host.isLinked = true; self.host.waitLink = false; Sound_PlaySound(self, "sounds/weapons/tesla/switchon.wav", SOUND_TYPE_ENV_OBJECT, SOUND_PRIORITY_PLAYALWAYS); } } else { if (self.host.mode == 2) { - useprint(other, 18, 0, 0); + Player_UseprintWithWait(other, self, 18, 0, 0); } } } @@ -236,9 +236,9 @@ void() teleporter_link_touch = { if (!self.waitLink) - useprint(other, 17, 0, 0); + Player_UseprintWithWait(other, self, 17, 0, 0); - if (other.button7) { + if (Player_UseButtonPressed(other, self)) { local entity en; en = find(world, targetname, self.target2); @@ -253,7 +253,7 @@ void() teleport_touch = entity tempe; if (self.cooldown) { - useprint(other, 16, 0, 0); + Player_UseprintWithWait(other, self, 16, 0, 0); return; } @@ -261,7 +261,7 @@ void() teleport_touch = return; if (!isPowerOn) { - useprint(other, 8, 0, 0); + Player_UseprintWithWait(other, self, 8, 0, 0); return; } @@ -271,12 +271,12 @@ void() teleport_touch = } if (!self.cost) - useprint(other, 14, 0, 0); + Player_UseprintWithWait(other, self, 14, 0, 0); else - useprint(other, 15, self.cost, 0); + Player_UseprintWithWait(other, self, 15, self.cost, 0); - if (other.button7 && !(other.semi_actions & SEMIACTION_USE)) { + if (Player_UseButtonPressed(other, self) && !(other.semi_actions & SEMIACTION_USE)) { other.semi_actions |= SEMIACTION_USE; if (other.points < self.cost) { diff --git a/source/server/entities/traps.qc b/source/server/entities/traps.qc index f60e701..7790277 100644 --- a/source/server/entities/traps.qc +++ b/source/server/entities/traps.qc @@ -236,14 +236,14 @@ void() zapper_touch = } if (self.requirespower == true && !isPowerOn) { - useprint (other, 8, 0, 0); + Player_UseprintWithWait (other, self, 8, 0, 0); return; } if (self.state == 0) { - useprint (other, 11, self.cost, self.weapon); + Player_UseprintWithWait (other, self, 11, self.cost, self.weapon); - if (!other.button7 || (other.semi_actions & SEMIACTION_USE)) { + if (!Player_UseButtonPressed(other, self) || (other.semi_actions & SEMIACTION_USE)) { return; } diff --git a/source/server/entities/triggers.qc b/source/server/entities/triggers.qc index 1b5a3b5..1a68951 100644 --- a/source/server/entities/triggers.qc +++ b/source/server/entities/triggers.qc @@ -229,7 +229,7 @@ void() trigger_interact_touch = if (other.classname != "player" || other.downed || other.isBuying == true || !PlayerIsLooking(other, self)) return; - if (other.button7) { + if (Player_UseButtonPressed(other, self)) { if (self.noise) Sound_PlaySound(other, self.noise, SOUND_TYPE_ENV_OBJECT, SOUND_PRIORITY_PLAYALWAYS); multi_trigger(); diff --git a/source/server/entities/wall_weapon.qc b/source/server/entities/wall_weapon.qc index d5c9272..e19bd8f 100644 --- a/source/server/entities/wall_weapon.qc +++ b/source/server/entities/wall_weapon.qc @@ -165,9 +165,9 @@ void () WallWeapon_TouchTrigger = wcost = (is_pap) ? self.pap_cost : self.cost2; float wep = (is_pap) ? EqualPapWeapon(self.weapon) : self.weapon; - useprint(other, 3, wcost, wep); + Player_UseprintWithWait(other, self, 3, wcost, wep); - if (!other.button7 || (other.semi_actions & SEMIACTION_USE) || other.isBuying) { + if (!Player_UseButtonPressed(other, self) || (other.semi_actions & SEMIACTION_USE) || other.isBuying) { return; } @@ -220,9 +220,9 @@ void () WallWeapon_TouchTrigger = // Set the cost and weapon value (for useprint). wcost = (IsPapWeapon(other.weapon)) ? self.pap_cost : self.cost2; - useprint(other, 3, wcost, other.weapon); + Player_UseprintWithWait(other, self, 3, wcost, other.weapon); - if (!other.button7 || (other.semi_actions & SEMIACTION_USE) || other.isBuying) { + if (!Player_UseButtonPressed(other, self) || (other.semi_actions & SEMIACTION_USE) || other.isBuying) { return; } @@ -254,9 +254,9 @@ void () WallWeapon_TouchTrigger = if (other.grenades & 2) return; - useprint (other, 4, self.cost, self.weapon); + Player_UseprintWithWait(other, self, 4, self.cost, self.weapon); - if (!other.button7 || (other.semi_actions & SEMIACTION_USE)) + if (!Player_UseButtonPressed(other, self) || (other.semi_actions & SEMIACTION_USE)) return; if (other.points < self.cost2) { @@ -285,10 +285,10 @@ void () WallWeapon_TouchTrigger = else if (self.weapon == W_GRENADE) { if (other.primary_grenades < 4) - useprint (other, 3, self.cost2, self.weapon); + Player_UseprintWithWait(other, self, 3, self.cost2, self.weapon); else return; - if (!other.button7 || (other.semi_actions & SEMIACTION_USE)) + if (!Player_UseButtonPressed(other, self) || (other.semi_actions & SEMIACTION_USE)) return; if (other.points < self.cost) { @@ -315,8 +315,8 @@ void () WallWeapon_TouchTrigger = else if (self.weapon == W_BOWIE) { if (!other.has_bowie_knife) { - useprint(other, 4, self.cost2, self.weapon); - if (other.button7) + Player_UseprintWithWait(other, self, 4, self.cost2, self.weapon); + if (Player_UseButtonPressed(other, self)) { if (other.points < self.cost2) { centerprint(other, STR_NOTENOUGHPOINTS); @@ -345,9 +345,9 @@ void () WallWeapon_TouchTrigger = entity tempe; //centerprint(other, self.message); - useprint (other, 4, self.cost, self.weapon); + Player_UseprintWithWait(other, self, 4, self.cost, self.weapon); - if (!other.button7 || (other.semi_actions & SEMIACTION_USE)) { + if (!Player_UseButtonPressed(other, self) || (other.semi_actions & SEMIACTION_USE)) { return; } diff --git a/source/server/entities/window.qc b/source/server/entities/window.qc index 6b30d12..a4527f7 100644 --- a/source/server/entities/window.qc +++ b/source/server/entities/window.qc @@ -326,9 +326,9 @@ void() window_touch = // cypress (09 dec 2023) -- support for limited barricade health. if(self.health < self.health_delay) { - useprint (other, 5, 0, 0); + Player_UseprintWithWait(other, self, 5, 0, 0); - if(other.button7) + if(Player_UseButtonPressed(other, self)) { if(self.rebuild_time < time) { diff --git a/source/server/player/last_stand.qc b/source/server/player/last_stand.qc index 5bc9609..b646751 100644 --- a/source/server/player/last_stand.qc +++ b/source/server/player/last_stand.qc @@ -356,10 +356,10 @@ void() LastStand_TouchReviveTrigger = // No one is actively reviving the downed team mate. if (self.owner.beingrevived == false) { // Hold F to revive... - useprint(other, 13, 0, 0); + Player_UseprintWithWait(other, self, 13, 0, 0); // Kick-off the revive sequence. - if (other.button7) { + if (Player_UseButtonPressed(other, self)) { // Revive time should be significantly shorter with // Quick Revive. float revive_time = 4; diff --git a/source/server/player/player_core.qc b/source/server/player/player_core.qc index 620e180..64609f8 100644 --- a/source/server/player/player_core.qc +++ b/source/server/player/player_core.qc @@ -431,6 +431,48 @@ void() Player_UpdateProgressBar = } }; +// +// Player_UseprintWithWait(who, type, cost, weapon) +// For avoiding issues with overlapping bounding boxes for specific +// machines. +// +.entity last_looked_ent; +.float last_looked_time; +void(entity who, entity active_ent, float type, float cost, float weapon) Player_UseprintWithWait = +{ + // Small delay before we can interact with a new entity to + // mitigate overlapping bboxes causing problems. + if (who.last_looked_time >= time && active_ent != who.last_looked_ent) + return false; + + if (who.last_looked_time < time) { + who.last_looked_time = time + 0.15; + who.last_looked_ent = active_ent; + } + + if (who.last_looked_ent == active_ent) + useprint(who, type, cost, weapon); +}; + +// +// Player_UseButtonPressed(who, active_ent) +// Logic for checking if the use button is pressed +// and appropriate conditions are met for validity. +// +float(entity who, entity active_ent) Player_UseButtonPressed = +{ + // Small delay before we can interact with a new entity to + // mitigate overlapping bboxes causing problems. + if (who.last_looked_time >= time && active_ent != who.last_looked_ent) + return false; + + if (who.button7) { + return true; + } + + return false; +}; + void() PlayerJump = { if (!(self.flags & FL_ONGROUND) @@ -771,13 +813,7 @@ void() PlayerPostThink = else self.facingenemy = false; -#ifndef FTE - // 1/4 of a second is enough of a delay to not kill the effect. - player_trace_time = time + 0.25; -#else - // FTE's server rate is already slower, no real need to delay this. player_trace_time = time + 0.05; -#endif // FTE } }; @@ -862,6 +898,7 @@ void() PlayerSpawn = self.classname = "player"; self.solid = SOLID_BBOX; self.flags = FL_CLIENT; + self.last_looked_time = 0; self.onfire = false; self.fire_timeout = 0;