Faction

Faction setup hooks.

Factions have their own hooks that are called for various reasons, with the most common being to set up a character once it's created and assigned to a certain faction. For example, giving a police faction character a weapon upon creation. These hooks are used in faction tables that are created in schema/factions/sfactionname.lua and cannot be used like regular gamemode hooks.

Functions

FACTION:GetDefaultDesc(client, faction)

Called when the default description for a character needs to be retrieved. This function allows factions to define custom default descriptions for characters.

Parameters

  • client Player

    The client for whom the default description is being retrieved

  • faction Character

    The faction ID for which the default description is being retrieved

Returns

  • string

    The default description for the newly created character

Example Usage

function FACTION:GetDefaultDesc(client, faction)
	return "A police officer"
end

FACTION:GetDefaultName(client)

Called when the default name for a character needs to be retrieved (i.e., upon initial creation).

Parameters

  • client Player

    The client for whom the default name is being retrieved

Returns

  • string

    The default name for the newly created character

Example Usage

function FACTION:GetDefaultName(client)
	return "CT-" .. math.random(111111, 999999)
end

FACTION:OnCharCreated(client, character)

Called when a character has been initially created and assigned to this faction.

Parameters

  • client Player

    The client that owns the character

  • character Character

    The character that has been created

Example Usage

function FACTION:OnCharCreated(client, character)
	local inventory = character:getInv()
	inventory:add("fancy_suit")
end

FACTION:OnSpawn(client)

Called when a character in this faction has spawned in the world.

Parameters

  • client Player

    The player that has just spawned

Example Usage

function FACTION:OnSpawn(client)
	client:chatNotify("You have spawned!")
end

FACTION:OnTransferred(character)

Called when a player's character has been transferred to this faction.

Parameters

  • character Character

    The character that was transferred

Example Usage

function FACTION:OnTransferred(character)
	local randomModelIndex = math.random(1, #self.models)
	character:setModel(self.models[randomModelIndex])
end