Homebrew
Chain Lightning charge. When reduced to 80 hit points and again at 30 hit points, an electric vial activates and pumps into the trex. During its next turn it may use its chain lightning ability Enlarge (1/day). At the start of the trex first turn, a vial breaks on its back and casts Enlarge on the trex.
Multiattack. The tyrannosaurus makes two attacks: one with its bite and one with its tail. It can't make both attacks against the same target. Bite. Melee Weapon Attack: +10 to hit, reach 10 ft., one target. Hit: 33 (4d12 + 7) piercing damage. If the target is a Medium or smaller creature, it is grappled (escape DC 17). Until this grapple ends, the target is restrained, and the tyrannosaurus can't bite another target. Tail. Melee Weapon Attack: +10 to hit, reach 10 ft., one target. Hit: 20 (3d8 + 7) bludgeoning damage. Chain Lightning. can only be used when charged You create a bolt of lightning that arcs toward a target of your choice that you can see within range. Three bolts then leap from that target to as many as three other targets, each of which must be within 30 feet of the first target. A target can be a creature or an object and can be targeted by only one of the bolts. A target must make a Dexterity saving throw. The target takes 7d8 lightning damage on a failed save, or half as much damage on a successful one. DC SAVE 14
Counterspell Vial 2/day. When a spell that targets the trex directly is cast, a vial on its back casts counterspell at 3rd level.
If you see this creature, it most likely doesn't want to be there any more than you do. It'll swing against whoever is doing the most damage. If the creature can be calmed, it may retreat but who knows how long it'll live.
Wherever the Beastmaster deems it.