WheteThunger / BetterChinookPatrol

Plugin for Rust servers that properly randomizes the order in which chinooks visit monuments
MIT License
2 stars 0 forks source link

fixes a possible out or range error #4

Closed hamilton5 closed 1 year ago

hamilton5 commented 1 year ago

in the rare event this ever happens:

[Better Chinook Patrol] 0 monuments on this map may be visited by Chinooks. 0 have drop zones.

WheteThunger commented 1 year ago

Thanks for the contribution!

Instead of exiting early in OnEntitySpawned, I suggest we just unsubscribe from the hook.

private void Init()
{
    _pluginConfig.Init(this);

    Unsubscribe(nameof(OnEntitySpawned));
}

private void OnServerInitialized()
{
    ...

    if (_eligiblePatrolPoints.Count > 0)
    {
        Subscribe(nameof(OnEntitySpawned));
    }
}

This will provide a marginal performance boost when there are no patrol points, since Oxide incurs some overhead for subscribed hooks even if they are never called, since it has to check if the signature matches the object the hook was called for.

hamilton5 commented 1 year ago

sorry I don't know a whole lot, I didn't even know that was possible. Definitely makes sense.