This is an old revision of the document!
⇐ Index
canonical link to CPACK - where to get the author-maintained version
This is the documentation page for the first person game mode. Information for players can be found here.
The FPS scripts were made with extensibility and versatility in mind, but because of that some parts of them may seem a little daunting. This page's goal is to act as a guide and a reference to hopefully lower that barrier to making your own first person levels.
As a general rule, all weapon and attribute names must follow the same capitalization rules when used as inputs, no matter what script they appear in. Weapon names are all lowercase (“cannon”) and attribute names are capitalized and camel cased (“MaxRange”).
Almost all weapon attributes have the same effect on all weapons. This holds true even if that weapon doesn't normally have that attribute. For instance, in “FPS: Anti Up” (map #586), the cannon is given AC simply by having an item upgrade give the cannon anticreep-related attributes.
Attributes that do not end in a “.0” are integers (they ignore anything past the decimal place when finding their effect).
Attribute Name | Default Value | Description | Notes |
---|---|---|---|
Rate | 30 | The number of updates between shots. Values of 1 and below max the weapon fire rate, at once per update. | |
DmgDepth | 0.0 | The depth of normal damage to creeper. Is affected by crimson (20% damage). | The same as the MaxNumCells, Radius, and Amt arguments to the DamageCreeper function. |
DmgDist | 0 | The maximum radius that normal damage will damage creeper at. | |
DmgMaxCells | 9999 | The maximum number of cells that normal creeper damage can affect. | |
DmgIterations | 1 | Increases normal damage spread against thin creep, decreasing damage loss. Multiplies the max cells when creeper is less than DmgDepth deep. | Implementation is to spread damage across several DamageCreeper calls with decreased amounts. |
ProjSpeed | 10 | How fast the weapon's projectiles travel, in cells per update. | |
MinRange | 0 | The lower bound of ballistic weapons' targeting, in cells. | Ballistic (mortar-like) weapons only. |
MaxRange | 100 | The upper bound of ballistic weapons' targeting, in cells. | |
AcDepth | 0.0 | The depth of AC deposited per shot. | Same as the Amt, Range and Cap arguments to the AddCreeperWithCapInRange function. |
AcDist | 0 | The radius that AC is deposited inside of. | |
AcCap | 0.0 | The maximum depth that AC can be deposited to. Keeping the cap at 0 will add AC damage without creating AC, effectively giving bonus damage against crimson. | |
UnitDmgAmt | 0.0 | The amount of damage dealt to vulnerable enemy units. Most units have a max HP of 1. | |
UnitDmgDist | 0.0 | The radius inside of which vulnerable enemy units will be damaged. | |
MeshDmg | 0.0 | The amount of damage done to mesh. Mesh has a maximum health of 1. | |
MeshDist | 0 | The radius inside of which mesh is damaged. | |
NetMult | 0.0 | Keeps track of the total strength of upgrades the weapon has received. Should not be modified without upgrading the weapon accordingly. Info cache-based upgrades increment this automatically, so only custom upgrades should interact with it. |
This script controls all aspects of first-person movement: speed, collision, respawn, etc. “Run when paused” should be turned on, so it can return normal controls if the player leaves free view while paused.
Script vars:
Contains logic for health and firing weapons.
Script vars:
Makes all totems charge in a way usable in a first-person level. Rules are as follows:
There are no script vars.
A weapon pack that determines the starting settings for the cannon, mortar, and sprayer. It follows the same format that other weapon packs should, so this section applies to custom weapons as well.
All script vars except for those ending in “Other” simply set the starting value for the weapon and attribute in the name. See weapon attributes for a more detailed description.
Script vars ending in “Other” are for setting attributes that are not already listed for a particular weapon. The string is case sensitive, and must be formatted as a list of attribute-value pairs. The weapon name should not be added to the attribute name. An example would be:
DmgDepth: 0.5, DmgDist: 5, Rate: 10
Note that each key-value pair is separated with a colon, and different pairs are separated by commas. Whitespace is ignored.
This section requires knowledge of 4RPL.
Certain parts of the game mode are stored as global variables, allowing them to be read from any script in the level. They are listed below.
Variable Name | Description |
---|---|
activeWeapon | The name of the weapon that is currently selected. |
isFPMode | A bool, indicating whether the player is currently in first person mode. Updates while paused. |
playerPos | The position of the player, as a 3-dimensional vector. It is the location of the camera when the player is in first person mode, not the terrain below the camera. This means it is roughly 9 cells above the terrain. Changing this will teleport the player to that x and z, but the y always follows the terrain. |
playerForward | A normalized 3 dimensional vector pointing in the direction the player is looking. Changing this will not rotate the player. Useful for making something move in front of the player. |
playerHealth | A floating point from 0 to 1 representing how much health the player has out of their max health. |
weaponAttributes | A table containing all attribute values for all weapons. More detail in interacting with weapon attributes |
fireTimer | The current countdown until the player can fire again. Mainly used by weapon packs. |
Various parts of the game are communicated via messages. Registering other scripts for these messages can sometimes be useful.
Message Channel | When it is sent | Data included |
---|---|---|
ItemCollected | When an info cache is collected via the item.4rpl script | The ID of the unit that sent the message |
PlayerDied | When the player's health reaches 0 | How many times the player has died |
Respawn | When the respawn button is pressed | 0 |
WeaponEffect | When a bullet is destroyed and creates weapon effects | A list: [“weaponName”, position (a V3)] |
WeaponFired | When the player fires any weapon | 0 |
CrosshairUpdated | Every frame update, after the crosshair's position is updated | The ID of the crosshair |
The weaponAttributes table has an entry for each weapon, accessible by its name. That value is another table with entries for all of that weapon's attributes. This means that the simplest syntax for reading the value of a weapon's attribute is:
<-*weaponAttributes {"weaponName"} {"attributeName"}
Although if many attributes need to be read for the same weapon, it can be easier to store the second table to its own (local) variable.
Similarly, the simplest way to change a weapon's attribute is:
value ->*weaponAttributes {"weaponName"} {"attributeName"}
To put everything together, here is an example that uses everything mentioned so far.
Whenever a bullet creates its weapon effect, it sends a message on the “WeaponEffect” channel. _DATA will be a list with two elements: the first is the name of the weapon, and the second is a 3-dimensional vector of the location where the weapon effect was made. By registering a script for that event, custom effects can be added to weapons without modifying the original scripts.
The base template for this is as follows:
once RegisterForMsg("WeaponEffect" "DoCustomWeaponEffects") endonce :DoCustomWeaponEffects #Store data into more readable vars <-_DATA[0] ->weapon <-_DATA[1] ->effectPosition #Read whatever attributes are needed for this effect #Repeat if necessary <-*weaponAttributes {<-weapon} {"SomeAttribute"} ->someAttribute #Then create the effect. Teleport the player, flip C/AC, damp waves, whatever you want.
The weapon loader and item scripts don't filter what stats are being added to the weapon, so new attributes can be added and read just like the base ones.
New weapons can be added into the gamemode through the use of special scripts. There are two ways to write these scripts: for weapons that use the same logic as those in the “Vanilla Weapons” pack, defining starting stats and visuals is all that is needed. If a weapon needs to do more than what is possible with those options, you can define your own logic.
When a weapon can use the same logic as the base weapons, creating that weapon becomes much simpler. This kind of custom weapon is more about creating a new weapon slot for a custom effect that doesn't fit on the regular weapons, like teleportation.
The things that must be addressed in a weapon pack are:
Here is a blank template: (The Vanilla Weapons script can be used as an example)
Visual settings for weapons are in the form of hidden attributes. Some of them are vector types, meaning they cannot be set as input vars. They are:
Attribute Name | Default Value | Description | Notes |
---|---|---|---|
Color | V3(1, 1, 1) | The color to make the bullet. Values over 1 will put the color into the HDR glow range. | |
Trail | V2(0 0) | The characteristics of the bullet's trail. The same as the last two arguments to CreateTrail. | |
FireSound | “” | The name of the sound to play when fired. | A list of all valid sound names is here. |
FireVolume | 1.0 | The volume the fire sound is played at. 1 is normal volume. | |
HitSound | “” | The name of the sound to play when the bullet hits. | |
HitVolume | 1.0 | The volume the hit sound is played at. 1 is normal volume. | |
EffectName | “” | The name of the effect to make when the bullet hits. Leave empty for no effect. | See CreateEffect for a list of options. |
EffectScale | 1.0 | The scale the effect is made at. Applied to all dimensions. | |
Path | 0 | The type of path and targeting the weapon uses. 0 is straight (cannon), and 1 is ballistic (mortar). If it is anything else, the crosshair will be hidden and the weapon will not fire on its own, leaving that up to you and giving more freedom. |
When a weapon's Path attribute is set to anything other than 0 or 1, nothing is done for you, meaning you have more freedom about what you do with the weapon, but it is more work to make.
The additional parts of the weapon that need to be addressed are:
Add advanced template
⇐ Index