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
cw_forcefield to the schema data.Hooks
cwForceField:ClockworkInitPostEntity()
server gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:8Implements hook ClockworkInitPostEntity
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.
Restored fields keep their exact position instead of snapping to the floor.
cwForceField:PlayerCanGetUp(player)
shared gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:32Implements 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
falsenear a forcefield, otherwisenil
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
falsenear a forcefield, otherwisenil
Defined in
cwForceField:PlayerCharacterLoaded(player)
server gamemodes/cwhl2rp/plugins/forcefields/plugin/sv_hooks.lua:22Implements 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:63Implements 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:50Implements 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:54Called 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
nilfor the default
cwForceField:ShouldForcefieldCollide(player, field, mode)
shared gamemodes/cwhl2rp/plugins/forcefields/plugin/sh_plugin.lua:93Implements 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
nilfor the default