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 [2016/05/01 13:02] – Incorrect code applied by me, changed it so it works on any map understandably. cpaca | crpl:crpltutorial:code_examples [2022/01/09 00:42] – added Make a non-moving unit only buildable in void Grabz | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | ||
< | < | ||
Line 974: | Line 973: | ||
</ | </ | ||
<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' | <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 | ||
+ | </ |