This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cw4:cpack:docs:23977d46-b69d-431a-82e1-f4013f889c5a [2021/02/25 20:42] – Updated for some minor script changes qople | cw4:cpack:docs:23977d46-b69d-431a-82e1-f4013f889c5a [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
< | < | ||
- | ====== qople - First Person Tools ====== | + | ====== qople - First Person Tools ====== |
// | // | ||
Line 10: | Line 10: | ||
===== Basic Conventions ===== | ===== Basic Conventions ===== | ||
- | 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 (" | + | |
+ | 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 (" | ||
===== Weapon Attributes ===== | ===== Weapon Attributes ===== | ||
+ | |||
Almost all weapon attributes have the same effect on all weapons. This holds true even if that weapon doesn' | Almost all weapon attributes have the same effect on all weapons. This holds true even if that weapon doesn' | ||
Attributes that do not end in a " | Attributes that do not end in a " | ||
- | ^ Attribute Name ^ Default Value ^ Description | + | ^ Attribute Name ^ Default Value ^ Description |
- | | Rate | 30 | The number of updates between shots. Values of 1 and below max the weapon fire rate, at once per update. | + | | Rate | 30 | The number of updates between shots. Values of 1 and below max the weapon fire rate, at once per update. |
| DmgDepth | | DmgDepth | ||
- | | DmgDist | + | | DmgDist |
- | | DmgMaxCells | + | | DmgMaxCells |
| DmgIterations | | DmgIterations | ||
- | | ProjSpeed | + | | ProjSpeed |
| MinRange | | MinRange | ||
- | | MaxRange | + | | MaxRange |
| AcDepth | | AcDepth | ||
- | | AcDist | + | | AcDist |
- | | 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. | + | | 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 | + | | UnitDmgAmt |
- | | UnitDmgDist | + | | UnitDmgDist |
- | | MeshDmg | + | | MeshDmg |
- | | MeshDist | + | | MeshDist |
- | | NetMult | + | | BaseDPS |
===== List of Units (CMODS) in this CPACK ===== | ===== List of Units (CMODS) in this CPACK ===== | ||
Line 45: | Line 47: | ||
==== Move.4rpl ==== | ==== Move.4rpl ==== | ||
- | This script controls all aspects of first-person movement: speed, collision, respawn, etc. "Run when paused" | + | This script controls all aspects of first-person movement: speed, collision, respawn, etc. "Run when paused" |
Script vars: | Script vars: | ||
- | | + | |
- | * PlayerHeight:The height of the player above the ground, in cells. The default is 9. Changing this in combination with the move speed will effectively change the scale of the map. | + | |
- | * AllowMoveOnVoid: Whether void is counted as an impassable wall, or terrain height 0. Values other than 0 allow movement on void. Only really makes sense to allow it if the level has a planet. | + | * accelTime: The number of updates it takes for the player to reach full speed from a standstill. |
- | * CollisionThreshold: The highest terrain difference that the player can walk over. | + | * decelTime: The number of updates it takes for the player to stop from full speed. |
- | * StartX, StartZ: The cell coordinates of the player' | + | * playerHeight:The height of the player above the ground, in cells. The default is 9. Changing this in combination with the move speed will effectively change the scale of the map. |
- | * StartRotation: The direction that the player points when they spawn, in degrees. 0 faces them in the positive Z direction. | + | * allowMoveOnVoid: Whether void is counted as an impassable wall, or terrain height 0. Values other than 0 allow movement on void. Only really makes sense to allow it if the level has a planet. |
+ | * collisionThreshold: The highest terrain difference that the player can walk over. | ||
+ | * startX, startZ: The cell coordinates of the player' | ||
+ | * startRotation: The direction that the player points when they spawn, in degrees. 0 faces them in the positive Z direction. Clock-Wise rotation. | ||
+ | * stunDuration: | ||
==== Player.4rpl ==== | ==== Player.4rpl ==== | ||
- | Contains logic for health and firing weapons. | + | Contains logic for health and firing weapons. |
Script vars: | Script vars: | ||
- | * MaxHealth: The max health the player has. 30 is the default. Damage taken is proportional to the square root of creeper, with a depth of 1 dealing 0.1 damage per update. | ||
- | * BonusRequirement: | ||
- | * StartingWeapons: | ||
- | ==== Totems.4rpl ==== | + | |
- | + | * bonusRequirement: | |
- | Makes all totems charge in a way usable in a first-person level. Rules are as follows: | + | * startingWeapons: |
- | | + | * weaponOrder: A list of all weapons that are in the level, in order of their hotkeys. Changing the order of this will rearrange the weapon hotkeys. |
- | * Partially charged totems will stop charging when the player | + | |
- | * Totems will lose charge when there is creeper on the center cell of the unit. | + | |
- | * Disabled totems ("unit: off") will not charge, and any existing ammo will be removed. | + | |
- | + | ||
- | There are no script vars. | + | |
==== Vanilla Weapons.4rpl ==== | ==== Vanilla Weapons.4rpl ==== | ||
Line 85: | Line 83: | ||
Note that each key-value pair is separated with a colon, and different pairs are separated by commas. Whitespace is ignored. | Note that each key-value pair is separated with a colon, and different pairs are separated by commas. Whitespace is ignored. | ||
+ | |||
+ | ==== Misc Settings.4rpl ==== | ||
+ | |||
+ | Handles various settings that persist across the gamemode. Also creates the wall tool and DPS monitor on game load. | ||
+ | |||
+ | Script vars: | ||
+ | |||
+ | * useWallOverride: | ||
+ | * wallUpdateRate: | ||
+ | * chargeTotems: | ||
+ | * Totems will gain charge at an increasing rate while the player is within 15 cells. | ||
+ | * Partially charged totems will stop charging when the player is outside that radius, but will not lose charge. | ||
+ | * Totems will lose charge when there is creeper on the center cell of the unit. | ||
+ | * Disabled totems (" | ||
+ | * selectionMode: | ||
+ | * selectableWhitelist: | ||
+ | * buildWhitelist: | ||
===== 4RPL Extensions ===== | ===== 4RPL Extensions ===== | ||
+ | |||
//This section requires knowledge of 4RPL.// | //This section requires knowledge of 4RPL.// | ||
==== Global Variables ==== | ==== Global Variables ==== | ||
+ | |||
Certain parts of the game mode are stored as [[4rpl: | Certain parts of the game mode are stored as [[4rpl: | ||
^ Variable Name ^ Description | ^ Variable Name ^ Description | ||
| activeWeapon | | activeWeapon | ||
+ | | fireTimer | ||
+ | | frameToUpdate | ||
| isFPMode | | isFPMode | ||
- | | playerPos | + | | playerForward |
- | | playerForward | + | | playerHealth |
- | | playerHealth | + | | playerPos |
+ | | playerStunned | ||
| weaponAttributes | | weaponAttributes | ||
- | | fireTimer | + | |
+ | The Move.4rpl and Player.4rpl scripts are also registered, so you can get and set all variables they use with [[4rpl: | ||
==== Messages ==== | ==== Messages ==== | ||
+ | |||
Various parts of the game are communicated via messages. Registering other scripts for these messages can sometimes be useful. | Various parts of the game are communicated via messages. Registering other scripts for these messages can sometimes be useful. | ||
^ Message Channel | ^ Message Channel | ||
- | | ItemCollected | + | | ItemCollected |
| PlayerDied | | PlayerDied | ||
| Respawn | | Respawn | ||
- | | WeaponEffect | + | | WeaponEffect |
| WeaponFired | | WeaponFired | ||
- | | CrosshairUpdated | + | | CrosshairUpdated |
+ | | Initialize | ||
+ | | DamagePlayer | ||
+ | | AddText | ||
==== Interacting with Weapon Attributes ==== | ==== Interacting with Weapon Attributes ==== | ||
- | 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' | ||
- | | + | 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' |
+ | |||
+ | | ||
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. | 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' | Similarly, the simplest way to change a weapon' | ||
- | value -> | ||
+ | value -> | ||
=== Adding Custom Attributes === | === Adding Custom Attributes === | ||
+ | |||
To put everything together, here is an example that uses everything mentioned so far. | To put everything together, here is an example that uses everything mentioned so far. | ||
Line 150: | Line 177: | ||
==== Custom Weapons ==== | ==== Custom Weapons ==== | ||
+ | |||
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 " | 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 " | ||
=== The Basic Way === | === The Basic Way === | ||
+ | |||
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' | 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' | ||
The things that must be addressed in a weapon pack are: | The things that must be addressed in a weapon pack are: | ||
+ | |||
* Input vars/base stats | * Input vars/base stats | ||
* Visual attributes | * Visual attributes | ||
Line 162: | Line 192: | ||
Here is a blank template: (The Vanilla Weapons script can be used as an example) | Here is a blank template: (The Vanilla Weapons script can be used as an example) | ||
+ | |||
<hidden Click to show source code> | <hidden Click to show source code> | ||
- | <file 4RPL BlankPack.4rpl> | + | <code 4RPL BlankPack.4rpl> |
#Comma separated, whitespace ignored. | #Comma separated, whitespace ignored. | ||
#List of all weapons added by this script | #List of all weapons added by this script | ||
Line 175: | Line 206: | ||
#List stat vars here. Format as weaponAttributeName. weaponOther is supported. | #List stat vars here. Format as weaponAttributeName. weaponOther is supported. | ||
- | once | + | :Once |
@SetHiddenAttributes | @SetHiddenAttributes | ||
@InitializeWeapons | @InitializeWeapons | ||
Line 184: | Line 215: | ||
#Make the weapon visually different from others | #Make the weapon visually different from others | ||
RegisterForMsg(" | RegisterForMsg(" | ||
- | endonce | ||
: | : | ||
Line 215: | Line 245: | ||
RegisterScript(< | RegisterScript(< | ||
SendMsg(" | SendMsg(" | ||
- | </file> | + | </code> |
</ | </ | ||
- | 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: | + | \\ 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 | ^ Attribute Name ^ Default Value ^ Description | ||
- | | Color | V3(1, 1, 1) | The color to make the bullet. Values over 1 will put the color into the HDR glow range. | + | | 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' | + | | Trail | V2(0 0) | The characteristics of the bullet' |
| FireSound | | FireSound | ||
- | | FireVolume | + | | FireVolume |
- | | HitSound | + | | HitSound |
- | | HitVolume | + | | HitVolume |
| EffectName | | EffectName | ||
- | | EffectScale | + | | EffectScale |
- | | 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. | + | | 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. |
+ | | BulletGUID | ||
+ | |||
+ | === Using BulletGUID === | ||
+ | |||
+ | If the BulletGUID attribute is defined for a weapon, the default bullet will be hidden, and a unit of the given type is created to act as the visual. This unit: | ||
+ | |||
+ | * Follows the same path the bullet would | ||
+ | * Is rotated to match the direction it is moving | ||
+ | * Is spawned with a variable named " | ||
+ | * Is destroyed when the bullet hits something or leaves the map | ||
+ | |||
+ | It can have scripts attached to it that make animations or provide additional weapon logic. BulletGUID does nothing for weapons that do not use default bullets. | ||
=== The Advanced way === | === The Advanced way === | ||
- | When a weapon' | + | |
+ | When a weapon' | ||
The additional parts of the weapon that need to be addressed are: | The additional parts of the weapon that need to be addressed are: | ||
+ | |||
* Weapon Targeting: should be done inside the CrosshairUpdated event handler if any visuals depend on this. | * Weapon Targeting: should be done inside the CrosshairUpdated event handler if any visuals depend on this. | ||
- | * Firing logic: Register for the WeaponFire | + | * Firing logic: Register for the WeaponFired |
* Bullets: Normally the default bullet script figures out its own settings and what it should be doing based on the weapon attribute table and the active weapon. If you aren't using it, you need to do that. | * Bullets: Normally the default bullet script figures out its own settings and what it should be doing based on the weapon attribute table and the active weapon. If you aren't using it, you need to do that. | ||
- | FIXME Add advanced | + | The template |
+ | |||
+ | <hidden Click to show source code> | ||
+ | |||
+ | <code 4RPL BlankPack.4rpl> | ||
+ | #Uses " | ||
+ | |||
+ | #Comma separated, whitespace ignored. | ||
+ | #List of all weapons added by this script | ||
+ | $$weaponsAdded:"" | ||
+ | |||
+ | #List of custom attibutes those weapons should have on initialization | ||
+ | #Custom attributes in an " | ||
+ | $$customAttributes:"" | ||
+ | |||
+ | #Disable default weapon logic | ||
+ | $$myweaponPath: | ||
+ | |||
+ | #List stat vars here. Format as weaponAttributeName. weaponOther is supported. | ||
+ | |||
+ | |||
+ | # | ||
+ | #basic weapon logic that should always run, if any | ||
+ | #For instance, if your weapon has limited charge it could recharge passively. | ||
+ | |||
+ | # | ||
+ | |||
+ | :once | ||
+ | @InitializeWeapons | ||
+ | @GetWeaponStats | ||
+ | |||
+ | RegisterForMsg(" | ||
+ | RegisterForMsg(" | ||
+ | RegisterForMsg(" | ||
+ | |||
+ | #Fire the weapon | ||
+ | :Fire | ||
+ | #Only do something if your weapon is active | ||
+ | if(< | ||
+ | #If the weapon is unable to fire, set < | ||
+ | #so the script doesn' | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | if(< | ||
+ | #Handle targeting in here if any visuals depend on it | ||
+ | else | ||
+ | #Disable or hide custom visuals while other weapons are active | ||
+ | endif | ||
+ | |||
+ | #Called whenever the ItemCollected message is sent. | ||
+ | #Stores the attributes of myweapon to variables with matching names. | ||
+ | #Note the variable names are Capitalized. | ||
+ | : | ||
+ | #If you don't need all the attributes, feel free to replace this with a smaller list. | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | loop | ||
+ | |||
+ | # | ||
+ | |||
+ | #Required for the weapon pack to work. | ||
+ | : | ||
+ | Split(RemoveWhiteSpace(< | ||
+ | RegisterScript(< | ||
+ | SendMsg(" | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | \\ ==== Overriding Movement ==== | ||
+ | |||
+ | Writing to the playerPos global will teleport the player. If high FPS is on, a tween frame will be added to make movement smoother. To disable that, set the W component of the vector (the 4th one) to true. To snap the height to the terrain, set the Y component to anything less than -100. | ||
+ | |||
+ | As soon as you stop changing the camera position, normal movement will return. | ||
+ | |||
+ | ==== Misc. ==== | ||
+ | |||
+ | Code snippets that might be useful for some purposes. | ||
+ | |||
+ | === Unlocking a weapon === | ||
+ | |||
+ | <code 4RPL> | ||
+ | |||
+ | === Changing the Respawn Point === | ||
+ | <code 4RPL> | ||
< | < | ||