In UScript, it seems this isn't really a built-in concept, or at least not one I've come across.
For example, I recently wanted to execute some UScript code when any player in a match fires a shock rifle and hits any surface within a specific zone.
In an event or observer-based language, to achieve this you might write something like the following pseudocode:
Code: Select all
foreach (Level.PlayerList as Player) {
Player
.on("PrimaryWeaponFire", function(Event) {
Player.ClientMessage("You used your weapon's primary fire");
Player.ClientMessage("Your weapon was " $ Event.Weapon.Name);
})
.on("PrimaryWeaponImpact", function(Event) {
Player.ClientMessage("Your primary weapon impacted something.");
Player.ClientMessage("The impact ocurred in zone: " $ Event.Impact.Zone.Tag);
Player.ClientMessage("The impact ocurred at co-ordinates: " $ (string) Event.Impact.Location);
foreach (Event.Impact.Victims as Victim) {
Player.ClientMessage("The impact injured " $ Victim.Name);
Player.ClientMessage("It caused them " $ Victim.DamageTaken $ " damage");
}
})
}
If I understand correctly, even the first example -- triggering the message "You used your weapon's primary fire" when someone shoots -- would involve a lot of complexity such as:
• Creating a custom weapon which subclasses existing weapon(s)
• Using the `ReplaceWith` function to replace the level's existing weapons with your custom weapon(s)
• Using the `Fire()` function in your custom weapon to send the ClientMessage to the owner
But what would happen if you had multiple weapons in a map? Would you need to create new subclassed weapons for all of them just so you can observe their primary fire events?
What if the map contained a mutator which already used the ReplaceWith function to replace all the weapons with another custom weapon? Would your script just fail in that case?
So... am I completely missing something or is there just no simple way to generically and agnostically observe events like this in UScript?