How can I tap into onUserDelete? I'm currently building a plugin that uses a table that contains rows with an 'active' field set to 1.

If an admin deletes a user from the system, I want to change this value to 0. 

I found an 'onUserDelete' event documented but can't work out where or how to use it.

Any help would be greatly appreciated!

EDIT UPDATED:

I now have this code in the init() function of my plugin controller but deleting a user does not seem to fire the code:

    parent::init();

    craft()-&gt;on('users.onDeleteUser', function(Event $event) {
        $user = $event-&gt;params['user'];

        $userId = $user-&gt;id; // ???????

        $craft-&gt;memberships_membership-&gt;cancelMembershipById($userId);
    });


Any ideas?
From the documentation on events, they follow this pattern:

craft()-&gt;on('component.eventName', function(Event $event) {
    // ...
});


So in your example, it'd be something like this and you'd want to add it to your plugin's init() method in the main plugin class.

public function init()
{
    parent::init();

    craft()-&gt;on('users.onDeleteUser', function(Event $event) {
        $user = $event-&gt;params['user'];
        $userToTransferContentTo = $event-&gt;params['transferContentTo']
    });
}


The full list of available events and the parameters they have can be found here.