This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
crpl:crpltutorial:code_examples [2015/04/07 01:37] – [GetClosestUnitToCoords] Telanir | crpl:crpltutorial:code_examples [2022/01/09 00:42] – added Make a non-moving unit only buildable in void Grabz | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | ||
< | < | ||
====== Code Examples ====== | ====== Code Examples ====== | ||
+ | |||
Code examples contributed by map makers and coders alike. Feel free to submit your own - it will be much appreciated. | Code examples contributed by map makers and coders alike. Feel free to submit your own - it will be much appreciated. | ||
You can also view the scripts in any map: make a copy of the map you want to inspect, rename the copy " | You can also view the scripts in any map: make a copy of the map you want to inspect, rename the copy " | ||
+ | |||
+ | <wrap hi> | ||
===== Manage Treasure Chests in Credits Mission ===== | ===== Manage Treasure Chests in Credits Mission ===== | ||
Line 962: | Line 964: | ||
</ | </ | ||
< | < | ||
+ | |||
+ | |||
+ | ===CRPL generating CRPL=== | ||
+ | This CRPL will generate CRPL with custom program (if it is in the map scripts) | ||
+ | < | ||
+ | CreateUnit(" | ||
+ | AddScriptToUnit(< | ||
+ | </ | ||
+ | <sub> Stolen from Teknotiss(who took it from virgil), where pyramids make golems. I simply changed golem to unit. Added by cpaca, known as Karma' | ||
+ | |||
+ | ===== Make a non-moving unit only buildable in void ===== | ||
+ | This code will make it so a unit can be only built in void and not on terrain. It only works properly for stationary units. | ||
+ | |||
+ | * This is a global script, so you have to add it in Package Manager -> Global Control -> Pre Update. | ||
+ | * **Tick the Run when paused box**, then in one of the UNITGUID fields paste the GUID of one or more void only units. | ||
+ | * The script does not work in editor, you can finalize the map, back out then open the finalized map and test there if it works. | ||
+ | * The unit must have the "Can build/land anywhere" | ||
+ | |||
+ | < | ||
+ | $UnitGUID0:"" | ||
+ | $UnitGUID1:"" | ||
+ | $UnitGUID2:"" | ||
+ | $UnitGUID3:"" | ||
+ | $UnitGUID4:"" | ||
+ | |||
+ | GetBuildUnit -> | ||
+ | |||
+ | #Only do something if state has changed | ||
+ | < | ||
+ | FALSE -> | ||
+ | FALSE -> | ||
+ | |||
+ | 5 0 do | ||
+ | " | ||
+ | <-val StringLength gt0 <-val < | ||
+ | TRUE -> | ||
+ | endif | ||
+ | <-val StringLength gt0 <-val < | ||
+ | TRUE -> | ||
+ | endif | ||
+ | loop | ||
+ | |||
+ | #If a void only unit was selected, and the last selection was not a void only unit | ||
+ | < | ||
+ | FALSE SetAllLegalUnitCells | ||
+ | < | ||
+ | TRUE UseLegalUnitCells | ||
+ | #If a non void only unit was selected, and the last selection was a void only unit | ||
+ | else < | ||
+ | FALSE SetAllLegalUnitCells | ||
+ | FALSE UseLegalUnitCells | ||
+ | endif endif | ||
+ | endif | ||
+ | |||
+ | #Save current state | ||
+ | < | ||
+ | |||
+ | #Initialize | ||
+ | :once | ||
+ | GetBuildUnit -> | ||
+ | @RebuildVoidCellsList | ||
+ | |||
+ | : | ||
+ | #Build list of void cells | ||
+ | CreateList -> | ||
+ | GetMapSize ->sizeZ ->sizeX | ||
+ | <-sizeZ 0 do | ||
+ | < | ||
+ | #If terrain is void, add coordinates to list | ||
+ | I J GetTerrain eq0 if | ||
+ | < | ||
+ | endif | ||
+ | loop | ||
+ | loop | ||
+ | </ |