Warnings module

Control Module - Warnings - Adds a way to give and remove warnings to players.

Usage


    -- This will add a warning to the player
    Warnings.add_warning('MrBiter','Cooldude2606','Killed too many biters')

    -- This will remove a warning from a player, second name is just who is doing the action
    Warnings.remove_warning('MrBiter','Cooldude2606')

    -- Script warning as similar to normal warning but are designed to have no effect for a short amount of time
    -- this is so it can be used for greifer protection without being too agressive
    Warnings.add_script_warning('MrBiter','Killed too many biters')

    -- Both normal and script warnings can also be cleared, this will remove all warnings
    Warnings.clear_warnings('MrBiter','Cooldude2606')

Events

on_warning_added When a warning is added to a player
on_warning_removed When a warning is removed from a player
on_script_warning_added When a warning is added to a player, by the script
on_script_warning_removed When a warning is remnoved from a player, by the script

Functions

get_warnings (player) Gets an array of warnings that the player has, always returns a list even if emtpy
count_warnings (player) Gets the number of warnings that a player has on them
add_warning (player, by_player_name[, reason='Non given.']) Adds a warning to a player, when a warning is added a set action is done based on the number of warnings and the config file
remove_warning (player, by_player_name) Removes a warning from a player, always removes the earlyist warning, fifo
clear_warnings (player, by_player_name) Removes all warnings from a player, will trigger remove event for each warning
get_script_warnings (player) Gets an array of all the script warnings that a player has
count_script_warnings (player) Gets the number of script warnings that a player has on them
add_script_warning (player[, reason='Non given.']) Adds a script warning to a player, this may add a full warning if max script warnings is met
remove_script_warning (player) Removes a script warning from a player
clear_script_warnings (player) Removes all script warnings from a player, emits event for each warning removed

Events

# on_warning_added

When a warning is added to a player

Event Parameters:
  • player_index : (number) the index of the player who recived the warning
  • by_player_name : (string) the name of the player who gave the warning
  • reason : (string) the reason that the player was given a warning
  • warning_count : (number) the new number of warnings that the player has
# on_warning_removed

When a warning is removed from a player

Event Parameters:
  • player_index : (number) the index of the player who is having the warning removed
  • warning_by_name : (string) the name of the player who gave the warning
  • removed_by_name : (string) the name of the player who is removing the warning
  • warning_count : (number) the new number of warnings that the player has
# on_script_warning_added

When a warning is added to a player, by the script

Event Parameters:
  • player_index : (number) the index of the player who recived the warning
  • reason : (string) the reason that the player was given a warning
  • warning_count : (number) the new number of warnings that the player has
# on_script_warning_removed

When a warning is remnoved from a player, by the script

Event Parameters:
  • player_index : (number) the index of the player who is having the warning removed
  • warning_count : (number) the new number of warnings that the player has

Functions

# get_warnings (player)

Gets an array of warnings that the player has, always returns a list even if emtpy

Parameters:
  • player : (LuaPlayer) the player to get the warning for
Returns:
  • (table) an array of all the warnings on this player, contains tick, by_player_name and reason
# count_warnings (player)

Gets the number of warnings that a player has on them

Parameters:
  • player : (LuaPlayer) the player to count the warnings for
Returns:
  • (number) the number of warnings that the player has
# add_warning (player, by_player_name[, reason='Non given.'])

Adds a warning to a player, when a warning is added a set action is done based on the number of warnings and the config file

Parameters:
  • player : (LuaPlayer) the player to add a warning to
  • by_player_name : (string) the name of the player who is doing the action
  • reason : (string) the reason that the player is being warned (default: 'Non given.')
Returns:
  • (number) the number of warnings that the player has
# remove_warning (player, by_player_name)

Removes a warning from a player, always removes the earlyist warning, fifo

Parameters:
  • player : (LuaPlayer) the player to remove a warning from
  • by_player_name : (string) the name of the player who is doing the action
Returns:
  • (number) the number of warnings that the player has
# clear_warnings (player, by_player_name)

Removes all warnings from a player, will trigger remove event for each warning

Parameters:
  • player : (LuaPlayer) the player to clear the warnings from
  • by_player_name : (string) the name of the player who is doing the action
Returns:
  • (boolean) true when warnings were cleared succesfully
# get_script_warnings (player)

Gets an array of all the script warnings that a player has

Parameters:
  • player : (LuaPlayer) the player to get the script warnings of
Returns:
  • (table) a table of all the script warnings a player has, contains tick and reason
# count_script_warnings (player)

Gets the number of script warnings that a player has on them

Parameters:
  • player : (LuaPlayer) the player to count the script warnings of
Returns:
  • (number) the number of script warnings that the player has
# add_script_warning (player[, reason='Non given.'])

Adds a script warning to a player, this may add a full warning if max script warnings is met

Parameters:
  • player : (LuaPlayer) the player to add a script warning to
  • reason : (string) the reason that the player is being warned (default: 'Non given.')
Returns:
  • (number) the number of script warnings that the player has
# remove_script_warning (player)

Removes a script warning from a player

Parameters:
  • player : (LuaPlayer) the player to remove a script warning from
Returns:
  • (number) the number of script warnings that the player has
# clear_script_warnings (player)

Removes all script warnings from a player, emits event for each warning removed

Parameters:
  • player : (LuaPlayer) the player to clear the script warnings from