Main file of the Force Fields plugin, which adds Combine force fields that citizens cannot pass through; exposes the plugin as cwForceField, defines the collision rules of cw_forcefield and includes the plugin's server and client files.

The ShouldCollide hook lets projectiles, Combine NPCs and vehicles, Combine players and holders of a forcefield card through, and asks the ShouldForcefieldCollide hook about everyone else. That hook decides by the field's mode, one of the four listed in cwForceField.modes: no one, Civil Workers' Union, everyone or off.

Summary

Hooks

Called after Catwork has loaded the map entities; restores the saved forcefields.
Spawns the forcefields saved for the current map with their saved mode and power state.
Called when a fallen over player attempts to get up; blocks it within 50 units of a forcefield.
Called when a player's character has loaded; sets whether forcefields block them.
Called when a player is given an item; a forcefield card lets them pass through forcefields.
Called when an item is taken from a player; makes forcefields block them again.
Called after data is saved; saves the forcefields.
Saves the position, angles, mode and power state of every cw_forcefield to the schema data.
Called to check whether two entities collide; decides who a forcefield blocks.
Called to check whether a forcefield blocks a player, by the field's mode.

Hooks

cwForceField:ClockworkInitPostEntity()

server gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:8

Implements hook ClockworkInitPostEntity

Called after Catwork has loaded the map entities; restores the saved forcefields.

cwForceField:LoadForceFields()

server gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_plugin.lua:8

Spawns the forcefields saved for the current map with their saved mode and power state.

Restored fields keep their exact position instead of snapping to the floor.

cwForceField:PlayerCanGetUp(player)

shared gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:32

Implements hook PlayerCanGetUp

On the server

Called when a fallen over player attempts to get up; blocks it within 50 units of a forcefield.

The client's hook of the same name only hides the hint.

Parameters

  • player Player The player getting up

Returns

  • Boolean false near a forcefield, otherwise nil

On the client

Called to check whether the local player can get up; blocks it within 50 units of a forcefield.

Parameters

  • player

Returns

  • Boolean false near a forcefield, otherwise nil

Defined in

cwForceField:PlayerCharacterLoaded(player)

server gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:22

Implements hook PlayerCharacterLoaded

Called when a player's character has loaded; sets whether forcefields block them.

The ShouldForceFieldCollide net var would otherwise keep the value of the character played before.

Parameters

  • player Player The player whose character loaded

cwForceField:PlayerItemGiven(player, itemTable, bForce)

server gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:63

Implements hook PlayerItemGiven

Called when a player is given an item; a forcefield card lets them pass through forcefields.

Sets the ShouldForceFieldCollide net var to false for a combine_forcefield_card.

Parameters

  • player Player The player given the item
  • itemTable Item The item given
  • bForce Boolean Whether the item was forced into the inventory

cwForceField:PlayerItemTaken(player, itemTable)

server gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:50

Implements hook PlayerItemTaken

Called when an item is taken from a player; makes forcefields block them again.

Sets the ShouldForceFieldCollide net var to true when the player loses a combine_forcefield_card and has fewer than two left.

Parameters

  • player Player The player who lost the item
  • itemTable Item The item taken

Implements hook PostSaveData

Called after data is saved; saves the forcefields.

Implements hook SaveForceFields

Saves the position, angles, mode and power state of every cw_forcefield to the schema data.

Writes plugins/forcefields/<map>.

cwForceField:ShouldCollide(a, b)

shared gamemodes/cwhl2rp/plugins/forcefields/plugin/sh_plugin.lua:54

Called to check whether two entities collide; decides who a forcefield blocks.

Combine projectiles, NPCs and vehicles always pass through forcefields. Players holding use always collide, so they can use the field. Combine players and holders of a forcefield card pass through; for everyone else ShouldForcefieldCollide decides by the field's mode.

Parameters

  • a Entity The first entity
  • b Entity The second entity

Returns

  • Boolean Whether the entities collide, or nil for the default

cwForceField:ShouldForcefieldCollide(player, field, mode)

shared gamemodes/cwhl2rp/plugins/forcefields/plugin/sh_plugin.lua:93

Implements hook ShouldForcefieldCollide

Called to check whether a forcefield blocks a player, by the field's mode.

Mode 1 blocks everyone, mode 2 lets Civil Workers' Union members through, and modes 3 (everyone allowed) and 4 (off) block no one. The modes are listed in cwForceField.modes.

Parameters

  • player Player The player touching the field
  • field Entity The cw_forcefield
  • mode Number The field's mode, 1 to 4

Returns

  • Boolean Whether the player collides with the field, or nil for the default

Defined in