Creeper World 4 How to apply 4RPL (CW4’s scripting language) to the game

Creeper World 4 How to apply 4RPL (CW4’s scripting language) to the game 1 - steamsplay.com
Creeper World 4 How to apply 4RPL (CW4’s scripting language) to the game 1 - steamsplay.com

This guide is designed to give an introduction for how to apply 4RPL (CW4’s scripting language) to the game; creating effects like unlocking units when a infocache is collected or giving you unlimited resources. The guide focuses on how to take console scripts and apply them to the game to get their effects. There will be scripts for you to copy, as well as links to the wiki for more scripts, 4RPL tutorials and 4RPL documentation.
 
 

What is 4RPL

4RPL is the scripting language for Creeper World 4; it is capable of manipulating levels in game in a very powerful way and serves as the backbone of heavily scripted maps such as PaC, CSM and FPS. It is capable of creating/destroying any unit in the game, switching weapons to other ammo types, manipulating creeper levels & flow rates and so much more. It can also be used to make entirely new units, from weapons to bosses to an entire enemy base.
 
 
If a level is doing something that default units cannot; the answer 99% of the time is 4RPL. Some examples include: anytime you unlock a unit mid-mission, the orb rain on Archon, the Wallis device, Berthas, Airships, and pretty much the entirety of Play as Creeper. To see some other effects, the ‘4RPL’ tag is used in Colonies for maps that make at least some use of 4RPL.
 
 
4RPL also isn’t just limited to in level effects; players have made code to help with map creation and map analysis. Code that instantly constructs all units on the map, code that gives information about a level, and even code that will play the game for you. The biggest limit you have with 4RPL is that it cannot manipulate the UI much; as an example, there is no 4RPL call for disabling the minimap.
 
 
 

The 4RPL Console

The 4RPL Console is where you run personal scripts; these scripts will not take effect for other players if you use them while making the map. They are very useful in quickly running code for performing actions that are either tedious or impossible to do with normal controls.
 
 
On any level, editor mode can be enabled with shift+e; when editor mode is enabled the green ‘Editor’ button in the bottom right will open the mission editor menu. Navigate to the ‘Mods’ tab and there will be 2 buttons at the top; ‘Open CPACK Manager’ and ‘4RPL Console’. In this section, we will be dealing with the 4RPL Console, clicking that button will switch the mission editor menu for a 4RPL Console, pictured below.
 
 
Creeper World 4 How to apply 4RPL (CW4's scripting language) to the game - The 4RPL Console - E4B26C4
 
 
Running code with the 4RPL console is easy, follow the steps below, relevant buttons are labelled in the following image.
 
 
Creeper World 4 How to apply 4RPL (CW4's scripting language) to the game - The 4RPL Console - A7C3561
 
Step 1: Click the ‘+ New’ button, this should open up a file explorer window. Name the file, this name will be how the script is labelled in this menu.
 
Step 2: Click the Yellow E button next to the script name you just set. This will attempt to open the 4RPL file in an external program; you will likely get a prompt asking “How do you want to open this file?”, navigate through that to a text editing program of your choice. I recommend Notepad++ if you want to code yourself, but any text editor program should work fine. If you are having trouble with this step, the wiki – [knucklecracker.com]  might be able to help you.
 
Step 3: Paste the code you want below the first line of the file (pasting it on a line with # before it will make the game ignore that bit of code). For this example I will be using the code:
 
 

SetCreeper(50 50 -25 false)

 
Save the file and return to Creeper World 4.
 
Step 4: Click the button with blue boxes next to the yellow E button and underneath Output on the right should appear “Success! [6] opcodes.”
 
Step 5: Click either of the buttons with a green triangle on them; the first will run the code once and is labelled ‘Run Once’. The Second button is just called ‘Run’ and will run the code constantly until Stopped (a new button with a red square will appear to stop the script).
 
 
To explicitly explain what happened; the code sets the creeper level of the tile 50,50 to -25, or 25 anticreeper. Running the code once will simply set that tile to 25 anticreeper, but the ‘Run’ button will make the code run every single gametick, once per gametick. So every single gametick the code reset the creeper level of that tile to -25.
 
 
More useful scripts as well as an explanation for their usage can be found in the next section. I recommend creating a new file for each script you want to run as pasting multiple scripts in a single file will (generally) result in all of them running when the script is run.
 
 
 

4RPL Console Scripts

Construct All Units

 
When placing player units in the editor, they usually place incomplete. Running this script will instantly fully construct all units on the map.
 
 

GetUnitsInRange(V3(150 0 150) 400 false false false 0 2 0) ->Units
do(<-Units 0)
ConstructUnit(<-Units[i] 9999)
loop

 
 

Add Orbital Count

 
This code will increase the number of orbitals the player has access to by 1 every time the code is run. In general I recommend only using the ‘Run Once’ button for this code, clicking it for every orbital you want.
 
 

GetOrbitalCount 1 add SetOrbitalCount

 
 

Subtract Orbital Count

 
For when you run the above code one too many times.
 
 

GetOrbitalCount 1 sub SetOrbitalCount

 
 

Unit Duplicator

 
When placing multiple enemy units, it can sometimes be tedious to set the unit settings for multiple units, especially if they all have the same or similar settings. For this code, let it run constantly and select a unit, the ‘b’ key will save that units settings. Once a unit is copied, the ‘v’ key will create a duplicate of that unit at the specified location. This is designed for enemy units, it will copy units like cannons, but will not copy their settings, nor will it match the construction status of the unit.
 
 

if(GetKeyDown("B" true))
GetSelectedUnits ->SelectedUnits
<-SelectedUnits[0] ->CopyUnit
GetUnitType(<-CopyUnit) ->CopyType
GetUnitSettings(<-CopyUnit) ->CopySettings
trace("Copying " <-CopyType AsString concat)
endif
if(GetKeyDown("V" true))
CreateUnitOnTerrain(<-CopyType GetPointerTerrainCoords <-CopySettings)
endif

 
 

Map Reset Help

 
Credit to K75 for the mesh section of the code, this code is designed to help reset maps in the event you unpause while attempting to build a map. There already exist several buttons in the editor for resetting map components, including the Delete All Creeper & Delete all AC buttons in the Terrain tab, all of the buttons on the bottom of the Units Tab, and the Reset Map Data at the top of the Game tab.
 
This script is made to help clear up some of the map elements that are not reset by the above buttons. The script will reset all mesh on the map to its default white state, reset all stashes to contain no creeper, and reset all UltraCapacitors to full ammo.
 
 

GetMapSize ->sizeZ ->sizeX
GetUnitsByType("stash" 0) ->stashes
do(<-stashes 0)
GetUnitSettings(<-stashes[i]) ->UnitSettings
GetUnitPosition(<-stashes[i]) ->UnitPos
DestroyUnit(<-stashes[i] true true true)
CreateUnit("stash" <-UnitPos <-UnitSettings)
loop
GetUnitsByType("" 0) ->UltraCs
do(<-UltraCs 0)
SetUnitAmmo(<-UltraCs 100)
loop
do(<-sizeZ 0)
do(<-sizeX 0)
if(GetMeshHealth(I J) neq0)
SetMeshHealth(I J -1000000)
endif
loop
loop

 
A quick note about stashes, the script just replaces all stashes on the map with a duplicate, so the script will change the unit ID of all stashes on the map.
 
 
Some very powerful and more complicated console scripts can be found in the 4RPL Tools tab of the developers wiki – [knucklecracker.com] .
 
 
 

4RPL Console Scripts 2: Cheat-like Effects

The following scripts are what I like to refer to as ‘cheat-like effects’ because they are designed to be used to be enabled on levels you are having trouble with. Note that you do need to open the editor to use these, so you will be unable to submit scores on maps where you used these effects.
 
 
To enable these effects, create 4RPL Console scripts, and run the codes you want to have enabled. The effects will remain so long as the code is running and will disappear once you stop running the script.
 
 

Unlimited Energy

 
This script will constantly max out your energy storage every frame.
 
 

SetUnitAmmo(GetRiftLab 100)

 
 

Unlimited Factory Resources

 
Same as the Unlimited Energy script, but for your factory resources.
 
 

SetFactoryWares(1 360)
SetFactoryWares(2 360)
SetFactoryWares(3 360)

 
 

Units Undamaged by Creeper

 
The script makes all of your units immune to being damaged by creeper; the effects will persist even after the code stops running, but units built after the script stops running will not be affected.
 
 

GetUnitsInRange(V3(150 0 150) 400 true false false 2 0 1) ->Units
do(<-Units 0)
SetUnitDamagedByCreeper(<-Units[i] false)
loop

 
 

Instant Build

 
We have already seen this code, but it can also be run constantly to instantly complete all your units.
 
 

GetUnitsInRange(V3(150 0 150) 400 false false false 0 2 0) ->Units
do(<-Units 0)
ConstructUnit(<-Units[i] 9999)
loop

 
 

Infinite Ammo Units

 
 

GetUnitsInRange(V3(150 0 150) 400 false false false 2 1 1) ->Units
do(<-Units 0)
SetUnitAmmo(<-Units[i] GetUnitMaxAmmo(<-Units[i]))
loop

 
 
 

CPACK – Global Control

Global Control is where you place scripts that you want to run constantly for all players of a map. As an example, the orb rain from Archon (shield story mission) is a Global Control script; the orbs spawn and fall down on everyone that plays the map.
 
 
In the mods tab of the mission editor, there was an option for ‘Open CPACK Manager’, clicking it will open a new window that will take over most of your screen. Getting a script running in here has a few more steps than running a script in the 4RPL Console.
 
 
To make a CPACK, click the + button along the top and input a name for the CPACK. An accurate name is not required but naming things appropriately helps keep things organised. All scripts and other assets for a level need to be organised in a CPACK.
 
 
In the below image, numbers have been added to label the buttons that correspond to various steps below:
 
 
Creeper World 4 How to apply 4RPL (CW4's scripting language) to the game - CPACK - Global Control - DA1FDE1
 
Step 1:Select the CPACK you want to add the script to from the drop down menu.
 
Step 2:Click the Scripts button beneath the CPACK name.
 
Step 3:Click the ‘+ New’ button and name the script. As with the CPACK, the name is mostly just used for organisation.
 
Step 4:Click the Yellow E button beneath +New, this will attempt to open the 4RPL file in an external program; you will likely get a prompt asking “How do you want to open this file?”, navigate through that to a text editing program of your choice. I recommend Notepad++ if you want to code yourself, but any text editor program should work fine. If you are having trouble with this step, the wiki – [knucklecracker.com]  might be able to help you.
 
Step 5:Paste the code you want into the script, not on the first line, same as with the 4RPL Console. For this example I will be using:
 
 

SetCreeper(GetPointerTerrainCoords -25 false)

 
Remember to save the file once you paste the code.
 
Step 6: Click ‘Compile All Scripts’. This should pop up a window saying how many scripts were compiled and how many opcodes there are. If you are using the above code and no other scripts, this popup should say 1 script and 5 opcodes.
 
Step 7:Click Global Control near the top middle of the screen.
 
Step 8:In line and to the right of ‘PRE’ beneath Global Control, select the script from the drop down menu and click the + button.
 
Step 9:Click Update Unit Instances in the top right and then close out of the CPACK manager.
 
 
Your script should now be running, and will continue to run even for other players if they download the map. The script above is a simplified version of the script seen in Cursor maps, placing anticreeper at the location of your mouse cursor.
 
 
These scripts are constantly running, once every game tick (30 times per in game second), so be careful that the scripts you run are balanced around running that many times. By default these scripts do not run while the game is paused, however in the CPACK manager, clicking on the script as it appears underneath ‘PRE’ will open the Script Execution Settings. From there you can enable ‘Run when paused’ and apply to have the script run even when the game is paused.
 
 
 

Global Control Scripts

All scripts from the 4RPL Console Scripts section will work here to similar effect, but I will state again that the code will run 30 times per second, so I would not recommend the Add Orbital code. As stated above, once the scripts are set up on a level, everyone who plays the level will experience them, so the below scripts are for use in levels intended for upload.
 
 

Incrementing Creeper Cap

 
Creeper cap is a mechanic that not many players know about; if there is a certain amount of creeper on the map, some creeper structures (notably emitters) will shut off. The creeper cap is listed as an average creeper level for the entire map; so a creeper cap of 2 would be hit when there is enough creeper to cover every tile on the map with 2 layers of creeper. The following code causes the creeper cap to steadily increase from 5 to 15 over the course of 20 minutes; allowing for a type of ramping difficulty on a map.
 
 

SetCreeperCutoff(GetGameUpdateCount 0.000278 mul 5 add 15 min)

 
The code can be modified, the 0.000278 number is the amount the creeper cap is increased per game update; this number right now increases the creeper cap by 1 every 2 minutes; so use that as a benchmark. The 5 and 15 are the starting creeper level and the maximum the creeper cap will reach before stopping.
 
 

Decaying Units

 
Player units regenerate at a slow rate and will fully heal if not touching creeper. This code reverses that, meaning player units will slowly lose health and die over time.
 
 

once
10 SetTimer0
endonce

if(GetTimer0 lte0)
GetUnitsInRange(V3(150 0 150) 400 false false false 2 0 1) ->PlayerUnits
if(GetListCount(<-PlayerUnits) gt0)
do(GetListCount(<-PlayerUnits) 0)
SetUnitHealRate(<-PlayerUnits[i] -0.0001)
loop
endif
10 SetTimer0
endif

 
 

Build Limit Increase on Infocache Pickup

 
One of the most requested scripts is one that allows map makers to have units only become available after the player has collected an infocache. This is slightly more complicated than adding a single script, you will need to set infocache parameters. Furthermore, changes to things like what unit are unlocked and how many units are unlocked are set in the code and will need to be changed in there. All the details can be found beneath the code.
 
 

once
RegisterForMSG("UnitLimitIncrease" "IncreaseBuildLimit")
endonce

:IncreaseBuildLimit
SetUnitBuildLimit("cannon" dup GetUnitBuildLimit 1 add)

 
The code will do nothing right now, because there is nothing to trigger it. Basically the code is looking for something else to trigger “UnitLimitIncrease”; when it is triggered the rest of the code will run. To set this up you need to select the infocache you want to unlock and put in the text “UnitLimitIncrease” without quotations into the MSG Channel field. The code by default will increase the build limit of the cannon unit by 1, to change those parameters see the next paragraphs.
 
In the code above, the last line is what determines what unit build limit is increased and by how much. To change the unit that is unlocked you need to change “cannon” to another unit type (remember quotation marks); the list of unit types can be found on the wiki – [knucklecracker.com] . For custom units, including the airship, sweeper and bertha, you will need the CMOD GUID for the unit. In the CPACK Manager there should be a ‘Units’ tab, select it and then click on the name of the unit (note the name might be different than the name in the menu). At the top right, underneath ‘CMOD Settings’ should be a field for the GUID; replace “cannon” with this GUID (with quotes around it).
 
The other parameter that you can change is how much the unit build limit is increased per infocache collected; just change the 1 on the last line to whatever number you want the build limit to increment by.
 
You can also duplicate the last line and change the parameters to have infocaches unlock multiple units. As an example of everything above put together; this is the code for having infocaches unlock 5 rockets and 2 airships when collected:
 
 

once
RegisterForMSG("UnitLimitIncrease" "IncreaseBuildLimit")
endonce

:IncreaseBuildLimit
SetUnitBuildLimit("rocketpad" dup GetUnitBuildLimit 5 add)
SetUnitBuildLimit("ca8dfbe4-a3ca-4223-b8c4-070de8877b26" dup GetUnitBuildLimit 2 add)

 
 
 

CPACK – Units

Comments on CPACK Units

 
While attaching scripts to units is fairly easy; you first need a unit to actually attach the scripts to. Creating a unit is a whole other procedure and often the settings for that unit will need to be changed depending on the script(s) being attached. As such I will not be giving scripts here, if you are interested in making custom units, a tutorial on CPACK use by Zer0 One can be found on the wiki – [knucklecracker.com] .
 
 
If you want to include scripted units, it is probably easier to copy already existing units by exporting & importing CPACKs than it is to add your own units. A guide for exporting/importing CPACKs can be found here – [steamcommunity.com] .
 
 
 

If You Want to Make Your Own Scripts

If you want to make your own scripts, the wiki has a number of resources to help you and a much better 4RPL introduction than I could write; pages are linked below.
 
 
Scripting: https://knucklecracker.com/wiki/doku.php?id=4rpl:overview – [knucklecracker.com] 
 
This page is the first place you should go when learning to code 4RPL in my opinion, it gives a very low level and quick explanation of stack-based languages, hopefully giving you enough information to start coding.
 
 
Tutorials: https://knucklecracker.com/wiki/doku.php?id=cw4:tutorials – [knucklecracker.com] 
 
This page contains community contributed tutorials, including one Youtube video guide by Zer0 One, who goes into the details of how to create units and scripts for CPACK use.
 
 
4RPL Scripting Language: https://knucklecracker.com/wiki/doku.php?id=4rpl:start – [knucklecracker.com] 
 
This is the page where all 4RPL commands are listed, with links to documentation for each command.
 
 
Knuckle Cracker Discord: https://discord.gg/knucklecracker – [discord.gg] 
 
The KC Discord is where most discussion on Knuckle Cracker games is currently. The mapmaking_support channel should be able to answer just about any question you have about 4RPL scripting.
 
 

Written by Fireswamp

 
 
This is all for Creeper World 4 How to apply 4RPL (CW4’s scripting language) to the game hope you enjoy the post. If you believe we forget or we should update the post please let us know via comment, we will try our best to fix how fast is possible! Have a great day!
 


Be the first to comment

Leave a Reply

Your email address will not be published.


*